pcbjam/tests/e2e/clipboard.spec.ts
Istvan Matejcsok 6034a0550d eeschema copy/paste fix: wx UTF-8 text dataobj (c1f1477) + regression specs
Cmd+C/Cmd+V in the wasm eeschema pasted a stray "(" SCH_TEXT — the stroke
font renders it as a small blue arc — instead of the copied symbol, and any
copy reached navigator.clipboard as a single character. Root cause and fix
live in wxwidgets (90bbad29822: UTF-8 wxDF_UNICODETEXT + the port's missing
GetAllFormats key function; c1f14775ba3: empty-read cache fallback + no
browser pre-clear on copy). This bump carries them plus the guards:

- tests/kicad/eeschema-copy-paste.spec.ts: chromium asserts the full
  multi-form (lib_symbols …)(symbol …) blob reaches navigator.clipboard;
  both engines assert copy → paste → save yields a second symbol and no
  stray (text …) item (firefox exercises the m_textCache fallback path).
  The kicad-chromium project now grants clipboard-read/write. NB the kicad
  projects' device UAs claim Windows, so specs must send plain Control+…
  — ControlOrMeta resolves to Meta on a mac host, which the "Windows" app
  ignores, and the bare key fires eeschema hotkeys instead.
- tests/e2e/textdataobj.spec.ts + Makefile.wasm target `textdataobj`:
  drives the wx-repo harness app (wxwidgets/tests/wasm/textdataobj_test.cpp)
  and asserts the SUITE-DONE failure counters plus the full-string browser
  round-trip, sentinel-seeded so a failed write cannot read as stale success.
- tests/e2e/clipboard.spec.ts: the Copy test now asserts the full input
  text reaches the clipboard (previously truncated to "S").

Verified locally: all specs red on the old wx, green after; wx-chromium
320/320, kicad-chromium 121/121 (collab specs env-gated).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-26 11:21:00 +02:00

141 lines
6.2 KiB
TypeScript

// wxClipboard Tests - Clipboard operations for KiCad copy/paste
// Uses element registry for semantic element identification
import { test, expect, waitForWxApp, clickByLabel } from './utils/fixtures';
import { stableShot } from './utils/element-tracker';
test.describe('wxClipboard Tests', () => {
test('Clipboard test app loads successfully', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
await waitForWxApp(page);
await stableShot(page, 'clipboard-01-loaded.png', { fullPage: true });
const hasStartupLog = testLogger.consoleLogs.some(l =>
l.includes('wxClipboard test app started') || l.includes('Clipboard test app started')
);
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('Copy button copies text to clipboard', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
await waitForWxApp(page);
// Seed the clipboard so a silently-failed write cannot pass as success.
await page.evaluate(() => navigator.clipboard.writeText('SENTINEL-BEFORE-COPY'));
// Click "Copy to Clipboard" button
await clickByLabel(page, 'Copy to Clipboard');
// Either success (real clipboard worked) or at least attempt was made
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should succeed or at least attempt' }).toBe(true);
// The FULL input text must reach the browser clipboard — the UTF-32/UTF-8
// mixup in wxTextDataObject used to truncate it to its first character.
const clip = await page.evaluate(() => navigator.clipboard.readText());
expect(clip).toBe('Sample text for clipboard test');
await stableShot(page, 'clipboard-02-copy-clicked.png', { fullPage: true });
});
test('Paste button retrieves text from clipboard', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
await waitForWxApp(page);
// First copy something
await clickByLabel(page, 'Copy to Clipboard');
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should log activity' }).toBe(true);
// Click "Paste from Clipboard" button
await clickByLabel(page, 'Paste from Clipboard');
// Either we successfully pasted, there was no text (valid), or at least we attempted
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Pasted')) ||
(l.includes('WARNING') && l.includes('No text data')) ||
l.includes('Attempting to paste')
), { message: 'Paste should succeed or report no text' }).toBe(true);
await stableShot(page, 'clipboard-03-paste-clicked.png', { fullPage: true });
});
test('Check clipboard button reports clipboard content', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
await waitForWxApp(page);
// First copy something to ensure clipboard has content
await clickByLabel(page, 'Copy to Clipboard');
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should log activity' }).toBe(true);
// Click "Check Clipboard" button
await clickByLabel(page, 'Check Clipboard');
// Check for clipboard content report
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('Clipboard contains') || l.includes('Checking clipboard')
), { message: 'Check should report clipboard contents' }).toBe(true);
await stableShot(page, 'clipboard-04-check-clicked.png', { fullPage: true });
});
test('Clear clipboard button clears clipboard', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
await waitForWxApp(page);
// First copy something
await clickByLabel(page, 'Copy to Clipboard');
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should log activity' }).toBe(true);
// Click "Clear Clipboard" button
await clickByLabel(page, 'Clear Clipboard');
// Check for SUCCESS log or at least attempt
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Clipboard cleared')) || l.includes('Attempting to clear')
), { message: 'Clear should succeed or at least attempt' }).toBe(true);
await stableShot(page, 'clipboard-05-clear-clicked.png', { fullPage: true });
});
test('Full clipboard flow: copy, check, paste, clear', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
await waitForWxApp(page);
// 1. Copy
await clickByLabel(page, 'Copy to Clipboard');
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Copied') || l.includes('Attempting to copy')
), { message: 'Copy should log activity' }).toBe(true);
// 2. Check
await clickByLabel(page, 'Check Clipboard');
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('Clipboard contains') || l.includes('Checking clipboard')
), { message: 'Check should report clipboard' }).toBe(true);
// 3. Paste
await clickByLabel(page, 'Paste from Clipboard');
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Pasted') || l.includes('Attempting to paste')
), { message: 'Paste should log activity' }).toBe(true);
// 4. Clear
await clickByLabel(page, 'Clear Clipboard');
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Clipboard cleared') || l.includes('Attempting to clear')
), { message: 'Clear should log activity' }).toBe(true);
await stableShot(page, 'clipboard-06-full-flow.png', { fullPage: true });
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
});