|
| 1 | +const { test, expect } = require('@playwright/test'); |
| 2 | + |
| 3 | +const ADMIN_PATH = '/wp-admin/admin.php?page=supersede-css-jlg'; |
| 4 | +const DEFAULT_USERNAME = process.env.WP_USERNAME || 'admin'; |
| 5 | +const DEFAULT_PASSWORD = process.env.WP_PASSWORD || 'password'; |
| 6 | + |
| 7 | +async function authenticate(page, adminUrl, credentials) { |
| 8 | + const loginUrl = `/wp-login.php?redirect_to=${encodeURIComponent(adminUrl)}`; |
| 9 | + await page.goto(loginUrl, { waitUntil: 'domcontentloaded' }); |
| 10 | + |
| 11 | + const usernameInput = page.locator('#user_login'); |
| 12 | + if (await usernameInput.isVisible()) { |
| 13 | + await usernameInput.fill(credentials.username); |
| 14 | + await page.locator('#user_pass').fill(credentials.password); |
| 15 | + await Promise.all([ |
| 16 | + page.waitForNavigation({ waitUntil: 'networkidle' }), |
| 17 | + page.locator('#wp-submit').click(), |
| 18 | + ]); |
| 19 | + } |
| 20 | + |
| 21 | + await page.goto(adminUrl, { waitUntil: 'networkidle' }); |
| 22 | +} |
| 23 | + |
| 24 | +test.describe('Command palette accessibility', () => { |
| 25 | + test('search input exposes translated accessible name', async ({ page }, testInfo) => { |
| 26 | + const baseURL = testInfo.project.use.baseURL || 'http://localhost:8889'; |
| 27 | + const adminUrl = new URL(ADMIN_PATH, baseURL).toString(); |
| 28 | + |
| 29 | + await authenticate(page, adminUrl, { |
| 30 | + username: DEFAULT_USERNAME, |
| 31 | + password: DEFAULT_PASSWORD, |
| 32 | + }); |
| 33 | + |
| 34 | + await page.waitForFunction( |
| 35 | + () => Boolean(window.SSC && window.SSC.i18n && window.SSC.i18n.commandPaletteSearchLabel) |
| 36 | + ); |
| 37 | + const expectedLabel = await page.evaluate(() => window.SSC.i18n.commandPaletteSearchLabel); |
| 38 | + |
| 39 | + const commandPaletteButton = page.locator('#ssc-cmdk'); |
| 40 | + await expect(commandPaletteButton).toBeVisible(); |
| 41 | + await commandPaletteButton.click(); |
| 42 | + |
| 43 | + const searchInput = page.locator('#ssc-cmdp-search'); |
| 44 | + await expect(searchInput).toBeVisible(); |
| 45 | + await expect(searchInput).toHaveAccessibleName(expectedLabel); |
| 46 | + }); |
| 47 | +}); |
0 commit comments