-
-
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 44 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
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,54 @@ | ||
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('[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()); | ||
mount(<AnnouncementHero />); | ||
// 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()); | ||
mount(<AnnouncementHero />); | ||
// 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', '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="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 |
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 />); | ||
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="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'); | ||
}); | ||
}); |
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