Test keyboard and mixed-direction content
Test behavior, not just translated screenshots
Localization testing includes message completeness, plural categories, formatting, reading order, keyboard navigation, focus visibility, reflow and mixed-direction text. A screenshot is useful for detecting layout differences but does not establish keyboard usability or correct speech output. Test with both directions and predictable fixture data. Preserve source order for controls and avoid positive tabindex values or CSS visual reordering that creates a confusing focus sequence.
import test from 'node:test';import assert from 'node:assert/strict';import {selectLocale, titleFor, ticketMessage} from './messages.mjs';import {priceText, bookingDate} from './formats.mjs';test('locale fallback', () => { assert.equal(selectLocale('en-GB'), 'en-GB'); assert.equal(selectLocale('unsupported'), 'en-US'); assert.equal(selectLocale('constructor'), 'en-US');});test('English singular and plural', () => { assert.equal(ticketMessage('en-US', 1), '1 ticket'); assert.equal(ticketMessage('en-GB', 0), '0 tickets'); assert.equal(ticketMessage('en-GB', 2), '2 tickets'); assert.throws(() => ticketMessage('en-US', -1), RangeError);});test('regional title and formatting', () => { assert.equal(titleFor('en-GB'), 'Visitor centre'); assert.equal(priceText('en-US', 1250), new Intl.NumberFormat('en-US', {style:'currency',currency:'USD'}).format(12.5)); assert.equal(bookingDate('en-GB','2026-03-01T00:15:00Z'), new Intl.DateTimeFormat('en-GB',{year:'numeric',month:'short',day:'numeric',timeZone:'UTC'}).format(new Date('2026-03-01T00:15:00Z')));});Run node --test locale.test.mjs in the fixture directory. These tests check explicit English behavior and ensure the formatting options match the contract. They do not prove a translation is idiomatic or that the browser uses the same ICU data. Add tests for invalid prices, malformed timestamps and an unsupported currency; verify that choosing a locale does not mutate the underlying amount.
Create a minimal browser fixture before testing React
<!doctype html><html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Direction test</title> <link rel="stylesheet" href="desk.css"> </head> <body> <main> <h1>Direction test</h1> <section class="desk-panel" dir="rtl"> <div class="desk-row"> <span class="desk-badge">ID-17</span> <p class="desk-text"> A long label and <bdi dir="auto">אבג</bdi> with <bdi dir="ltr">ID-17</bdi> . </p> </div> <label for="search">Search tickets</label> <input id="search" dir="auto"> <button type="button">Apply</button> </section> </main> </body></html>This independent HTML fixture contains the direction and logical CSS behavior without React. Use Tab to reach the input and then the button. The focus sequence follows DOM order in both directions. Enter mixed-direction sample text and inspect caret navigation and selection manually; the correct caret behavior depends on the native browser and operating system. At 320 CSS pixels verify that labels and IDs wrap without horizontal page scrolling. For a deployed React version also test keyboard operation of the locale select, focus restoration when a view is replaced, and document lang/dir after navigation. Do not claim screen-reader or IME compatibility from a DOM assertion.
Turn the checklist into a component test contract
import {test, expect} from '@playwright/test';test('RTL fixture preserves keyboard order', async ({page}) => { await page.goto('/direction.html'); await expect(page.locator('.desk-panel')).toHaveCSS('direction', 'rtl'); await page.keyboard.press('Tab'); await expect(page.getByRole('textbox', {name:'Search tickets'})).toBeFocused(); await page.keyboard.press('Tab'); await expect(page.getByRole('button', {name:'Apply'})).toBeFocused(); await page.setViewportSize({width:320,height:640}); expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);});This staged Playwright Test example requires a reviewed local server, baseURL and installed @playwright/test, with direction.html and desk.css served together. It checks a static fixture, not React. Repeat against the integrated app with semantic locators and both directions, plus long messages, missing keys, fixed timezone and locale changes. Confirm actual keyboard layout/IME and assistive-technology behavior with qualified manual testing. In SSR verify that first client render uses identical message data, locale and timezone as the server. No user locale history is collected in this fixture. Practice: add an LTR counterpart and check the same focus sequence and mirrored border; describe which assertions still require human observation.