Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add unit tests for campaigns folder #1724

Merged
merged 48 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
563ac08
unit tests for campaigns folder
reachaadrika May 29, 2023
7ee04b5
other changes to the code , name fix and fixing eslint errors
reachaadrika May 29, 2023
510ae01
Merge branch 'master' into campaignTests
reachaadrika May 29, 2023
c6a39a5
Merge branch 'master' into campaignTests
reachaadrika May 30, 2023
7eab794
Merge branch 'master' into campaignTests
reachaadrika Jun 1, 2023
13e87e6
Merge branch 'master' into campaignTests
reachaadrika Jun 3, 2023
418c7fa
changes in unit tests
reachaadrika Jun 3, 2023
d514196
git
reachaadrika Jun 3, 2023
91585c2
Merge branch 'master' into campaignTests
reachaadrika Jun 6, 2023
d796bcc
Merge branch 'master' of https://github.com/reachaadrika/website into…
reachaadrika Jun 7, 2023
f8c3af6
adding data-cy attribute
reachaadrika Jun 7, 2023
7cf46cc
Merge branch 'campaignTests' of https://github.com/reachaadrika/websi…
reachaadrika Jun 7, 2023
9132a76
Merge branch 'master' into campaignTests
reachaadrika Jun 8, 2023
697d573
final change , replace -cy with -test-id to maintain consistency
reachaadrika Jun 8, 2023
58f092e
Merge branch 'master' into campaignTests
reachaadrika Jun 10, 2023
26b16a5
Merge branch 'master' into campaignTests
reachaadrika Jun 11, 2023
45735ee
removed whitespaces , changed names and done other changes]
reachaadrika Jun 11, 2023
0a96798
Merge branch 'master' into campaignTests
reachaadrika Jun 12, 2023
7d2fd02
Merge branch 'master' into campaignTests
reachaadrika Jun 17, 2023
595cc09
change adding testid on reflected component
reachaadrika Jun 17, 2023
2d2e676
Merge branch 'master' into campaignTests
reachaadrika Jun 17, 2023
90443f8
Merge branch 'master' into campaignTests
reachaadrika Jun 17, 2023
6d8ab7d
Update components/campaigns/Banner.js
reachaadrika Jun 17, 2023
b7fad6e
Update components/campaigns/Banner.js
reachaadrika Jun 17, 2023
3764428
Merge branch 'master' into campaignTests
reachaadrika Jun 18, 2023
27f04df
Merge branch 'master' of https://github.com/reachaadrika/website into…
reachaadrika Jun 19, 2023
8bdaeac
Merge branch 'master' into campaignTests
reachaadrika Jun 21, 2023
62934b6
Merge branch 'campaignTests' of https://github.com/reachaadrika/websi…
reachaadrika Jun 22, 2023
933dde2
Merge branch 'master' of https://github.com/reachaadrika/website into…
reachaadrika Jun 22, 2023
ddb3809
Merge branch 'master' into campaignTests
reachaadrika Jun 23, 2023
5900eae
Merge branch 'master' into campaignTests
reachaadrika Jun 27, 2023
5f6d2de
Merge branch 'master' into campaignTests
reachaadrika Jun 30, 2023
dd0b0e4
Merge branch 'master' into campaignTests
reachaadrika Jul 7, 2023
334887f
Merge branch 'master' into campaignTests
reachaadrika Jul 8, 2023
d2b1ab9
fix campaign tests
reachaadrika Jul 9, 2023
3f339e9
Merge branch 'master' into campaignTests
reachaadrika Jul 10, 2023
34f39c8
Merge branch 'master' into campaignTests
reachaadrika Jul 10, 2023
af76387
Merge branch 'master' into campaignTests
reachaadrika Jul 10, 2023
26df0f0
Merge branch 'master' into campaignTests
reachaadrika Jul 11, 2023
017e1f6
Merge branch 'master' into campaignTests
reachaadrika Jul 11, 2023
bcd67f7
fixed tests for Banner
reachaadrika Jul 11, 2023
fcd713f
Merge branch 'campaignTests' of https://github.com/reachaadrika/websi…
reachaadrika Jul 11, 2023
8128550
Merge branch 'master' into campaignTests
reachaadrika Jul 14, 2023
b80e195
Merge branch 'master' into campaignTests
akshatnema Jul 16, 2023
015b510
fix Announcement Hero
reachaadrika Jul 16, 2023
6027dd5
Merge branch 'campaignTests' of https://github.com/reachaadrika/websi…
reachaadrika Jul 16, 2023
5af3471
Format AnnouncementHero.js
akshatnema Jul 16, 2023
2cd75e7
Merge branch 'master' into campaignTests
reachaadrika Jul 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions components/campaigns/AnnoucementHero.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export default function AnnouncementHero({ className = '', small = false, hideVi
<div
className={`bg-gray-50 border border-gray-200 py-6 rounded ${className} ${
small ? 'mb-4' : 'mx-3 mt-3 p-3 mb-6'
}`}
}`} data-testid = "AnnouncementHero-main-div"
>
<Heading
className="countdown-text-gradient"
level="h2"
typeStyle="heading-lg"
>
typeStyle="heading-lg" >
AsyncAPI Conf on Tour 2023
</Heading>

<Heading
className="countdown-text-gradient"
level="h3"
Expand All @@ -53,6 +53,7 @@ export default function AnnouncementHero({ className = '', small = false, hideVi
href="https://conference.asyncapi.com/"
target="_blank"
text="Submit a session"
data-testid="AnnouncementHero-submit-session"
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/campaigns/AnnouncementRamainingDays.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function AnnouncementRemainingDays({ dateTime, eventName }) {
}

return (
<span className="font-extrabold countdown-text-gradient block">
<span className="font-extrabold countdown-text-gradient block" data-testid="AnnouncementRemainingDays-text">
{text} until {eventName}
</span>
)
Expand Down
6 changes: 3 additions & 3 deletions components/campaigns/Banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default function Banner({}) {
}

return (
<div className="bg-gray-100">
<div className="mx-auto max-w-screen-xl py-1 px-3 sm:px-6 lg:px-8">
<div className="bg-gray-100" data-testid="Banner-main-div">
<div className="mx-auto max-w-screen-xl py-1 px-3 sm:px-6 lg:px-8" >
<div className="flex items-center justify-between flex-wrap">
<div className="flex md:hidden w-0 flex-1 flex items-center text-xs">
<p className="font-medium text-gray-700">
Expand All @@ -37,7 +37,7 @@ export default function Banner({}) {
</p>
</div>
<div className="flex">
<a
<a data-testid="Banner-link"
href="https://www.youtube.com/playlist?list=PLbi1gRlP7pijRiA32SU36hD_FW-2qyPhl"
className="flex items-center justify-center px-4 py-1 border border-transparent rounded-md shadow-sm text-xs font-medium text-indigo-600 focus:text-indigo-600 bg-white hover:bg-indigo-50"
target="_blank" rel="noopener noreferrer"
Expand Down
5 changes: 0 additions & 5 deletions cypress/test/ComponentName.cy.js

This file was deleted.

55 changes: 55 additions & 0 deletions cypress/test/campaignTests/AnnouncementHero.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { mount } from '@cypress/react';
import AnnouncementHero from '../../../components/campaigns/AnnoucementHero';
beforeEach(() => {
mount(<AnnouncementHero />);
});


describe('AnnouncementHero Component', () => {
it('should render the component when the date is within the valid range', () => {
// Set the current date to May
const mockDate = new Date('2023-05-01T00:00:00Z');
cy.clock(mockDate.getTime());
// Assert that the component is rendered
//check for background color
cy.get('[data-testid="AnnouncementHero-main-div"]').should('have.class', 'bg-gray-50');
});

it('should display the correct event information', () => {
const mockDate = new Date('2023-05-01T00:00:00Z');
cy.clock(mockDate.getTime());
// Assert the event details
cy.get('[data-testid="AnnouncementHero-main-div"]').contains('AsyncAPI Conf on Tour 2023').should('exist');
cy.get('[data-testid="AnnouncementHero-main-div"]').contains('London Edition').should('exist');
cy.get('[data-testid="AnnouncementHero-main-div"]').contains('20th of September, 2023 | London, UK').should('exist');
cy.contains('Submit a session').should('exist');
});

it('should have a link to submit a session', () => {
const mockDate = new Date('2023-05-01T00:00:00Z');
cy.clock(mockDate.getTime());
// Assert the link
cy.get('[data-testid="AnnouncementHero-submit-session"]').should('have.attr', 'href', 'https://conference.asyncapi.com/')
.should('have.attr', 'target', '_blank')
.contains('Submit a session');
});
//check if announcement rendered is small or large .
it('should render a small announcement when "small" prop is true', () => {
const mockDate = new Date('2023-05-01T00:00:00Z');
cy.clock(mockDate.getTime());

mount(<AnnouncementHero small />);

cy.get('[data-testid="AnnouncementHero-main-div"]').should('have.class', 'mb-4');
});

it('should render a large announcement when "small" prop is false', () => {
const mockDate = new Date('2023-05-01T00:00:00Z');
cy.clock(mockDate.getTime());

mount(<AnnouncementHero small={false} />);

cy.get('[data-testid="AnnouncementHero-main-div"]').should('have.class', 'mx-3 mt-3 p-3 mb-6');
});
akshatnema marked this conversation as resolved.
Show resolved Hide resolved
});
38 changes: 38 additions & 0 deletions cypress/test/campaignTests/AnnouncementRemainingDays.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import moment from 'moment';
import { mount } from '@cypress/react';
import AnnouncementRemainingDays from '../../../components/campaigns/AnnouncementRamainingDays';

describe('AnnouncementRemainingDays', () => {
it('displays correct countdown text', () => {
const dateTime = moment().add(2, 'days').toISOString(); // Set the dateTime value as desired
const eventName = 'Your Event'; // Set the eventName as desired

mount(<AnnouncementRemainingDays dateTime={dateTime} eventName={eventName} />);

const date = moment(dateTime);
const now = moment();
const days = date.diff(now, 'days');

let text;
if (days >= 1) {
text = `${days} ${days === 1 ? 'day' : 'days'}`;
} else {
const hours = date.diff(now, 'hours');
if (hours > 1) {
text = 'A few hours';
} else {
const minutes = date.diff(now, 'minutes');
if (minutes > 1) {
text = 'A few minutes';
}
}
}

cy.get('[data-testid="AnnouncementRemainingDays-text"]').should('have.text', `${text} until ${eventName}`);

//check class font-extrabold
cy.get('[data-testid="AnnouncementRemainingDays-text"]').should('have.class', 'font-extrabold');
});
});

/// Make sure to adjust the dateTime and eventName variables as needed for your specific testcase
50 changes: 50 additions & 0 deletions cypress/test/campaignTests/Banner.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import { mount } from '@cypress/react';
import Banner from '../../../components/campaigns/Banner';

describe('Banner Component', () => {
it('should not render the banner when the date is not within the valid range', () => {
const today = new Date();
const [day, month, year] = [today.getUTCDate(), today.getUTCMonth(), today.getUTCFullYear()];
if (year > 2022 || month !== 10 || day < 6) {
mount(<Banner />);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use beforeEach here to mount the Banner Component

Copy link
Contributor Author

@reachaadrika reachaadrika Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I can't use BeforeEach since , for some parts in the code , I am rendering Banner after the clock is set , to get the Banner displayed like here const mockDate = new Date(2021, 10, 12).getTime(); cy.clock(mockDate); mount(<Banner />);

cy.get('[data-testid="Banner-main-div"]').should('not.exist');

} else {
mount(<Banner />);
cy.get('[data-testid="Banner-main-div"]').should('be.visible');

}
});

it('should render the banner when the date is within the valid range', () => {
const mockDate = new Date(2021, 10, 12).getTime();
cy.clock(mockDate);
mount(<Banner />);
cy.get('[data-testid="Banner-main-div"]').should('be.visible');
});

it('should display the correct message when the date is within the valid range', () => {
const mockDate = new Date(2021, 10, 12).getTime();
cy.clock(mockDate);
mount(<Banner />);
cy.contains('.font-medium', 'AsyncAPI Conference 2022 has ended').should('be.visible');
});

it('should have a link to the recordings playlist', () => {
const mockDate = new Date(2021, 10, 12).getTime();
cy.clock(mockDate);
mount(<Banner />);
cy.get('[data-testid="Banner-link"]')
.should('have.attr', 'href', 'https://www.youtube.com/playlist?list=PLbi1gRlP7pijRiA32SU36hD_FW-2qyPhl')
.should('have.attr', 'target', '_blank')
.should('have.attr', 'rel', 'noopener noreferrer');
});

it('should have the max-w-screen-xl class in the div element', () => {
const mockDate = new Date(2021, 10, 12).getTime();
cy.clock(mockDate);
mount(<Banner />);
cy.get('.max-w-screen-xl').should('exist');
});
});
Loading