-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: e2e tests on accordion component (issue/147) (#148)
* Added accordion e2e test * Update test/e2e/accordion.cy.js Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com> * Corrected test --------- Co-authored-by: Cahir O'Doherty <41006337+cahirodoherty-learningpool@users.noreply.github.com>
- Loading branch information
1 parent
f3daca8
commit 3b8f4cb
Showing
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
describe('Accordion', function () { | ||
function loopThroughAccordion(accordionComponent) { | ||
const items = accordionComponent._items | ||
cy.get('.accordion-item').should('have.length', items.length) | ||
// Check each accordion item | ||
items.forEach((item, index) => { | ||
const bodyWithoutHtml = item.body.replace(/<[^>]*>/g, '') | ||
// Check within the correct item so it doesn't detect visibility from other items | ||
cy.get('.accordion-item').eq(index).within(() => { | ||
cy.get('.accordion-item__btn.is-visited').should('not.exist') | ||
cy.get('.accordion-item__body-inner').should('not.be.visible') | ||
cy.get('.accordion-item__title').should('contain', item.title).click() | ||
cy.get('.accordion-item__btn.is-visited').should('exist') | ||
cy.get('.accordion-item__body-inner') | ||
.should('be.visible') | ||
.should('contain', bodyWithoutHtml) | ||
cy.get('.accordion-item__title').click() | ||
cy.get('.accordion-item__body-inner').should('not.be.visible') | ||
}) | ||
}) | ||
} | ||
|
||
beforeEach(function () { | ||
cy.getData() | ||
}); | ||
|
||
it('should display the accordion component', function () { | ||
const accordionComponents = this.data.components.filter((component) => component._component === 'accordion') | ||
accordionComponents.forEach((accordionComponent) => { | ||
cy.visit(`/#/preview/${accordionComponent._id}`); | ||
const bodyWithoutHtml = accordionComponent.body.replace(/<[^>]*>/g, '') | ||
|
||
// Test basic accordion component | ||
cy.testContainsOrNotExists('.accordion__title', accordionComponent.displayTitle) | ||
cy.testContainsOrNotExists('.accordion__body', bodyWithoutHtml) | ||
cy.testContainsOrNotExists('.accordion__instruction', accordionComponent.instruction) | ||
|
||
// Test accordion items | ||
loopThroughAccordion(accordionComponent) | ||
|
||
// Allow the component to load and run external custom tests | ||
cy.wait(1000) | ||
}) | ||
}); | ||
}); |