Skip to content

Commit

Permalink
Added accordion e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmyadams committed Feb 28, 2024
1 parent f3daca8 commit 7ea3deb
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/e2e/accordion.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
describe('Accordion', function () {
function loopThroughAccordion(accordionComponent) {
const itemsCount = Object.keys(accordionComponent._items).length
cy.get('.accordion-item').should('have.length', itemsCount)
for (let i = 0; i < itemsCount; i++) {
const bodyWithoutHtml = accordionComponent._items[i].body.replace(/<[^>]*>/g, '')
cy.get('.accordion-item').eq(i).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', accordionComponent._items[i].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, '')

cy.testContainsOrNotExists('.accordion__title', accordionComponent.displayTitle)
cy.testContainsOrNotExists('.accordion__body', bodyWithoutHtml)
cy.testContainsOrNotExists('.accordion__instruction', accordionComponent.instruction)

loopThroughAccordion(accordionComponent)

cy.wait(1000)
})
});
});

0 comments on commit 7ea3deb

Please sign in to comment.