import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { test } from "vitest"; import { compileScript, compileTemplate, parse } from "vue/compiler-sfc"; const contentAreaPath = "apps/desktop/src/components/layout/ContentArea.vue"; const dataGridPath = "apps/desktop/src/components/grid/DataGrid.vue"; const viewSwitcherPath = "apps/desktop/src/components/layout/QueryResultViewSwitcher.vue"; const toolbarActionsPath = "apps/desktop/src/components/layout/QueryResultToolbarActions.vue"; function source(path: string): string { return readFileSync(path, "utf8"); } function assertSfcCompiles(path: string): void { const { descriptor, errors } = parse(source(path), { filename: path }); assert.deepEqual(errors, [], `${path} should parse without SFC errors`); assert.ok(descriptor.scriptSetup, `${path} should have a script setup block`); compileScript(descriptor, { id: path }); if (descriptor.template) { const result = compileTemplate({ id: path, filename: path, source: descriptor.template.content }); assert.deepEqual(result.errors, [], `${path} template should compile`); } } test("query result toolbar SFCs compile", () => { for (const path of [contentAreaPath, dataGridPath, viewSwitcherPath, toolbarActionsPath]) assertSfcCompiles(path); }); test("query result toolbar reuses the production icon contract", () => { const contentArea = source(contentAreaPath); const viewSwitcher = source(viewSwitcherPath); const toolbarActions = source(toolbarActionsPath); assert.match(contentArea, / { const contentArea = source(contentAreaPath); assert.match(contentArea, /showResultRunSelector = computed\(\(\) => resultAutoSave\.value && resultRuns\.value\.length > 0\)/); assert.match(contentArea, /