-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Changes from 14 commits
563ac08
7ee04b5
510ae01
c6a39a5
7eab794
13e87e6
418c7fa
d514196
91585c2
d796bcc
f8c3af6
7cf46cc
9132a76
697d573
58f092e
26b16a5
45735ee
0a96798
7d2fd02
595cc09
2d2e676
90443f8
6d8ab7d
b7fad6e
3764428
27f04df
8bdaeac
62934b6
933dde2
ddb3809
5900eae
5f6d2de
dd0b0e4
334887f
d2b1ab9
3f339e9
34f39c8
af76387
26df0f0
017e1f6
bcd67f7
fcd713f
8128550
b80e195
015b510
6027dd5
5af3471
2cd75e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,22 +29,24 @@ export default function AnnouncementHero({ className = '', small = false, hideVi | |
className={`bg-gray-50 border border-gray-200 py-6 rounded ${className} ${ | ||
small ? 'mb-4' : 'mb-12' | ||
}`} | ||
data-testid = "container-div" | ||
> | ||
<Heading | ||
className="countdown-text-gradient" | ||
level="h2" | ||
typeStyle="heading-lg" | ||
|
||
> | ||
AsyncAPI Conf on Tour 2023 | ||
</Heading> | ||
<Heading | ||
className="countdown-text-gradient" | ||
level="h3" | ||
typeStyle="heading-sm" | ||
> | ||
data-testid="sub-heading " > | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the extra trailing space @reachaadrika There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved done |
||
Madrid Edition | ||
</Heading> | ||
<Paragraph typeStyle="body-lg"> | ||
<Paragraph typeStyle="body-lg" > | ||
October, 2023 | Madrid, Spain | ||
</Paragraph> | ||
<AnnouncementRemainingDays dateTime={cfpDeadline} eventName="the end for Call for Speakers." /> | ||
|
@@ -53,6 +55,7 @@ export default function AnnouncementHero({ className = '', small = false, hideVi | |
href="https://sessionize.com/aacot-madrid/" | ||
target="_blank" | ||
text="Submit a session" | ||
data-testid="submit-session" | ||
/> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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="span-text"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh my god. Don't use so generic names @reachaadrika Use the component name, helpful for code readibility purpose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved done |
||
{text} until {eventName} | ||
</span> | ||
) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is already deleted in another PR. It may create issues while merging any of the PRs. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import { mount } from '@cypress/react'; | ||
import AnnouncementHero from '../../../components/campaigns/AnnoucementHero'; | ||
|
||
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()); | ||
|
||
mount(<AnnouncementHero />); | ||
|
||
// Assert that the component is rendered | ||
//check for background color | ||
cy.get('.bg-gray-50').should('exist'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use, For example:
Cypress Code
Benefits of using data-ComponentId, it is isolated from all the JS CSS changes, (post css as well) offers more accuracy to our testing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @reachaadrika is using it at many places. Maybe she forgot about it here, but yeah, the test for background color should be there as it tests whether component is rendering it's properties also. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am checking for background and for rest of the components I will add data attribute There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done the suggested changes , do check @imabp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@reachaadrika still the change is not reflected here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}); | ||
|
||
it('should not render the component when the date is outside the valid range', () => { | ||
// Set the current date to June | ||
const mockDate = new Date('2023-06-01T00:00:00Z'); | ||
cy.clock(mockDate.getTime()); | ||
|
||
mount(<AnnouncementHero />); | ||
|
||
// Assert that the component is not rendered | ||
cy.get('[data-testid="container-div"]').should('not.exist'); | ||
}); | ||
|
||
it('should display the correct event information', () => { | ||
const mockDate = new Date('2023-05-01T00:00:00Z'); | ||
cy.clock(mockDate.getTime()); | ||
|
||
mount(<AnnouncementHero />); | ||
|
||
// Assert the event details | ||
cy.get('[data-testid="container-div"]').contains( 'AsyncAPI Conf on Tour 2023').should('exist'); | ||
cy.get('[data-testid="container-div"]').contains( 'Madrid Edition').should('exist'); | ||
cy.get('[data-testid="container-div"]').contains('October, 2023 | Madrid, Spain').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()); | ||
|
||
mount(<AnnouncementHero />); | ||
|
||
// Assert the link | ||
cy.get('[data-testid="submit-session"]') | ||
.should('have.attr', 'href', 'https://sessionize.com/aacot-madrid/') | ||
.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="container-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="container-div"]').should('have.class', 'mb-12'); | ||
}); | ||
akshatnema marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); |
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="span-text"]').should('have.text', `${text} until ${eventName}`); | ||
|
||
//check class font-extrabold | ||
cy.get('[data-testid="span-text"]').should('have.class', 'font-extrabold'); | ||
}); | ||
}); | ||
|
||
/// Make sure to adjust the dateTime and eventName variables as needed for your specific testcase |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||||||
import React from 'react'; | ||||||||||
import { mount } from '@cypress/react'; | ||||||||||
import Banner from '../../../components/campaigns/Banner'; | ||||||||||
|
||||||||||
describe('Banner Component', () => { | ||||||||||
it('should render the banner when the date is within the valid range', () => { | ||||||||||
const today = new Date(); | ||||||||||
const day = today.getUTCDate(); | ||||||||||
const month = today.getUTCMonth(); | ||||||||||
const year = today.getUTCFullYear(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reachaadrika as they are related, use parallel assignment.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved done |
||||||||||
|
||||||||||
if (year > 2022 || month !== 10 || day < 6) { | ||||||||||
mount(<Banner />); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||
cy.get('[data-testid="main-div-banner"]').should('not.exist'); | ||||||||||
|
||||||||||
} else { | ||||||||||
mount(<Banner />); | ||||||||||
|
||||||||||
cy.get('[data-testid="main-div-banner"]').should('be.visible'); | ||||||||||
|
||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
it('should display the correct message when the date is within the valid range', () => { | ||||||||||
const today = new Date(); | ||||||||||
const day = today.getUTCDate(); | ||||||||||
const month = today.getUTCMonth(); | ||||||||||
const year = today.getUTCFullYear(); | ||||||||||
|
||||||||||
if (year > 2022 || month !== 10 || day < 6) { | ||||||||||
mount(<Banner />); | ||||||||||
|
||||||||||
//checking css class that font is medium or not | ||||||||||
cy.contains('.font-medium', 'AsyncAPI Conference 2022 has ended').should('not.exist'); | ||||||||||
} else { | ||||||||||
mount(<Banner />); | ||||||||||
|
||||||||||
cy.contains('.font-medium', 'AsyncAPI Conference 2022 has ended').should('be.visible'); | ||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
it('should have a link to the recordings playlist', () => { | ||||||||||
const today = new Date(); | ||||||||||
const day = today.getUTCDate(); | ||||||||||
const month = today.getUTCMonth(); | ||||||||||
const year = today.getUTCFullYear(); | ||||||||||
|
||||||||||
if (year === 2022 && month === 10 && day >= 6) { | ||||||||||
mount(<Banner />); | ||||||||||
|
||||||||||
cy.get('[data-testid="linkTorecordings"]') | ||||||||||
.should('have.attr', 'href', 'https://www.youtube.com/playlist?list=PLbi1gRlP7pijRiA32SU36hD_FW-2qyPhl') | ||||||||||
.should('have.attr', 'target', '_blank') | ||||||||||
.should('have.attr', 'rel', 'noopener noreferrer'); | ||||||||||
} else { | ||||||||||
mount(<Banner />); | ||||||||||
|
||||||||||
cy.get('[data-testid="linkTorecordings"]').should('not.exist'); | ||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
|
||||||||||
//check to see if max-w-screen is present or not , for full width element | ||||||||||
it('should have the max-w-screen-xl class in the div element', () => { | ||||||||||
const today = new Date(); | ||||||||||
const day = today.getUTCDate(); | ||||||||||
const month = today.getUTCMonth(); | ||||||||||
const year = today.getUTCFullYear(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use parallel assignment, as said above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved done |
||||||||||
|
||||||||||
if (year === 2022 && month === 10 && day >= 6) { | ||||||||||
mount(<Banner />); | ||||||||||
|
||||||||||
//check for max-w-screen-xl class, since it is an imp check | ||||||||||
cy.get('.max-w-screen-xl').should('exist'); | ||||||||||
|
||||||||||
} else { | ||||||||||
mount(<Banner />); | ||||||||||
cy.get('.max-w-screen-xl').should('not.exist'); | ||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
|
||||||||||
}); | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reachaadrika Why did you changed the CSS here?
You should check for these classNames inside the test file instead of reverting it to previous classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed