Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): assert the selection the editor holds in the spellcheck smoke (#4472)
Nick Gomezc94728edda42
diff --git a/packages/desktop/tests/smoke/_helpers/settings-surface.ts b/packages/desktop/tests/smoke/_helpers/settings-surface.tsindex 7d2137c32..d8dfaff13 100644--- a/packages/desktop/tests/smoke/_helpers/settings-surface.ts+++ b/packages/desktop/tests/smoke/_helpers/settings-surface.ts@@ -357,6 +357,29 @@ export async function readMenuSnapshotSpellcheck(editor: Page): Promise<boolean});}+export interface EditorSelectionSnapshot {+ readonly held: boolean;+ readonly text: string;+}++export async function readEditorSelectionSnapshot(editor: Page): Promise<EditorSelectionSnapshot> {+ return editorBody(editor).evaluate(async (element) => {+ const menu = window.okDesktop?.menu;+ if (!menu) throw new Error('the editor window exposes no okDesktop.menu bridge');+ const snapshot = await menu.dispatch({ kind: 'query' });+ if (!snapshot) {+ throw new Error('menu.dispatch({ kind: "query" }) returned no renderer snapshot');+ }+ const selection = window.getSelection();+ const range = selection !== null && selection.rangeCount > 0 ? selection.getRangeAt(0) : null;+ const insideEditor = range !== null && element.contains(range.commonAncestorContainer);+ return {+ held: snapshot.viewMenuState.hasEditorSelection ?? false,+ text: insideEditor ? (selection?.toString() ?? '') : '',+ } satisfies EditorSelectionSnapshot;+ });+}+export async function applicationMenuSpellcheck(app: ElectronApplication,action: 'read' | 'click',diff --git a/packages/desktop/tests/smoke/spellcheck-presentation.e2e.ts b/packages/desktop/tests/smoke/spellcheck-presentation.e2e.tsindex 940aacde7..d2018d21a 100644--- a/packages/desktop/tests/smoke/spellcheck-presentation.e2e.ts+++ b/packages/desktop/tests/smoke/spellcheck-presentation.e2e.ts@@ -4,6 +4,7 @@ import { PLATFORM_SKIP_REASON, PLATFORM_SUPPORTED, SMOKE_ENABLED } from './_helpimport {addLanguageInSelector,closeSettingsDialog,+ type EditorSelectionSnapshot,editorBody,findEditorWindow,launchOnSeededProfile,@@ -11,6 +12,7 @@ import {openSettingsDialog,openSpellingSettings,pickNonDefaultSelection,+ readEditorSelectionSnapshot,readSessionSpellingTruth,seedProjectProfile,setSpellcheckToggle,@@ -30,6 +32,8 @@ const STAMP = 'pre-settings';const CONTENT_HOLD_MS = 1_000;+const PRESS_INTERVAL_MS = 33;+type StampCarrier = Record<string, unknown>;const STAMP_KEY = '__okSpellingProbeStamp';@@ -59,8 +63,24 @@ async function readStamps(editor: Page): Promise<SurfaceStamps> {}, STAMP_KEY);}-async function readEditorSelectionText(editor: Page): Promise<string> {- return editor.evaluate(() => window.getSelection()?.toString() ?? '');+async function waitForEditorSelection(+ editor: Page,+ expected: string,+ timeoutMs = 15_000,+): Promise<void> {+ await expect+ .poll(() => readEditorSelectionSnapshot(editor), { timeout: timeoutMs })+ .toEqual({ held: true, text: expected } satisfies EditorSelectionSnapshot);+}++async function selectMarkerBackwards(editor: Page, timeoutMs = 30_000): Promise<void> {+ await expect(async () => {+ await editor.keyboard.press('End');+ for (let i = 0; i < MARKER.length; i++) {+ await editor.keyboard.press('Shift+ArrowLeft', { delay: PRESS_INTERVAL_MS });+ }+ await waitForEditorSelection(editor, MARKER, 3_000);+ }).toPass({ timeout: timeoutMs });}async function refocusEditable(editor: Page): Promise<void> {@@ -141,8 +161,7 @@ test.describe('Spelling settings — platform presentation and editor non-interfconst contentBefore = await readEditorContent(editor);- for (let i = 0; i < MARKER.length; i++) await editor.keyboard.press('Shift+ArrowLeft');- expect(await readEditorSelectionText(editor)).toBe(MARKER);+ await selectMarkerBackwards(editor);await stampSurfaces(editor);@@ -168,7 +187,7 @@ test.describe('Spelling settings — platform presentation and editor non-interfawait expectEditorContentHolds(editor, contentBefore, CONTENT_HOLD_MS);await refocusEditable(editor);- expect(await readEditorSelectionText(editor)).toBe(MARKER);+ await waitForEditorSelection(editor, MARKER);await editor.keyboard.press('ControlOrMeta+z');await expect(body).not.toContainText(MARKER, { timeout: 20_000 });