fix(tests): remove low-value source snapshots and define test standards
This commit is contained in:
80 files changed
+14
-2225
No files matched your search
@@ -1,27 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("DataGrid native clipboard regions", () => {
|
||||
it("keeps table info text selection out of grid copy shortcuts", () => {
|
||||
expect(dataGridSource).toMatch(/<div\b(?=[^>]*\bv-if="showTableInfo")(?=[^>]*\bdata-native-clipboard)[^>]*>/);
|
||||
});
|
||||
|
||||
it("keeps transposed field-name text selection out of grid copy shortcuts", () => {
|
||||
expect(dataGridSource).toMatch(/<div\b(?=[^>]*\bdata-native-clipboard)(?=[^>]*class="sticky left-0)[^>]*>/);
|
||||
});
|
||||
|
||||
it("opens read-only text selection from DOM, canvas, and transposed cells", () => {
|
||||
expect(dataGridSource.match(/startReadonlyCellTextSelection\(/g)).toHaveLength(4);
|
||||
expect(dataGridSource).not.toContain("showReadonlyCellDetailsOnDblClick");
|
||||
expect(dataGridSource).toContain("if (!canEditCellItem(item, actualColIdx)) {");
|
||||
expect(dataGridSource.match(/<DataGridReadonlyTextSelection/g)).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("uses a text cursor for read-only cells across grid render modes", () => {
|
||||
expect(dataGridSource).toContain('hitItem && actualColIdx !== undefined ? "text" : "cell"');
|
||||
expect(dataGridSource).toContain("'cursor-text': !isScrolling && !canEditCellItem(item, col.actualColIdx)");
|
||||
expect(dataGridSource).toContain("'cursor-text': !isScrolling,");
|
||||
});
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("DataGrid column comments", () => {
|
||||
it("uses per-ordinal multi-source comments, falling back to source metadata for single-source grids", () => {
|
||||
expect(dataGridSource).toMatch(
|
||||
/function resolvedColumnComment\(column: string, actualColIdx: number\)[\s\S]*?const ordinalComments = props\.resultColumnComments;[\s\S]*?if \(ordinalComments\) return ordinalComments\[actualColIdx\];[\s\S]*?dataGridColumnCommentFor\([\s\S]*?props\.sourceColumns\?\.\[actualColIdx\][\s\S]*?\);\s*\}/,
|
||||
);
|
||||
expect(dataGridSource).toContain(':column-comment="headerColumnComment(col.name, col.actualColIdx)"');
|
||||
expect(dataGridSource).toContain(':tooltip-column-comment="resolvedColumnComment(col.name, col.actualColIdx)"');
|
||||
expect(dataGridSource).toContain("(column, index) => headerColumnComment(column, index)");
|
||||
});
|
||||
|
||||
it("routes per-ordinal comments to field filtering and go-to-column lookup", () => {
|
||||
expect(dataGridSource).toMatch(/useDataGridColumnLayoutState\(\{[\s\S]*?columnComments: \(\) => props\.resultColumnComments,[\s\S]*?\}\);/);
|
||||
expect(dataGridSource).toMatch(/const goToColumnItems = computed\(\(\) =>[\s\S]*?buildDataGridColumnLookupItems\(\{[\s\S]*?columnComments: props\.resultColumnComments,[\s\S]*?\}\),[\s\S]*?\);/);
|
||||
});
|
||||
});
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
|
||||
const formatterSource = readFileSync(new URL("../../../composables/useDataGridColumnFormatter.ts", import.meta.url), "utf8");
|
||||
|
||||
function functionSource(source: string, name: string): string {
|
||||
const start = source.indexOf(`function ${name}`);
|
||||
expect(start).toBeGreaterThanOrEqual(0);
|
||||
const end = source.indexOf("\n function ", start + 1);
|
||||
return source.slice(start, end < 0 ? undefined : end);
|
||||
}
|
||||
|
||||
describe("DataGrid column formatter keys", () => {
|
||||
it("derives every key list from the shared canonical key builder", () => {
|
||||
const keysSource = functionSource(formatterSource, "formatterKeysForColumn");
|
||||
expect(keysSource).toContain("return columnFormatterKeys({");
|
||||
expect(keysSource).toContain("databaseType: options.resolvedDatabaseType.value");
|
||||
expect(keysSource).toContain("displaySource: props.queryDisplaySourceColumns?.[columnIndex]");
|
||||
// Saves keep writing the single canonical keys[0] spelling.
|
||||
const saveSource = functionSource(formatterSource, "saveColumnFormatter");
|
||||
expect(saveSource).toContain("const key = formatterKeyForColumn(columnIndex);");
|
||||
expect(saveSource).toContain("settingsStore.updateColumnFormatter(key, formatter);");
|
||||
});
|
||||
|
||||
it("clears every candidate key so either surface leaves the column unformatted", () => {
|
||||
const clearSource = functionSource(formatterSource, "clearColumnFormatter");
|
||||
expect(clearSource).toContain("const keys = formatterKeysForColumn(columnIndex);");
|
||||
expect(clearSource).toContain("if (!keys.length) return;");
|
||||
expect(clearSource).toContain("for (const key of keys) settingsStore.updateColumnFormatter(key, undefined);");
|
||||
});
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("DataGrid loading elapsed timer", () => {
|
||||
it("resets for a new load but resumes from the original start after KeepAlive activation", () => {
|
||||
expect(dataGridSource).toContain("function startLoadingElapsedTimer(reset = false)");
|
||||
expect(dataGridSource).toContain("if (reset || !_loadingStart)");
|
||||
expect(dataGridSource).toContain("startLoadingElapsedTimer(true);");
|
||||
expect(dataGridSource).toMatch(/function resumeCanvasGridWork\(\) \{\s*dataGridIsActive = true;\s*startLoadingElapsedTimer\(\);/);
|
||||
expect(dataGridSource).toMatch(/function pauseCanvasGridWork\(\) \{\s*dataGridIsActive = false;\s*stopLoadingElapsedTimer\(\);/);
|
||||
});
|
||||
});
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("DataGrid transpose presentation", () => {
|
||||
it("left-aligns record headers with their transposed values", () => {
|
||||
expect(dataGridSource).toContain('class="shrink-0 border-r border-border px-2 py-1.5 text-left tabular-nums relative"');
|
||||
expect(dataGridSource).not.toContain('class="shrink-0 border-r border-border px-2 py-1.5 text-center tabular-nums relative"');
|
||||
});
|
||||
|
||||
it("shows field metadata only when the transpose setting is enabled", () => {
|
||||
expect(dataGridSource).toContain("settingsStore.editorSettings.dataGridShowTransposeFieldMetadata");
|
||||
expect(dataGridSource).toContain("showTransposeFieldMetadata.value && showColumnTypesInHeader.value");
|
||||
expect(dataGridSource).toContain("showTransposeFieldMetadata.value && showColumnCommentsInHeader.value");
|
||||
expect(dataGridSource).toContain("30 + (transposeReserveTypeLine.value ? 14 : 0) + (transposeReserveCommentLine.value ? 14 : 0)");
|
||||
expect(dataGridSource).toContain(':item-size="transposeRowHeight"');
|
||||
expect(dataGridSource).toContain("data-grid-transpose-type-line");
|
||||
expect(dataGridSource).toContain("data-grid-transpose-comment-line");
|
||||
expect(dataGridSource).toContain("data-grid-transpose-index-indicator");
|
||||
expect(dataGridSource).toContain("showColumnTypesInHeader && item.type");
|
||||
expect(dataGridSource).toContain("showColumnCommentsInHeader && item.comment");
|
||||
expect(dataGridSource).toContain("transposeColumnIndexKind(item.column)");
|
||||
});
|
||||
|
||||
it("shows complete long metadata in a hoverable, bounded tooltip", () => {
|
||||
expect(dataGridSource).toContain("data-grid-transpose-field-tooltip");
|
||||
expect(dataGridSource).toContain(':text="transposeFieldTitle(item)"');
|
||||
expect(dataGridSource).toContain('side="right"');
|
||||
expect(dataGridSource).toContain("max-h-[min(20rem,calc(100vh-1rem))]");
|
||||
expect(dataGridSource).toContain("w-[min(24rem,calc(100vw-1rem))]");
|
||||
expect(dataGridSource).toContain("overflow-auto rounded-md");
|
||||
expect(dataGridSource).toContain("whitespace-pre-wrap break-words select-text");
|
||||
expect(dataGridSource).not.toContain("data-grid-transpose-field-popover");
|
||||
});
|
||||
|
||||
it("stops clipping the cell while the long-text editor or readonly text selection is active", () => {
|
||||
// Transposed rows are compact (30px by default) while the expanded editor
|
||||
// grows well beyond that; the cell must switch to overflow-visible while the
|
||||
// editor / readonly text selection is active, mirroring the normal grid cell.
|
||||
expect(dataGridSource).toContain("'overflow-visible z-20 border-r-transparent': transposeCellEditorActive(cell.recordIndex, cell.valueIndex)");
|
||||
expect(dataGridSource).toContain("'overflow-hidden text-ellipsis whitespace-nowrap': !transposeCellEditorActive(cell.recordIndex, cell.valueIndex)");
|
||||
expect(dataGridSource).toContain("function transposeCellEditorActive");
|
||||
expect(dataGridSource).toContain("readonlyTextCellMatches(rowId, valueIndex)");
|
||||
// The transposed cell no longer unconditionally truncates (overflow: hidden),
|
||||
// which would crop the expanded editor below the compact row bounds.
|
||||
expect(dataGridSource).not.toContain('class="relative flex shrink-0 items-center border-r border-border/70 px-2 py-0 truncate"');
|
||||
});
|
||||
|
||||
it("shares the normal grid cell's editor overlay contract while editing", () => {
|
||||
// Normal grid cells switch to the same overflow/z/border contract while the
|
||||
// cell editor or readonly text selection is active, so long-text editing
|
||||
// looks identical across both views.
|
||||
expect(dataGridSource).toContain("'overflow-visible z-20 border-r-transparent': (editingCell?.rowId === item.id && editingCell?.col === col.actualColIdx) || readonlyTextCellMatches(item.id, col.actualColIdx),");
|
||||
expect(dataGridSource).toContain("'overflow-hidden': !((editingCell?.rowId === item.id && editingCell?.col === col.actualColIdx) || readonlyTextCellMatches(item.id, col.actualColIdx)),");
|
||||
});
|
||||
});
|
||||
@@ -1,36 +0,0 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
|
||||
|
||||
function sourceBetween(start: string, end: string): string {
|
||||
const startIndex = dataGridSource.indexOf(start);
|
||||
const endIndex = dataGridSource.indexOf(end, startIndex + start.length);
|
||||
expect(startIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(endIndex).toBeGreaterThan(startIndex);
|
||||
return dataGridSource.slice(startIndex, endIndex);
|
||||
}
|
||||
|
||||
describe("data grid wheel bindings", () => {
|
||||
it("routes Canvas and DOM wheel calculations through the shared helper", () => {
|
||||
const canvasHandler = sourceBetween("function onCanvasWheel", "function onDomGridWheel");
|
||||
const domHandler = sourceBetween("function onDomGridWheel", "function onCanvasMouseMove");
|
||||
|
||||
for (const handler of [canvasHandler, domHandler]) {
|
||||
expect(handler).toContain("resolveDataGridWheelScroll({");
|
||||
expect(handler).toContain("if (!wheelScroll.moved) return;");
|
||||
expect(handler.indexOf("if (!wheelScroll.moved) return;")).toBeLessThan(handler.indexOf("event.preventDefault();"));
|
||||
expect(handler).toContain("event.stopPropagation();");
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts genuine pixel deltaX in the Canvas handler", () => {
|
||||
const predicate = sourceBetween("function shouldAccelerateCanvasWheel", "function onCanvasWheel");
|
||||
expect(predicate).toContain("if (event.deltaX !== 0) return true;");
|
||||
});
|
||||
|
||||
it("keeps wheel handlers bound in both render modes", () => {
|
||||
expect(dataGridSource).toContain('@wheel="onCanvasWheel"');
|
||||
expect(dataGridSource.match(/@wheel="onDomGridWheel"/g)).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user