fix(grid): refresh database-computed values after edits
This commit is contained in:
1 parent
b3b6d29099
commit
5acdbfa61e
5 files changed
+332
-12
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dataGridSource = readFileSync(new URL("../DataGrid.vue", import.meta.url), "utf8");
|
||||
|
||||
function functionSource(name: string, nextName: string): string {
|
||||
const start = dataGridSource.indexOf(`function ${name}`);
|
||||
const relativeEnd = dataGridSource.slice(start).search(new RegExp(`\\n(?:async\\s+)?function\\s+${nextName}\\b`));
|
||||
expect(start).toBeGreaterThanOrEqual(0);
|
||||
expect(relativeEnd).toBeGreaterThan(0);
|
||||
return dataGridSource.slice(start, start + relativeEnd);
|
||||
}
|
||||
|
||||
describe("DataGrid save reload integration", () => {
|
||||
it("shares the toolbar full-reload preparation with editor saves", () => {
|
||||
const prepareSource = functionSource("prepareFullReload", "onToolbarRefresh");
|
||||
const toolbarSource = functionSource("onToolbarRefresh", "setAutoRefreshInterval");
|
||||
|
||||
expect(dataGridSource).toContain("prepareFullReload,\n emit,");
|
||||
expect(toolbarSource).toContain("prepareFullReload();");
|
||||
expect(prepareSource).toContain("resetInfiniteScrollState();");
|
||||
expect(prepareSource).toContain("captureCurrentSelectionForRefresh();");
|
||||
expect(prepareSource).toContain("preservedSelectionOnNextResult = selection ? { selection, sourceResult: props.result } : null;");
|
||||
expect(prepareSource).toContain("preservedDetailsOnNextResult = captureDetailsForRefresh();");
|
||||
expect(prepareSource).toContain("preserveTransposeOnNextResult.value = showTranspose.value;");
|
||||
expect(dataGridSource).toContain("if (detailsSnapshot) restoreDetailsAfterRefresh(detailsSnapshot);");
|
||||
});
|
||||
|
||||
it("resets accumulated infinite-scroll pagination before reloading from offset zero", () => {
|
||||
const resetSource = functionSource("resetInfiniteScrollState", "prepareFullReload");
|
||||
const nextPageSource = functionSource("infiniteScrollNextPage", "checkInfiniteScroll");
|
||||
|
||||
expect(resetSource).toContain("currentPage.value = 1;");
|
||||
expect(resetSource).toContain("lastInfiniteScrollPage = 0;");
|
||||
expect(resetSource).toContain("infiniteScrollRequestedOffset = undefined;");
|
||||
expect(resetSource).toContain("infiniteScrollRequestedLimit = undefined;");
|
||||
expect(nextPageSource).toContain("const nextOffset = props.result.rows.length;");
|
||||
expect(nextPageSource).toContain('emit("paginate", nextOffset, nextLimit, currentWhereInput(), currentOrderBy());');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user