import { strict as assert } from "node:assert"; import { readFileSync } from "node:fs"; import test from "node:test"; const source = readFileSync("apps/desktop/src/components/editor/QueryEditor.vue", "utf8"); const searchPanelSource = readFileSync("apps/desktop/src/components/editor/EditorSearchPanel.vue", "utf8"); const appSource = readFileSync("apps/desktop/src/App.vue", "utf8"); const cellDetailEditorSource = readFileSync("apps/desktop/src/composables/useCellDetailEditor.ts", "utf8"); const contentAreaSource = readFileSync("apps/desktop/src/components/layout/ContentArea.vue", "utf8"); const dataGridSource = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8"); const editorThemeSource = readFileSync("apps/desktop/src/lib/editorThemes.ts", "utf8"); test("query editor opens search and replace with configurable shortcuts", () => { assert.match(source, /shortcutToCodeMirrorKey\(shortcuts\.find\)/); assert.match(source, /shortcutToCodeMirrorKey\(shortcuts\.replace\)/); assert.match(source, /run:\s*openReplace/); assert.match(source, /defineExpose\(\{\s*openSearch,\s*openReplace\s*\}\)/); assert.match(searchPanelSource, /showReplace\.value\s*=\s*true/); assert.match(searchPanelSource, /replaceInputRef\.value\?\.focus\(\)/); assert.match(searchPanelSource, /defineExpose\(\{\s*openSearch,\s*openReplace,\s*closeSearch\s*\}\)/); }); test("query editor localizes the replace all button", () => { assert.match(searchPanelSource, /t\("editor\.search\.replaceAll"\)/); assert.doesNotMatch(searchPanelSource, />\s*全部\s* { assert.doesNotMatch(editorThemeSource, /"\.cm-searchMatch"/); assert.doesNotMatch(editorThemeSource, /"\.cm-searchMatch-selected"/); }); test("cell detail editor uses custom search panel with configurable shortcuts", () => { assert.match(cellDetailEditorSource, /shortcutToCodeMirrorKey\(shortcuts\.find\)/); assert.match(cellDetailEditorSource, /shortcutToCodeMirrorKey\(shortcuts\.replace\)/); assert.match(cellDetailEditorSource, /openSearch:\s*\(\)\s*=>\s*boolean/); assert.match(cellDetailEditorSource, /openReplace:\s*\(\)\s*=>\s*boolean/); assert.match(cellDetailEditorSource, /createApp\(EditorSearchPanel/); assert.match(cellDetailEditorSource, /searchApp\.use\(i18n\)/); assert.match(dataGridSource, /openCellDetailSearch/); }); test("data grid uses Mod-R for refresh instead of editor replace", () => { assert.match(dataGridSource, /data-grid-root/); assert.match(dataGridSource, /data-cell-detail-editor-root/); assert.match(dataGridSource, /if \(event\.defaultPrevented\) return/); assert.match(dataGridSource, /isModRShortcut\(event\)/); assert.match(dataGridSource, /await onToolbarRefresh\(\)/); }); test("app keydown routes Mod-R directly before browser reload handling", () => { assert.match(appSource, /if \(e\.defaultPrevented\) return/); assert.match(appSource, /isModRShortcut\(e\)/); assert.match(appSource, /contentAreaRef\.value\?\.handleModRTarget\(e\.target\)/); assert.match(contentAreaSource, /function handleModRTarget\(target: Element\): boolean/); assert.match(contentAreaSource, /queryEditorRef\.value\?\.openReplace\(\)/); assert.match(contentAreaSource, /dataGridRef\.value\?\.openCellDetailSearch\(\)/); assert.match(contentAreaSource, /if \(target\.closest\("\[data-grid-root\]"\)\) return refreshData\(\)/); });