-
Notifications
You must be signed in to change notification settings - Fork 111
test: check the admin screens under a right-to-left locale #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
21985ac
test: check the admin screens under a right-to-left locale
TallblokeUK b97947b
test: cover the toolbar boundary widths and the editor input labels
TallblokeUK 048dd1e
ci: run the right-to-left Playwright project with the default suite
TallblokeUK 98a089e
test: give the right-to-left specs a user and session of their own
TallblokeUK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| // CodeMirror replaces the labelled textarea with an input of its own, so the | ||
| // name a screen reader hears comes from the attribute the plugin sets on that | ||
| // input after the editor starts. One check per editor the plugin creates. | ||
| test.describe('Code editor labels', () => { | ||
| test('the snippet editor input is named', async ({ page }) => { | ||
| await page.goto('/wp-admin/admin.php?page=add-snippet') | ||
| await page.waitForSelector('.CodeMirror') | ||
|
|
||
| await expect(page.locator('.snippet-editor .CodeMirror textarea')).toHaveAttribute('aria-label', 'Snippet code') | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
|
|
||
| test('the settings preview input is named', async ({ page }) => { | ||
| await page.goto('/wp-admin/admin.php?page=snippets-settings§ion=editing') | ||
| await page.waitForSelector('.CodeMirror') | ||
|
|
||
| await expect(page.locator('.CodeMirror textarea').first()).toHaveAttribute('aria-label', 'Code editor preview') | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| // The admin screens under a right-to-left locale. Mirroring is driven by the | ||
| // direction multiplier and logical properties; what can still go wrong is a | ||
| // control pushed past the page edge or a row that no longer fits, so every | ||
| // screen is checked for those rather than for how it looks. | ||
| const SCREENS: [string, string, string][] = [ | ||
| ['settings, editing tab', '/wp-admin/admin.php?page=snippets-settings§ion=editing', '#settings-sections-tabs'], | ||
| ['settings, advanced tab', '/wp-admin/admin.php?page=snippets-settings§ion=advanced', '#settings-sections-tabs'], | ||
| ['snippets list', '/wp-admin/admin.php?page=snippets', '.snippet-view-toggle'], | ||
| ['new snippet', '/wp-admin/admin.php?page=add-snippet', '.CodeMirror'], | ||
| ['import', '/wp-admin/admin.php?page=import-code-snippets', '#wpbody-content'] | ||
| ] | ||
|
|
||
| interface LayoutReport { | ||
| dir: string | ||
| bodyRtl: boolean | ||
| multiplier: string | ||
| pageOverflow: number | ||
| offscreen: string[] | ||
| } | ||
|
|
||
| const inspect = (): LayoutReport => { | ||
| const viewportWidth = document.documentElement.clientWidth | ||
| const selector = ['a', 'button', 'input', 'select'].map(tag => `#wpbody-content ${tag}`).join(', ') | ||
| const controls = Array.from(document.querySelectorAll<HTMLElement>(selector)) | ||
|
|
||
| const offscreen = controls | ||
| .filter(element => null !== element.offsetParent) | ||
| .map(element => ({ element, rect: element.getBoundingClientRect() })) | ||
| .filter(({ rect }) => 0 < rect.width && (0 > rect.left || rect.right > viewportWidth + 1)) | ||
| .map(({ element, rect }) => { | ||
| const name = `${element.tagName.toLowerCase()}.${element.className.split(' ')[0]}` | ||
| return `${name} left=${Math.round(rect.left)} right=${Math.round(rect.right)}` | ||
| }) | ||
|
|
||
| return { | ||
| dir: document.documentElement.getAttribute('dir') ?? 'ltr', | ||
| bodyRtl: document.body.classList.contains('rtl'), | ||
| multiplier: getComputedStyle(document.documentElement).getPropertyValue('--cs-direction-multiplier').trim(), | ||
| pageOverflow: document.documentElement.scrollWidth - viewportWidth, | ||
| offscreen | ||
| } | ||
| } | ||
|
|
||
| test.describe('Right-to-left layout', () => { | ||
| for (const [name, url, ready] of SCREENS) { | ||
| test(`${name} mirrors without spilling off the page`, async ({ page }) => { | ||
| await page.setViewportSize({ width: 1360, height: 900 }) | ||
| await page.goto(url) | ||
| await page.waitForSelector(ready) | ||
|
|
||
| const report = await page.evaluate(inspect) | ||
| test.skip('rtl' !== report.dir, 'The RTL locale is not available on this site, so there is nothing to check.') | ||
|
|
||
| expect(report.bodyRtl, 'WordPress marks the body as RTL').toBe(true) | ||
| expect(report.multiplier, 'the direction multiplier is flipped').toBe('-1') | ||
| expect(report.pageOverflow, 'the page does not scroll sideways').toBeLessThanOrEqual(0) | ||
| expect(report.offscreen, 'no control sits outside the viewport').toEqual([]) | ||
| }) | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { join } from 'path' | ||
| import { expect, test as setup } from '@playwright/test' | ||
| import { wpCli } from './helpers/wpCli' | ||
|
|
||
| // The RTL specs sign in as a user of their own whose locale is right-to-left, | ||
| // so the rest of the suite, which signs in as the usual admin, never sees the | ||
| // site mirrored, whatever order the projects run in. The language pack is | ||
| // fetched from wordpress.org when missing; if that is impossible (offline), | ||
| // the specs notice the page is still left-to-right and skip themselves. | ||
| const RTL_LOCALE = 'he_IL' | ||
| const RTL_USER = 'rtl-admin' | ||
| const SETUP_TIMEOUT_MS = 180000 | ||
|
|
||
| export const rtlAuthFile = join(__dirname, '.auth/rtl-user.json') | ||
|
|
||
| setup('sign in as a right-to-left user', async ({ page }) => { | ||
| setup.setTimeout(SETUP_TIMEOUT_MS) | ||
|
|
||
| try { | ||
| await wpCli(['language', 'core', 'install', RTL_LOCALE]) | ||
| } catch (error) { | ||
| console.warn(`Could not install the ${RTL_LOCALE} language pack; RTL specs will skip.`, error) | ||
| } | ||
|
|
||
| // `user create` takes no locale flag, so the locale is set by a second command. | ||
| try { | ||
| await wpCli(['user', 'get', RTL_USER, '--field=ID']) | ||
| } catch { | ||
| await wpCli(['user', 'create', RTL_USER, `${RTL_USER}@example.org`, '--role=administrator']) | ||
| } | ||
|
|
||
| await wpCli(['user', 'update', RTL_USER, '--user_pass=password', `--locale=${RTL_LOCALE}`]) | ||
|
|
||
| await page.goto('/wp-login.php') | ||
| await page.waitForSelector('#user_login') | ||
| await page.fill('#user_login', RTL_USER) | ||
| await page.fill('#user_pass', 'password') | ||
| await Promise.all([ | ||
| page.waitForLoadState('domcontentloaded'), | ||
| page.click('#wp-submit') | ||
| ]) | ||
| await page.waitForSelector('#wpbody-content, #adminmenu', { timeout: 60000 }) | ||
| await expect(page.locator('#adminmenu')).toBeVisible() | ||
|
|
||
| const dir = await page.evaluate(() => document.documentElement.getAttribute('dir')) | ||
| console.log(`RTL setup: ${RTL_USER} renders the admin with dir="${dir ?? 'ltr'}"`) | ||
|
|
||
| await page.context().storageState({ path: rtlAuthFile }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { test as teardown } from '@playwright/test' | ||
| import { wpCli } from './helpers/wpCli' | ||
|
|
||
| // Remove the right-to-left user the setup created, so the site is left as found. | ||
| teardown('remove the right-to-left user', async () => { | ||
| try { | ||
| await wpCli(['user', 'delete', 'rtl-admin', '--yes']) | ||
| } catch { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| // Already gone, or never created because the setup failed early. | ||
| } | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.