2025-12-03 11:27:00 +01:00
|
|
|
import { test, expect } from './utils/fixtures';
|
2026-07-07 10:50:24 +02:00
|
|
|
import { clickByLabel, waitForWxApp, stableShot } from './utils/element-tracker';
|
2025-12-03 11:27:00 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wxStyledTextCtrl Tests
|
|
|
|
|
*
|
|
|
|
|
* KiCad uses wxStyledTextCtrl (Scintilla) for:
|
|
|
|
|
* - DRC rules editor
|
|
|
|
|
* - Python console
|
|
|
|
|
* - Custom script editors
|
|
|
|
|
*
|
|
|
|
|
* Layout (from screenshot):
|
|
|
|
|
* - Description text at top
|
|
|
|
|
* - Buttons at y≈107 (centered):
|
|
|
|
|
* - Python: x≈345
|
|
|
|
|
* - DRC Rules: x≈433
|
|
|
|
|
* - Plain: x≈522
|
|
|
|
|
* - Insert Sample: x≈617
|
|
|
|
|
* - Clear: x≈719
|
|
|
|
|
* - Line Numbers: x≈828
|
|
|
|
|
* - Fold All: x≈932
|
|
|
|
|
* - wxStyledTextCtrl editor area: y≈130 to y≈500
|
|
|
|
|
* - Event log at bottom
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
test.describe('wxStyledTextCtrl Tests', () => {
|
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
|
await page.goto('/standalone/stc/stc_test.html');
|
2026-07-07 10:50:24 +02:00
|
|
|
// Deterministic app-readiness: canvas visible + wx element registry populated.
|
|
|
|
|
await waitForWxApp(page);
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('STC test app loads successfully', async ({ page, testLogger }) => {
|
2026-07-07 10:50:24 +02:00
|
|
|
// Readiness (canvas + registry populated) is handled by beforeEach's waitForWxApp,
|
|
|
|
|
// which is the load gate. The original only asserted no init errors (its startup-log
|
|
|
|
|
// check was computed but never asserted — the app logs [STC_EVENT], not a start line).
|
|
|
|
|
await stableShot(page, 'stc-01-loaded.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
expect(testLogger.errors.filter((e) => !e.includes('favicon'))).toHaveLength(0);
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Python syntax highlighting is enabled by default', async ({ page }) => {
|
|
|
|
|
// Visual verification - the editor should show Python code with colors
|
2026-07-07 10:50:24 +02:00
|
|
|
// (import, def, for keywords should be highlighted). Static default state.
|
|
|
|
|
await stableShot(page, 'stc-02-python-default.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('DRC Rules mode can be activated', async ({ page, testLogger }) => {
|
2025-12-30 14:17:51 +01:00
|
|
|
// Click DRC Rules button using element registry
|
|
|
|
|
await clickByLabel(page, 'DRC Rules');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(
|
|
|
|
|
() => testLogger.consoleLogs.some((log) => log.includes('DRC rules lexer configured')),
|
|
|
|
|
{ message: 'DRC rules lexer configured is logged' }
|
|
|
|
|
)
|
|
|
|
|
.toBe(true);
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-03-drc-mode.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Plain text mode can be activated', async ({ page, testLogger }) => {
|
2025-12-30 14:17:51 +01:00
|
|
|
// Click Plain button using element registry
|
|
|
|
|
await clickByLabel(page, 'Plain');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(
|
|
|
|
|
() => testLogger.consoleLogs.some((log) => log.includes('Plain text mode enabled')),
|
|
|
|
|
{ message: 'Plain text mode enabled is logged' }
|
|
|
|
|
)
|
|
|
|
|
.toBe(true);
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-04-plain-mode.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Insert Sample button adds code', async ({ page, testLogger }) => {
|
2025-12-30 14:17:51 +01:00
|
|
|
// Click Insert Sample button using element registry
|
|
|
|
|
await clickByLabel(page, 'Insert Sample');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(
|
|
|
|
|
() => testLogger.consoleLogs.some((log) => log.includes('Inserted sample code')),
|
|
|
|
|
{ message: 'Inserted sample code is logged' }
|
|
|
|
|
)
|
|
|
|
|
.toBe(true);
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-05-insert-sample.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Clear button clears editor content', async ({ page, testLogger }) => {
|
2025-12-30 14:17:51 +01:00
|
|
|
// Click Clear button using element registry
|
|
|
|
|
await clickByLabel(page, 'Clear');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(() => testLogger.consoleLogs.some((log) => log.includes('Text cleared')), {
|
|
|
|
|
message: 'Text cleared is logged',
|
|
|
|
|
})
|
|
|
|
|
.toBe(true);
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-06-cleared.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Line numbers can be toggled', async ({ page, testLogger }) => {
|
2025-12-30 14:17:51 +01:00
|
|
|
// Click Line Numbers button using element registry
|
|
|
|
|
await clickByLabel(page, 'Line Numbers');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(
|
|
|
|
|
() =>
|
|
|
|
|
testLogger.consoleLogs.some(
|
|
|
|
|
(log) => log.includes('Line numbers hidden') || log.includes('Line numbers shown')
|
|
|
|
|
),
|
|
|
|
|
{ message: 'Line numbers toggle is logged' }
|
|
|
|
|
)
|
|
|
|
|
.toBe(true);
|
|
|
|
|
|
|
|
|
|
await stableShot(page, 'stc-07-line-numbers-toggle.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Fold All button works', async ({ page, testLogger }) => {
|
2025-12-30 14:17:51 +01:00
|
|
|
// Click Fold All button using element registry
|
|
|
|
|
await clickByLabel(page, 'Fold All');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(() => testLogger.consoleLogs.some((log) => log.includes('All code folded')), {
|
|
|
|
|
message: 'All code folded is logged',
|
|
|
|
|
})
|
|
|
|
|
.toBe(true);
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-08-folded.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Editor can receive text input', async ({ page, testLogger }) => {
|
|
|
|
|
const canvas = page.locator('canvas');
|
|
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
// Clear the editor first using element registry, and wait deterministically
|
|
|
|
|
// for the clear to commit before typing.
|
2025-12-30 14:17:51 +01:00
|
|
|
await clickByLabel(page, 'Clear');
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(() => testLogger.consoleLogs.some((log) => log.includes('Text cleared')), {
|
|
|
|
|
message: 'editor reports "Text cleared" before typing',
|
|
|
|
|
})
|
|
|
|
|
.toBe(true);
|
2025-12-03 11:27:00 +01:00
|
|
|
|
|
|
|
|
// Click in the editor area to focus it
|
2025-12-30 14:17:51 +01:00
|
|
|
// STC (Scintilla) has complex internal windowing - click anywhere in editor area
|
2025-12-03 11:27:00 +01:00
|
|
|
await canvas.click({ position: { x: 400, y: 300 } });
|
2026-07-07 10:50:24 +02:00
|
|
|
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: Scintilla focus commit before keystrokes (no observable)
|
2025-12-03 11:27:00 +01:00
|
|
|
|
|
|
|
|
// Type some text
|
|
|
|
|
await page.keyboard.type('# Test input\nprint("Hello WASM!")');
|
|
|
|
|
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-09-typed.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
|
|
|
|
// The text should have triggered change events (logged every 10 changes)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Switching between modes preserves content structure', async ({ page, testLogger }) => {
|
|
|
|
|
// Start with Python mode (default)
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-10a-python.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2025-12-30 14:17:51 +01:00
|
|
|
// Switch to DRC mode using element registry
|
|
|
|
|
await clickByLabel(page, 'DRC Rules');
|
2026-07-07 10:50:24 +02:00
|
|
|
await expect
|
|
|
|
|
.poll(
|
|
|
|
|
() => testLogger.consoleLogs.some((log) => log.includes('DRC rules lexer configured')),
|
|
|
|
|
{ message: 'DRC rules lexer configured is logged' }
|
|
|
|
|
)
|
|
|
|
|
.toBe(true);
|
|
|
|
|
await stableShot(page, 'stc-10b-drc.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2025-12-30 14:17:51 +01:00
|
|
|
// Switch back to Python using element registry
|
|
|
|
|
await clickByLabel(page, 'Python');
|
2026-07-07 10:50:24 +02:00
|
|
|
await stableShot(page, 'stc-10c-python-again.png');
|
2025-12-03 11:27:00 +01:00
|
|
|
|
2025-12-30 14:17:51 +01:00
|
|
|
// Multiple mode switches should work (at least DRC mode change should be logged)
|
2026-07-07 10:50:24 +02:00
|
|
|
const modeChanges = testLogger.consoleLogs.filter(
|
|
|
|
|
(log) => log.includes('lexer configured') || log.includes('mode enabled')
|
2025-12-03 11:27:00 +01:00
|
|
|
).length;
|
2025-12-30 14:17:51 +01:00
|
|
|
expect(modeChanges).toBeGreaterThanOrEqual(1);
|
2025-12-03 11:27:00 +01:00
|
|
|
});
|
|
|
|
|
});
|