Skip to content

Commit 7e5e0d5

Browse files
authored
test(e2e): run the fake suite in Firefox and WebKit, cover /en, fix the file menu (#14)
Run the fake-backend Playwright suite in Chromium, Firefox and WebKit as parallel CI jobs (the real-stack suite stays on Chromium) and add English-locale tests for UI copy, error and rate-limit messages, the unavailable banner, shortcut help and the locale switch. Fixes the file context menu, which never opened in Firefox and WebKit: the auto popover treated the opening right-click's pointerup as an outside click, and WebKit does not focus clicked buttons, so focus left the menu; the menu now uses a manual popover with explicit Escape, outside-click and focus-out handling and a focusable container.
1 parent c29931b commit 7e5e0d5

6 files changed

Lines changed: 145 additions & 26 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ jobs:
3030
run: npm audit --audit-level=low
3131

3232
e2e:
33-
name: End-to-end (fake backend)
33+
# One job per browser, in parallel. Firefox and WebKit run only this
34+
# fake-backend suite; the real-stack suite stays on Chromium.
35+
name: End-to-end (fake backend, ${{ matrix.browser }})
3436
runs-on: ubuntu-latest
3537
timeout-minutes: 20
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
browser: [chromium, firefox, webkit]
3642
steps:
3743
- uses: actions/checkout@v7
3844
- uses: actions/setup-node@v7
@@ -48,22 +54,22 @@ jobs:
4854
uses: actions/cache@v6
4955
with:
5056
path: ~/.cache/ms-playwright
51-
key: playwright-chromium-shell-${{ runner.os }}-${{ steps.pw.outputs.version }}
52-
- name: Install Chromium
57+
key: playwright-${{ matrix.browser }}-${{ runner.os }}-${{ steps.pw.outputs.version }}
58+
- name: Install ${{ matrix.browser }}
5359
if: steps.pw-cache.outputs.cache-hit != 'true'
54-
run: npx playwright install --with-deps --only-shell chromium
55-
- name: Install Chromium system dependencies
60+
# Chromium: the headless shell is enough and much smaller than the full browser.
61+
run: npx playwright install --with-deps ${{ matrix.browser == 'chromium' && '--only-shell' || '' }} ${{ matrix.browser }}
62+
- name: Install ${{ matrix.browser }} system dependencies
5663
if: steps.pw-cache.outputs.cache-hit == 'true'
57-
run: npx playwright install-deps chromium
64+
run: npx playwright install-deps ${{ matrix.browser }}
5865
# Starts `next dev` with NEXT_PUBLIC_RPC_FAKE=1 (playwright.config.ts); no backend is needed.
59-
- run: npm run test:e2e
66+
- run: npm run test:e2e -- --project fake-${{ matrix.browser }}
6067
- name: Upload Playwright report
6168
if: failure()
6269
uses: actions/upload-artifact@v7
6370
with:
64-
name: playwright-report-fake
71+
name: playwright-report-fake-${{ matrix.browser }}
6572
path: |
6673
tests/e2e/report
6774
test-results
6875
retention-days: 7
69-

‎playwright.config.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export default defineConfig({
2626
trace: 'retain-on-failure',
2727
screenshot: 'only-on-failure',
2828
},
29-
projects: [{ name: 'fake-chromium', use: { ...devices['Desktop Chrome'], locale: 'ko-KR' } }],
29+
// Firefox and WebKit run only this fake-backend suite (not the @stack suite), each
30+
// in its own CI job: `npx playwright test --project fake-firefox`.
31+
projects: [
32+
{ name: 'fake-chromium', use: { ...devices['Desktop Chrome'], locale: 'ko-KR' } },
33+
{ name: 'fake-firefox', use: { ...devices['Desktop Firefox'], locale: 'ko-KR' } },
34+
{ name: 'fake-webkit', use: { ...devices['Desktop Safari'], locale: 'ko-KR' } },
35+
],
3036
webServer: {
3137
command: `npx next dev -p ${port}`,
3238
url: `http://localhost:${port}/ko`,

‎src/features/editor/FileMenu.tsx‎

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/**
44
* Context menu for a file (tab or file-list row): set as entry file, rename, close/delete.
5-
* Opens on right-click, the ContextMenu key or Shift+F10; it is a native popover,
6-
* so Esc and clicking elsewhere close it.
5+
* Opens on right-click, the ContextMenu key or Shift+F10. It is a manual popover
6+
* (top layer); Esc, a click elsewhere or moving focus out of it closes it.
77
*
88
* Usage:
99
* const menu = useFileMenu();
@@ -50,35 +50,66 @@ export function FileMenu({ menu, entryFileId, fileName, onSetEntry, onRename, on
5050
const ref = useRef<HTMLDivElement>(null);
5151
const { state, close } = menu;
5252

53+
// A manual popover with its own light dismiss. With popover="auto", Firefox and
54+
// Safari closed the menu as soon as the right-click that opened it ended (its
55+
// pointerup counted as a click outside), so the menu never appeared there.
5356
useEffect(() => {
5457
const el = ref.current;
5558
if (!el || !state) return;
59+
const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
5660
try {
5761
el.showPopover();
5862
} catch {
59-
// Popover API unavailable: the element still renders (absolutely positioned).
63+
// Popover API unavailable: the element still renders (fixed position).
6064
}
6165
el.querySelector<HTMLButtonElement>('button:not(:disabled)')?.focus();
62-
}, [state]);
66+
67+
const onPointerDown = (e: PointerEvent) => {
68+
if (!el.contains(e.target as Node)) close();
69+
};
70+
const onKeyDown = (e: KeyboardEvent) => {
71+
if (e.key !== 'Escape') return;
72+
e.preventDefault();
73+
close();
74+
opener?.focus();
75+
};
76+
const onFocusOut = (e: FocusEvent) => {
77+
if (e.relatedTarget instanceof Node && !el.contains(e.relatedTarget)) close();
78+
};
79+
// From the next task on, so nothing of the gesture that opened the menu can close it.
80+
const timer = setTimeout(() => document.addEventListener('pointerdown', onPointerDown, true));
81+
document.addEventListener('keydown', onKeyDown, true);
82+
el.addEventListener('focusout', onFocusOut);
83+
return () => {
84+
clearTimeout(timer);
85+
document.removeEventListener('pointerdown', onPointerDown, true);
86+
document.removeEventListener('keydown', onKeyDown, true);
87+
el.removeEventListener('focusout', onFocusOut);
88+
try {
89+
el.hidePopover();
90+
} catch {
91+
// already hidden, or no Popover API
92+
}
93+
};
94+
}, [state, close]);
6395

6496
if (!state) return null;
6597
const item =
6698
'flex h-9 w-full items-center gap-3 rounded-md px-3 text-left text-sm text-fg-secondary hover:bg-hover hover:text-fg disabled:opacity-50 disabled:hover:bg-transparent';
6799
const act = (fn: (id: string) => void) => () => {
68-
ref.current?.hidePopover?.();
69100
close();
70101
fn(state.fileId);
71102
};
72103

73104
return (
74105
<div
75106
ref={ref}
76-
popover="auto"
77-
onToggle={(e) => {
78-
if ((e as unknown as ToggleEvent).newState === 'closed') close();
79-
}}
107+
popover="manual"
108+
// Focusable, so a mouse press on an item keeps focus inside the menu. Safari does
109+
// not focus buttons on click and would otherwise move focus to the editor section.
110+
tabIndex={-1}
80111
aria-label={t('menu', { name: fileName(state.fileId) })}
81-
className="fixed m-0 w-56 rounded-lg border border-hair bg-raised p-1.5 text-fg shadow-raised"
112+
className="fixed m-0 w-56 rounded-lg outline-none border border-hair bg-raised p-1.5 text-fg shadow-raised"
82113
style={{ inset: 'auto', left: Math.min(state.x, window.innerWidth - 232), top: Math.min(state.y, window.innerHeight - 140) }}
83114
>
84115
<button type="button" className={item} onClick={act(onSetEntry)} disabled={entryFileId === state.fileId}>

‎tests/e2e/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ Two suites share the helpers in `helpers.ts`:
1010
## Fake backend (no services needed)
1111

1212
```bash
13-
npx playwright install --only-shell chromium # once
14-
npm run test:e2e # starts `next dev` itself
13+
npx playwright install --only-shell chromium firefox webkit # once
14+
npm run test:e2e # starts `next dev` itself; Chromium, Firefox and WebKit
15+
npm run test:e2e -- --project fake-chromium # one browser (CI runs one job per browser)
1516
npm run test:e2e:report
1617
```
1718

‎tests/e2e/fake/english.spec.ts‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* The English interface (/en): copy, error messages and shortcut help.
3+
* The rest of the suite runs in Korean, the default locale.
4+
*/
5+
import { expect, test } from '@playwright/test';
6+
import { headerButton, openPlayground, output, runAndWait, runButton, setEditor } from '../helpers';
7+
8+
test('UI copy is English and the document language is en', async ({ page }) => {
9+
await openPlayground(page, '', 'en');
10+
await expect(page.locator('html')).toHaveAttribute('lang', 'en');
11+
for (const name of ['Templates', 'History', 'Reference', 'Share']) await expect(headerButton(page, name)).toBeVisible();
12+
await expect(runButton(page)).toContainText('Run');
13+
await expect(output(page)).toContainText('Run your code to see the output here');
14+
await expect(page.getByRole('list', { name: 'Open files' })).toBeVisible();
15+
await setEditor(page, '출력("hello")\n');
16+
await runAndWait(page);
17+
await expect(output(page)).toContainText('Finished');
18+
});
19+
20+
test('compile errors are explained in English', async ({ page }) => {
21+
await openPlayground(page, '?fake=compile_error', 'en');
22+
await runAndWait(page);
23+
await expect(output(page)).toContainText('Compile error');
24+
await expect(output(page)).toContainText('Fix the problems listed below, then run again.');
25+
});
26+
27+
test('rate limiting is explained in English with a countdown', async ({ page }) => {
28+
await openPlayground(page, '?fake=rate_limited', 'en');
29+
await runAndWait(page);
30+
await expect(output(page).getByText('Too many runs in a short time').first()).toBeVisible();
31+
await expect(output(page).getByRole('button', { name: /Try again \(\d+\)/ })).toBeDisabled();
32+
});
33+
34+
test('the server-unavailable banner is in English', async ({ page }) => {
35+
await page.goto('/en?fake=unavailable');
36+
await expect(page.getByText("Can't reach the playground server")).toBeVisible({ timeout: 30_000 });
37+
await expect(page.getByRole('button', { name: 'Reconnect' })).toBeVisible();
38+
});
39+
40+
test('shortcut help lists the keys in English', async ({ page }) => {
41+
await openPlayground(page, '', 'en');
42+
await page.locator('body').press('?');
43+
const dialog = page.getByRole('dialog', { name: 'Keyboard shortcuts' });
44+
await expect(dialog).toBeVisible();
45+
await expect(dialog).toContainText('Run code');
46+
await expect(dialog).toContainText('Stop the run');
47+
await expect(dialog).toContainText('Save a draft in this browser');
48+
await page.keyboard.press('Escape');
49+
await expect(dialog).toBeHidden();
50+
});
51+
52+
test('switching the interface language keeps the page and its query', async ({ page }) => {
53+
await openPlayground(page, '?fake=compile_error');
54+
await page.getByRole('button', { name: '메뉴 더 보기' }).click();
55+
await page.getByRole('button', { name: 'English' }).click();
56+
await expect(page).toHaveURL(/\/en\?fake=compile_error$/);
57+
await expect(runButton(page)).toContainText('Run');
58+
});
59+
60+
test('the file context menu opens, works and closes with Escape or a click outside', async ({ page }) => {
61+
await openPlayground(page, '', 'en');
62+
const mainTab = page.getByRole('list', { name: 'Open files' }).getByRole('button', { name: /^main\.ksj/ });
63+
await mainTab.click({ button: 'right' });
64+
const menu = page.locator('[popover][aria-label="main.ksj menu"]');
65+
await expect(menu).toBeVisible();
66+
await page.keyboard.press('Escape');
67+
await expect(menu).toBeHidden();
68+
await mainTab.click({ button: 'right' });
69+
await expect(menu).toBeVisible();
70+
await output(page).click({ position: { x: 10, y: 10 } });
71+
await expect(menu).toBeHidden();
72+
await mainTab.click({ button: 'right' });
73+
await menu.getByRole('button', { name: 'Rename' }).click();
74+
await expect(page.getByRole('textbox', { name: 'New name for main.ksj' })).toBeFocused();
75+
});

‎tests/e2e/helpers.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export const tab = (page: Page, name: string) =>
1414
/** Header buttons (the same actions also exist, hidden, in the "more" menu). */
1515
export const headerButton = (page: Page, name: string | RegExp) => page.locator('header nav').getByRole('button', { name });
1616

17-
/** Opens /ko (plus query) and waits until the editor holds code. */
18-
export async function openPlayground(page: Page, query = '') {
19-
await page.goto(`/ko${query}`);
20-
await expect(page.getByRole('textbox', { name: /코드 편집기/ })).toBeAttached({ timeout: 30_000 });
17+
/** Opens /ko (or /en) plus query and waits until the editor holds code. */
18+
export async function openPlayground(page: Page, query = '', locale: 'ko' | 'en' = 'ko') {
19+
await page.goto(`/${locale}${query}`);
20+
await expect(page.getByRole('textbox', { name: locale === 'ko' ? /코드 편집기/ : /Code editor/ })).toBeAttached({ timeout: 30_000 });
2121
await expect.poll(() => editorValue(page), { timeout: 30_000 }).not.toBe('');
2222
}
2323

0 commit comments

Comments
 (0)