|
| 1 | +describe('accordion', () => { |
| 2 | + const verifyAccordionSetup = () => { |
| 3 | + cy.get('brn-accordion').should('have.attr', 'data-state', 'closed'); |
| 4 | + cy.get('brn-accordion-item').should('have.length', 3); |
| 5 | + cy.get('brn-accordion-item').first().as('firstItem'); |
| 6 | + cy.get('@firstItem').next().as('secondItem'); |
| 7 | + cy.get('@secondItem').next().as('thirdItem'); |
| 8 | + |
| 9 | + cy.get('@firstItem').should('have.attr', 'data-state', 'closed'); |
| 10 | + cy.get('@secondItem').should('have.attr', 'data-state', 'closed'); |
| 11 | + cy.get('@thirdItem').should('have.attr', 'data-state', 'closed'); |
| 12 | + |
| 13 | + cy.get('@firstItem') |
| 14 | + .find('brn-accordion-trigger') |
| 15 | + .should('have.attr', 'role', 'heading') |
| 16 | + .should('have.id', 'brn-accordion-trigger-0') |
| 17 | + .should('have.attr', 'data-state', 'closed') |
| 18 | + .should('have.attr', 'aria-expanded', 'false'); |
| 19 | + cy.get('@firstItem') |
| 20 | + .find('brn-accordion-content') |
| 21 | + .should('have.attr', 'role', 'region') |
| 22 | + .should('have.id', 'brn-accordion-content-0') |
| 23 | + .should('have.attr', 'data-state', 'closed'); |
| 24 | + }; |
| 25 | + |
| 26 | + const verifyAccordionStateOpen = () => { |
| 27 | + cy.get('brn-accordion').should('have.attr', 'data-state', 'open'); |
| 28 | + }; |
| 29 | + |
| 30 | + const verifyAccordionStateClosed = () => { |
| 31 | + cy.get('brn-accordion').should('have.attr', 'data-state', 'closed'); |
| 32 | + }; |
| 33 | + |
| 34 | + const verifyAccordionFirstItemStateOpen = () => { |
| 35 | + cy.get('@firstItem').should('have.attr', 'data-state', 'open'); |
| 36 | + cy.get('@firstItem') |
| 37 | + .find('brn-accordion-trigger') |
| 38 | + .should('have.attr', 'data-state', 'open') |
| 39 | + .should('have.attr', 'aria-expanded', 'true'); |
| 40 | + cy.get('@firstItem').find('brn-accordion-content').should('have.attr', 'data-state', 'open'); |
| 41 | + }; |
| 42 | + |
| 43 | + const verifyAccordionFirstItemStateClosed = () => { |
| 44 | + cy.get('@firstItem').should('have.attr', 'data-state', 'closed'); |
| 45 | + cy.get('@firstItem') |
| 46 | + .find('brn-accordion-trigger') |
| 47 | + .should('have.attr', 'data-state', 'closed') |
| 48 | + .should('have.attr', 'aria-expanded', 'false'); |
| 49 | + cy.get('@firstItem').find('brn-accordion-content').should('have.attr', 'data-state', 'closed'); |
| 50 | + }; |
| 51 | + |
| 52 | + const verifyAccordionSecondItemStateOpen = () => { |
| 53 | + cy.get('@secondItem').should('have.attr', 'data-state', 'open'); |
| 54 | + cy.get('@secondItem') |
| 55 | + .find('brn-accordion-trigger') |
| 56 | + .should('have.attr', 'data-state', 'open') |
| 57 | + .should('have.attr', 'aria-expanded', 'true'); |
| 58 | + cy.get('@secondItem').find('brn-accordion-content').should('have.attr', 'data-state', 'open'); |
| 59 | + }; |
| 60 | + |
| 61 | + const verifyAccordionSecondItemStateClosed = () => { |
| 62 | + cy.get('@secondItem').should('have.attr', 'data-state', 'closed'); |
| 63 | + cy.get('@secondItem') |
| 64 | + .find('brn-accordion-trigger') |
| 65 | + .should('have.attr', 'data-state', 'closed') |
| 66 | + .should('have.attr', 'aria-expanded', 'false'); |
| 67 | + cy.get('@secondItem').find('brn-accordion-content').should('have.attr', 'data-state', 'closed'); |
| 68 | + }; |
| 69 | + |
| 70 | + describe('default', () => { |
| 71 | + beforeEach(() => { |
| 72 | + cy.visit('/iframe.html?id=accordion--default'); |
| 73 | + cy.injectAxe(); |
| 74 | + }); |
| 75 | + |
| 76 | + it('click on trigger should open and close it content', () => { |
| 77 | + verifyAccordionSetup(); |
| 78 | + |
| 79 | + // click trigger first item to open it content |
| 80 | + cy.get('@firstItem').find('brn-accordion-trigger').click(); |
| 81 | + verifyAccordionStateOpen(); |
| 82 | + verifyAccordionFirstItemStateOpen(); |
| 83 | + |
| 84 | + // click trigger first item to close it content |
| 85 | + cy.get('@firstItem').find('brn-accordion-trigger').click(); |
| 86 | + verifyAccordionStateClosed(); |
| 87 | + verifyAccordionFirstItemStateClosed(); |
| 88 | + }); |
| 89 | + |
| 90 | + it('click on trigger should open it content and click on another trigger should closed previous content and open newly triggered content', () => { |
| 91 | + verifyAccordionSetup(); |
| 92 | + |
| 93 | + // click trigger first item to open it content |
| 94 | + cy.get('@firstItem').find('brn-accordion-trigger').click(); |
| 95 | + verifyAccordionStateOpen(); |
| 96 | + verifyAccordionFirstItemStateOpen(); |
| 97 | + |
| 98 | + // click trigger second item to open it content and close previous content |
| 99 | + cy.get('@secondItem').find('brn-accordion-trigger').click(); |
| 100 | + verifyAccordionStateOpen(); |
| 101 | + verifyAccordionSecondItemStateOpen(); |
| 102 | + verifyAccordionFirstItemStateClosed(); |
| 103 | + |
| 104 | + // click trigger second item to close it content |
| 105 | + cy.get('@secondItem').find('brn-accordion-trigger').click(); |
| 106 | + verifyAccordionStateClosed(); |
| 107 | + verifyAccordionSecondItemStateClosed(); |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments