|
| 1 | +import SettingsCard from './SettingsCard.vue' |
| 2 | +import IconLaptop from '~icons/mdi/laptop' |
| 3 | + |
| 4 | +describe('<SettingsCard />', () => { |
| 5 | + const title = 'My Device Settings' |
| 6 | + const description = 'The configuration I\'m passing in.' |
| 7 | + const headerSelector = '[data-cy="collapsible-header"]' |
| 8 | + const collapsibleSelector = '[data-cy="collapsible"]' |
| 9 | + |
| 10 | + it('renders', () => { |
| 11 | + const contentSelector = '[data-testid=content]' |
| 12 | + |
| 13 | + cy.mount(() => ( |
| 14 | + <div class="p-24px"> |
| 15 | + <SettingsCard title={title} description={description} icon={IconLaptop} maxHeight="800px"> |
| 16 | + <div data-testid="content"> |
| 17 | + <p>The body of the content</p> |
| 18 | + </div> |
| 19 | + </SettingsCard> |
| 20 | + </div> |
| 21 | + )) |
| 22 | + |
| 23 | + cy.get(contentSelector).should('not.exist') |
| 24 | + cy.findByText(title).click() |
| 25 | + cy.get(contentSelector).should('be.visible') |
| 26 | + cy.findByText(title).click() |
| 27 | + .get(contentSelector).should('not.exist') |
| 28 | + |
| 29 | + // expected aria and keyboard behavior with space and enter keys: |
| 30 | + cy.get(collapsibleSelector).should('be.focused') |
| 31 | + .get('body').type(' ') |
| 32 | + .get(contentSelector).should('be.visible') |
| 33 | + .get(headerSelector).should('have.attr', 'aria-expanded', 'true') |
| 34 | + .get('body').type(' ') |
| 35 | + .get(contentSelector).should('not.exist') |
| 36 | + .get(headerSelector).should('have.attr', 'aria-expanded', 'false') |
| 37 | + .get('body').type('{enter}') |
| 38 | + .get(contentSelector).should('be.visible') |
| 39 | + .get('body').type('{enter}') |
| 40 | + .get(contentSelector).should('not.exist') |
| 41 | + }) |
| 42 | + |
| 43 | + it('displays a nice focus state', () => { |
| 44 | + const title2 = 'Project Settings again' |
| 45 | + const description2 = 'Lorem ipsum dolor sit amet' |
| 46 | + |
| 47 | + cy.mount(() => ( |
| 48 | + <div class="p-24px"> |
| 49 | + <SettingsCard title={title} description={description} icon={IconLaptop} maxHeight="800px"> |
| 50 | + <div data-testid="content"> |
| 51 | + <p>The body of the content</p> |
| 52 | + </div> |
| 53 | + </SettingsCard> |
| 54 | + <SettingsCard title={title2} description={description2} icon={IconLaptop} maxHeight="800px"> |
| 55 | + <div data-testid="content"> |
| 56 | + <p>Second content</p> |
| 57 | + </div> |
| 58 | + </SettingsCard> |
| 59 | + </div> |
| 60 | + )) |
| 61 | + |
| 62 | + cy.contains(collapsibleSelector, title).focus().type(' ') |
| 63 | + }) |
| 64 | +}) |
0 commit comments