|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | +import type { HooksConfig } from '../../setup/index' |
| 6 | +import { expect, test } from '@playwright/experimental-ct-vue' |
| 7 | + |
| 8 | +import AppNavigation from './NcAppNavigation.story.vue' |
| 9 | + |
| 10 | +test.skip(({ browserName }) => browserName !== 'chromium') |
| 11 | + |
| 12 | +// A little bit hacky but we test a wrapper element so we need to use the real NcContent and NcAppNavigation |
| 13 | +test.beforeEach(async ({ mount, page }) => { |
| 14 | + const handle = await page.locator('#app-content').elementHandle() |
| 15 | + expect(handle).not.toBeNull() |
| 16 | + await handle!.evaluate((node) => { node.innerHTML = ''; node.id = 'root' }) |
| 17 | + |
| 18 | + await mount<HooksConfig>(AppNavigation, { |
| 19 | + hooksConfig: { |
| 20 | + routes: [ |
| 21 | + { path: '/', component: AppNavigation }, |
| 22 | + { path: '/foo', component: AppNavigation }, |
| 23 | + ], |
| 24 | + }, |
| 25 | + }) |
| 26 | +}) |
| 27 | + |
| 28 | +test('opens on n keyboard press', async ({ page }) => { |
| 29 | + await expect(page.getByText('First')).toBeVisible(); |
| 30 | + |
| 31 | + // cy.get('nav').then(($nav) => { |
| 32 | + // const id = $nav.attr('id') |
| 33 | + // cy.get(`[aria-controls="${id}"`).as('appNavigationToggle') |
| 34 | + // cy.get('@appNavigationToggle').should('have.attr', 'aria-expanded', 'true') |
| 35 | + // cy.get('nav').should('have.attr', 'aria-hidden', 'false') |
| 36 | + // cy.get('nav').should('not.have.attr', 'inert') |
| 37 | + |
| 38 | + // // close the sidebar |
| 39 | + // cy.get('@appNavigationToggle').click() |
| 40 | + |
| 41 | + // cy.get('@appNavigationToggle').should('have.attr', 'aria-expanded', 'false') |
| 42 | + // cy.get('nav').should('have.attr', 'aria-hidden', 'true') |
| 43 | + // cy.get('nav').should('have.attr', 'inert') |
| 44 | + |
| 45 | + // // open the sidebar with the keyboard |
| 46 | + // cy.get('body').type('n') |
| 47 | + |
| 48 | + // cy.get('@appNavigationToggle').should('have.attr', 'aria-expanded', 'true') |
| 49 | + // cy.get('nav').should('have.attr', 'aria-hidden', 'false') |
| 50 | + // cy.get('nav').should('not.have.attr', 'inert') |
| 51 | + |
| 52 | + // // make sure we auto-focus the first item |
| 53 | + // cy.document().then((doc) => { |
| 54 | + // const activeElement = doc.activeElement |
| 55 | + // const navigation = doc.querySelector('nav') |
| 56 | + // // eslint-disable-next-line no-unused-expressions |
| 57 | + // expect(navigation?.contains(activeElement)).to.be.true |
| 58 | + // }) |
| 59 | + // }) |
| 60 | +}) |
| 61 | + |
| 62 | +test('closes on n keyboard press', async ({ page }) => { |
| 63 | + await expect(page.getByText('First')).toBeVisible() |
| 64 | + const navigation = page.getByRole('navigation') |
| 65 | + |
| 66 | + await expect(navigation).toHaveAttribute('aria-hidden', 'false') |
| 67 | + await expect(navigation).not.toHaveAttribute('inert') |
| 68 | + |
| 69 | + // pressing n does nothing until we focus something within |
| 70 | + page.locator('body').press('n') |
| 71 | + await expect(navigation).toHaveAttribute('aria-hidden', 'false') |
| 72 | + await expect(navigation).not.toHaveAttribute('inert') |
| 73 | + |
| 74 | + // focus something within |
| 75 | + navigation.getByRole('link').first().focus() |
| 76 | + |
| 77 | + // pressing n closes the sidebar |
| 78 | + page.locator('body').press('n') |
| 79 | + await expect(navigation).toHaveAttribute('aria-hidden', 'true') |
| 80 | + await expect(navigation).toHaveAttribute('inert') |
| 81 | +}) |
0 commit comments