-
-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding unit tests for calendar modal and caption component (#1811)
- Loading branch information
1 parent
e5e9c78
commit 33b2479
Showing
6 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { mount } from 'cypress/react'; | ||
import Calendar from '../../components/Calendar'; | ||
import eventsData from '../../config/meetings.json'; | ||
|
||
describe('Calendar component', () => { | ||
beforeEach(() => { | ||
mount(<Calendar />); | ||
}); | ||
|
||
it('renders the upcoming events', () => { | ||
cy.get('[data-testid="Calendar-list-item"]').should('have.length', eventsData.length); | ||
}); | ||
|
||
it('renders the "View Calendar" button if events exist', () => { | ||
if (eventsData.length > 0) { | ||
cy.get('[data-testid="Calendar-button"]').should('be.visible'); | ||
} else { | ||
cy.get('[data-testid="Calendar-button"]').should('not.exist'); | ||
} | ||
}); | ||
|
||
it('renders the "No meetings scheduled" message if no events exist', () => { | ||
if (eventsData.length === 0) { | ||
cy.contains('There are no meetings scheduled for next few days.').should('be.visible'); | ||
} else { | ||
cy.contains('There are no meetings scheduled for next few days.').should('not.exist'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { mount } from 'cypress/react'; | ||
import Caption from '../../components/Caption'; | ||
|
||
describe('Caption component', () => { | ||
beforeEach(() => { | ||
mount(<Caption>AsyncAPI</Caption>); | ||
}); | ||
|
||
it('renders the caption text correctly', () => { | ||
cy.contains('AsyncAPI').should('be.visible'); | ||
}); | ||
|
||
it('check correct CSS classes', () => { | ||
cy.get('[data-testid="Caption-paragraph"]').should('have.class', 'text-center').and('have.class', 'text-xs') | ||
.and('have.class', 'text-gray-500') | ||
.and('have.class', 'mt-2'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { mount } from 'cypress/react'; | ||
import Modal from '../../components/Modal'; | ||
|
||
|
||
describe('Modal', () => { | ||
it('should call onModalClose when the close button is clicked', () => { | ||
const onModalClose = cy.stub().as('onModalClose'); | ||
mount(<Modal title="Test Modal" onModalClose={onModalClose} />); | ||
|
||
cy.get('[data-testid="Modal-close"]').click(); | ||
|
||
cy.get('@onModalClose').should('have.been.calledOnce'); | ||
}); | ||
|
||
it('should call onModalClose when the backdrop is clicked', () => { | ||
const onModalClose = cy.stub().as('onModalClose'); | ||
mount(<Modal title="Test Modal" onModalClose={onModalClose} />); | ||
|
||
cy.get('.backdrop-blur').click(); | ||
|
||
cy.get('@onModalClose').should('have.been.calledOnce'); | ||
}); | ||
|
||
it('should call onModalClose when the Escape key is pressed', () => { | ||
const onModalClose = cy.stub().as('onModalClose'); | ||
mount(<Modal title="Test Modal" onModalClose={onModalClose} />); | ||
|
||
cy.get('.backdrop-blur').type('{esc}'); | ||
|
||
cy.get('@onModalClose').should('have.been.calledOnce'); | ||
}); | ||
}); |