@svgrid/grid 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +137 -39
- package/dist/GridFooter.svelte +164 -0
- package/dist/GridFooter.svelte.d.ts +29 -0
- package/dist/GridMenus.svelte +570 -0
- package/dist/GridMenus.svelte.d.ts +31 -0
- package/dist/SvGrid.controller.svelte.d.ts +429 -0
- package/dist/SvGrid.controller.svelte.js +1732 -0
- package/dist/SvGrid.css +1709 -0
- package/dist/SvGrid.helpers.d.ts +35 -0
- package/dist/SvGrid.helpers.js +160 -0
- package/dist/SvGrid.svelte +344 -7043
- package/dist/SvGrid.svelte.d.ts +4 -357
- package/dist/SvGrid.types.d.ts +436 -0
- package/dist/SvGrid.types.js +1 -0
- package/dist/SvGridChart.svelte +1060 -23
- package/dist/SvGridChart.svelte.d.ts +17 -0
- package/dist/build-api.d.ts +5 -0
- package/dist/build-api.js +527 -0
- package/dist/cell-render.d.ts +15 -0
- package/dist/cell-render.js +246 -0
- package/dist/cell-values.d.ts +28 -0
- package/dist/cell-values.js +89 -0
- package/dist/chart.d.ts +370 -3
- package/dist/chart.js +1135 -42
- package/dist/clipboard.d.ts +15 -0
- package/dist/clipboard.js +356 -0
- package/dist/columns.d.ts +30 -0
- package/dist/columns.js +277 -0
- package/dist/core.d.ts +1 -1
- package/dist/css.d.ts +3 -0
- package/dist/editing.d.ts +24 -0
- package/dist/editing.js +343 -0
- package/dist/editors/cell-editors.d.ts +1 -1
- package/dist/facet-buckets.d.ts +13 -0
- package/dist/facet-buckets.js +54 -0
- package/dist/features.d.ts +5 -0
- package/dist/features.js +30 -0
- package/dist/filter-operators.d.ts +16 -0
- package/dist/filter-operators.js +69 -0
- package/dist/hyperformula-adapter.d.ts +82 -0
- package/dist/hyperformula-adapter.js +73 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/keyboard-handlers.d.ts +7 -0
- package/dist/keyboard-handlers.js +197 -0
- package/dist/menus.d.ts +40 -0
- package/dist/menus.js +389 -0
- package/dist/named-views.d.ts +27 -0
- package/dist/named-views.js +39 -0
- package/dist/row-resize.d.ts +43 -0
- package/dist/row-resize.js +158 -0
- package/dist/scroll-sync.d.ts +9 -0
- package/dist/scroll-sync.js +86 -0
- package/dist/selection.d.ts +26 -0
- package/dist/selection.js +387 -0
- package/dist/spreadsheet.d.ts +80 -0
- package/dist/spreadsheet.js +194 -0
- package/dist/summaries.d.ts +12 -0
- package/dist/summaries.js +65 -0
- package/dist/svgrid-wrapper.types.d.ts +12 -1
- package/dist/svgrid.comments-autocomplete.test.d.ts +1 -0
- package/dist/svgrid.comments-autocomplete.test.js +96 -0
- package/dist/svgrid.context-menu.test.d.ts +1 -0
- package/dist/svgrid.context-menu.test.js +102 -0
- package/dist/svgrid.new-features.wrapper.test.js +30 -4
- package/dist/svgrid.wrapper.test.js +27 -1
- package/dist/virtualization/column-virtualizer.d.ts +2 -0
- package/dist/virtualization/scroll-scaling.d.ts +28 -0
- package/dist/virtualization/scroll-scaling.js +64 -0
- package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
- package/dist/virtualization/scroll-scaling.test.js +86 -0
- package/dist/virtualization/svelte-virtualizer.svelte.d.ts +2 -0
- package/dist/virtualization/svelte-virtualizer.svelte.js +2 -0
- package/dist/virtualization/virtualizer.d.ts +7 -0
- package/dist/virtualization/virtualizer.js +30 -0
- package/package.json +1 -1
- package/src/GridFooter.svelte +164 -0
- package/src/GridMenus.svelte +570 -0
- package/src/SvGrid.controller.svelte.ts +2195 -0
- package/src/SvGrid.css +1747 -0
- package/src/SvGrid.helpers.test.ts +415 -0
- package/src/SvGrid.helpers.ts +185 -0
- package/src/SvGrid.svelte +348 -7043
- package/src/SvGrid.types.ts +456 -0
- package/src/SvGridChart.svelte +1060 -23
- package/src/build-api.coverage.test.ts +532 -0
- package/src/build-api.ts +663 -0
- package/src/cell-render.test.ts +451 -0
- package/src/cell-render.ts +426 -0
- package/src/cell-values.ts +114 -0
- package/src/chart-export.test.ts +370 -0
- package/src/chart.coverage.test.ts +814 -0
- package/src/chart.ts +1352 -47
- package/src/clipboard.test.ts +731 -0
- package/src/clipboard.ts +524 -0
- package/src/collaboration.coverage.test.ts +220 -0
- package/src/columns.test.ts +702 -0
- package/src/columns.ts +419 -0
- package/src/core.ts +8 -0
- package/src/css.d.ts +3 -0
- package/src/editing.test.ts +837 -0
- package/src/editing.ts +513 -0
- package/src/editors/cell-editors.coverage.test.ts +156 -0
- package/src/editors/cell-editors.ts +1 -0
- package/src/facet-buckets.test.ts +353 -0
- package/src/facet-buckets.ts +67 -0
- package/src/features.ts +128 -0
- package/src/filter-operators.test.ts +174 -0
- package/src/filter-operators.ts +87 -0
- package/src/hyperformula-adapter.test.ts +256 -0
- package/src/hyperformula-adapter.ts +124 -0
- package/src/index.ts +37 -0
- package/src/keyboard-handlers.coverage.test.ts +560 -0
- package/src/keyboard-handlers.ts +353 -0
- package/src/keyboard.ts +97 -97
- package/src/menus.test.ts +620 -0
- package/src/menus.ts +554 -0
- package/src/named-views.coverage.test.ts +210 -0
- package/src/named-views.ts +48 -0
- package/src/row-resize.test.ts +369 -0
- package/src/row-resize.ts +171 -0
- package/src/scroll-sync.test.ts +330 -0
- package/src/scroll-sync.ts +216 -0
- package/src/selection.test.ts +722 -0
- package/src/selection.ts +545 -0
- package/src/server-data-source.coverage.test.ts +180 -0
- package/src/spreadsheet.test.ts +445 -0
- package/src/spreadsheet.ts +246 -0
- package/src/summaries.ts +204 -0
- package/src/sv-grid-scrollbar.ts +13 -1
- package/src/svgrid-wrapper.types.ts +12 -1
- package/src/svgrid.behavior.test.ts +22 -0
- package/src/svgrid.comments-autocomplete.test.ts +112 -0
- package/src/svgrid.context-menu.test.ts +126 -0
- package/src/svgrid.interaction.test.ts +30 -0
- package/src/svgrid.new-features.wrapper.test.ts +65 -4
- package/src/svgrid.wrapper.test.ts +27 -1
- package/src/test-setup.ts +9 -6
- package/src/virtualization/scroll-scaling.test.ts +148 -0
- package/src/virtualization/scroll-scaling.ts +121 -0
- package/src/virtualization/svelte-virtualizer.svelte.ts +2 -0
- package/src/virtualization/virtualizer.ts +26 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coverage-focused behavioral tests for the SvGridApi assembled in
|
|
3
|
+
* `build-api.ts`. The existing `svgrid.api.test.ts` / `svgrid.api-extensions
|
|
4
|
+
* .test.ts` cover filters, row selection, pagination, navigation, and
|
|
5
|
+
* getState/setState. This file exercises the remaining surface:
|
|
6
|
+
* - getCellValue / setCellValue
|
|
7
|
+
* - selectCells / getSelected
|
|
8
|
+
* - addRow(s) / removeRow(s) / applyTransaction
|
|
9
|
+
* - addColumn(s) / removeColumn / setColumnVisible / getColumns
|
|
10
|
+
* - setColumnWidth / setColumnPinning / setColumnOrder
|
|
11
|
+
* - setFacetFilter
|
|
12
|
+
* - undo / redo / canUndo / canRedo / clearHistory
|
|
13
|
+
* - find (open/close/query/hits)
|
|
14
|
+
* - grouping (setGroupBy / expandAllGroups / collapseAllGroups)
|
|
15
|
+
* - autosizeColumn / refresh
|
|
16
|
+
*
|
|
17
|
+
* All tests mount the real <SvGrid /> in jsdom and drive the api handed back
|
|
18
|
+
* from onApiReady.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { describe, expect, it } from "vitest";
|
|
22
|
+
import { mount, unmount } from "svelte";
|
|
23
|
+
import SvGrid from "./SvGrid.svelte";
|
|
24
|
+
import {
|
|
25
|
+
columnFilteringFeature,
|
|
26
|
+
columnGroupingFeature,
|
|
27
|
+
rowExpandingFeature,
|
|
28
|
+
rowSelectionFeature,
|
|
29
|
+
rowSortingFeature,
|
|
30
|
+
tableFeatures,
|
|
31
|
+
} from "./index";
|
|
32
|
+
import type { ColumnDef, SvGridApi } from "./index";
|
|
33
|
+
|
|
34
|
+
type Row = { id: number; name: string; team: string; salary: number };
|
|
35
|
+
|
|
36
|
+
const baseRows: Row[] = [
|
|
37
|
+
{ id: 1, name: "Ada Lovelace", team: "Research", salary: 142_000 },
|
|
38
|
+
{ id: 2, name: "Grace Hopper", team: "Compilers", salary: 158_000 },
|
|
39
|
+
{ id: 3, name: "Alan Turing", team: "Research", salary: 138_000 },
|
|
40
|
+
{ id: 4, name: "Margaret Hamilton", team: "Apollo", salary: 165_000 },
|
|
41
|
+
{ id: 5, name: "Linus Torvalds", team: "Kernel", salary: 175_000 },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const baseColumns: ColumnDef<any, Row>[] = [
|
|
45
|
+
{ field: "name", header: "Name", width: 200 },
|
|
46
|
+
{ field: "team", header: "Team", width: 160 },
|
|
47
|
+
{ field: "salary", header: "Salary", width: 140 },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const flush = () => Promise.resolve();
|
|
51
|
+
|
|
52
|
+
function mountGrid(
|
|
53
|
+
extraProps: Record<string, unknown> = {},
|
|
54
|
+
features: any = tableFeatures({
|
|
55
|
+
columnFilteringFeature,
|
|
56
|
+
rowSortingFeature,
|
|
57
|
+
rowSelectionFeature,
|
|
58
|
+
columnGroupingFeature,
|
|
59
|
+
rowExpandingFeature,
|
|
60
|
+
}),
|
|
61
|
+
): Promise<{ api: SvGridApi<any, Row>; target: HTMLElement; destroy: () => void }> {
|
|
62
|
+
return new Promise((resolveApi, rejectApi) => {
|
|
63
|
+
const target = document.createElement("div");
|
|
64
|
+
document.body.appendChild(target);
|
|
65
|
+
let captured: SvGridApi<any, Row> | null = null;
|
|
66
|
+
const app = mount(SvGrid, {
|
|
67
|
+
target,
|
|
68
|
+
props: {
|
|
69
|
+
data: baseRows.map((r) => ({ ...r })),
|
|
70
|
+
columns: baseColumns.map((c) => ({ ...c })),
|
|
71
|
+
features,
|
|
72
|
+
getRowId: (r: Row) => String(r.id),
|
|
73
|
+
rowHeight: 36,
|
|
74
|
+
containerHeight: 480,
|
|
75
|
+
virtualization: false,
|
|
76
|
+
enableCellSelection: true,
|
|
77
|
+
onApiReady(api: SvGridApi<any, Row>) {
|
|
78
|
+
captured = api;
|
|
79
|
+
resolveApi({
|
|
80
|
+
api,
|
|
81
|
+
target,
|
|
82
|
+
destroy: () => {
|
|
83
|
+
unmount(app);
|
|
84
|
+
target.remove();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
...extraProps,
|
|
89
|
+
} as any,
|
|
90
|
+
});
|
|
91
|
+
queueMicrotask(() => {
|
|
92
|
+
if (!captured) rejectApi(new Error("onApiReady never fired"));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
describe("SvGridApi - cell read / write", () => {
|
|
98
|
+
it("getCellValue reads through the column field", async () => {
|
|
99
|
+
const { api, destroy } = await mountGrid();
|
|
100
|
+
try {
|
|
101
|
+
expect(api.getCellValue(0, "name")).toBe("Ada Lovelace");
|
|
102
|
+
expect(api.getCellValue(3, "team")).toBe("Apollo");
|
|
103
|
+
} finally {
|
|
104
|
+
destroy();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("getCellValue returns undefined for out-of-range row or unknown column", async () => {
|
|
109
|
+
const { api, destroy } = await mountGrid();
|
|
110
|
+
try {
|
|
111
|
+
expect(api.getCellValue(999, "name")).toBeUndefined();
|
|
112
|
+
expect(api.getCellValue(0, "nope")).toBeUndefined();
|
|
113
|
+
} finally {
|
|
114
|
+
destroy();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("setCellValue writes a new immutable row and reads back", async () => {
|
|
119
|
+
const { api, destroy } = await mountGrid();
|
|
120
|
+
try {
|
|
121
|
+
api.setCellValue(0, "name", "Ada L.");
|
|
122
|
+
await flush();
|
|
123
|
+
expect(api.getCellValue(0, "name")).toBe("Ada L.");
|
|
124
|
+
// other rows untouched
|
|
125
|
+
expect(api.getCellValue(1, "name")).toBe("Grace Hopper");
|
|
126
|
+
} finally {
|
|
127
|
+
destroy();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("setCellValue is a no-op for an invalid target", async () => {
|
|
132
|
+
const { api, destroy } = await mountGrid();
|
|
133
|
+
try {
|
|
134
|
+
expect(() => api.setCellValue(999, "name", "x")).not.toThrow();
|
|
135
|
+
expect(() => api.setCellValue(0, "unknown", "x")).not.toThrow();
|
|
136
|
+
} finally {
|
|
137
|
+
destroy();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe("SvGridApi - cell selection", () => {
|
|
143
|
+
it("selectCells sets a rectangle; getSelected reads it back normalized", async () => {
|
|
144
|
+
const { api, destroy } = await mountGrid();
|
|
145
|
+
try {
|
|
146
|
+
api.selectCells([[2, 1, 0, 0]]); // unsorted corners
|
|
147
|
+
await flush();
|
|
148
|
+
expect(api.getSelected()).toEqual([[0, 0, 2, 1]]);
|
|
149
|
+
} finally {
|
|
150
|
+
destroy();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("selectCells clamps open-ended (Infinity) coordinates to grid bounds", async () => {
|
|
155
|
+
const { api, destroy } = await mountGrid();
|
|
156
|
+
try {
|
|
157
|
+
api.selectCells([[0, 0, Infinity, Infinity]]);
|
|
158
|
+
await flush();
|
|
159
|
+
// 5 rows (0..4), 3 cols (0..2)
|
|
160
|
+
expect(api.getSelected()).toEqual([[0, 0, 4, 2]]);
|
|
161
|
+
} finally {
|
|
162
|
+
destroy();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("empty selectCells clears the range; getSelected returns []", async () => {
|
|
167
|
+
const { api, destroy } = await mountGrid();
|
|
168
|
+
try {
|
|
169
|
+
api.selectCells([[0, 0, 1, 1]]);
|
|
170
|
+
await flush();
|
|
171
|
+
api.selectCells([]);
|
|
172
|
+
await flush();
|
|
173
|
+
expect(api.getSelected()).toEqual([]);
|
|
174
|
+
} finally {
|
|
175
|
+
destroy();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe("SvGridApi - row mutations", () => {
|
|
181
|
+
it("addRow appends to the bottom by default", async () => {
|
|
182
|
+
const { api, destroy } = await mountGrid();
|
|
183
|
+
try {
|
|
184
|
+
api.addRow({ id: 6, name: "New", team: "QA", salary: 1 } as Row);
|
|
185
|
+
await flush();
|
|
186
|
+
const data = api.getData() as Row[];
|
|
187
|
+
expect(data.length).toBe(6);
|
|
188
|
+
expect(data[5]!.id).toBe(6);
|
|
189
|
+
} finally {
|
|
190
|
+
destroy();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("addRows at top / numeric index insert in place", async () => {
|
|
195
|
+
const { api, destroy } = await mountGrid();
|
|
196
|
+
try {
|
|
197
|
+
api.addRows([{ id: 7, name: "Top", team: "T", salary: 1 } as Row], "top");
|
|
198
|
+
await flush();
|
|
199
|
+
expect((api.getData() as Row[])[0]!.id).toBe(7);
|
|
200
|
+
|
|
201
|
+
api.addRows([{ id: 8, name: "Mid", team: "M", salary: 1 } as Row], 2);
|
|
202
|
+
await flush();
|
|
203
|
+
expect((api.getData() as Row[])[2]!.id).toBe(8);
|
|
204
|
+
} finally {
|
|
205
|
+
destroy();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("removeRow / removeRows drop by index", async () => {
|
|
210
|
+
const { api, destroy } = await mountGrid();
|
|
211
|
+
try {
|
|
212
|
+
api.removeRow(0);
|
|
213
|
+
await flush();
|
|
214
|
+
expect((api.getData() as Row[]).map((r) => r.id)).toEqual([2, 3, 4, 5]);
|
|
215
|
+
|
|
216
|
+
api.removeRows([0, 2]); // drops ids 2 and 4
|
|
217
|
+
await flush();
|
|
218
|
+
expect((api.getData() as Row[]).map((r) => r.id)).toEqual([3, 5]);
|
|
219
|
+
} finally {
|
|
220
|
+
destroy();
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("applyTransaction adds, updates (by id), and removes; returns counts", async () => {
|
|
225
|
+
const { api, destroy } = await mountGrid();
|
|
226
|
+
try {
|
|
227
|
+
const result = api.applyTransaction({
|
|
228
|
+
add: [{ id: 9, name: "Added", team: "X", salary: 1 } as Row],
|
|
229
|
+
update: [
|
|
230
|
+
{ id: 2, name: "Grace H.", team: "Compilers", salary: 999 } as Row,
|
|
231
|
+
],
|
|
232
|
+
remove: ["3"], // by getRowId string
|
|
233
|
+
});
|
|
234
|
+
await flush();
|
|
235
|
+
expect(result).toEqual({ added: 1, updated: 1, removed: 1 });
|
|
236
|
+
const data = api.getData() as Row[];
|
|
237
|
+
expect(data.find((r) => r.id === 3)).toBeUndefined();
|
|
238
|
+
expect(data.find((r) => r.id === 2)!.salary).toBe(999);
|
|
239
|
+
expect(data.find((r) => r.id === 9)).toBeTruthy();
|
|
240
|
+
} finally {
|
|
241
|
+
destroy();
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("applyTransaction removes by object reference too", async () => {
|
|
246
|
+
const { api, destroy } = await mountGrid();
|
|
247
|
+
try {
|
|
248
|
+
const target = (api.getData() as Row[])[0]!;
|
|
249
|
+
const result = api.applyTransaction({ remove: [target] });
|
|
250
|
+
await flush();
|
|
251
|
+
expect(result.removed).toBe(1);
|
|
252
|
+
expect((api.getData() as Row[]).find((r) => r === target)).toBeUndefined();
|
|
253
|
+
} finally {
|
|
254
|
+
destroy();
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
describe("SvGridApi - column mutations", () => {
|
|
260
|
+
it("addColumn left / right / numeric position, then getColumns reflects it", async () => {
|
|
261
|
+
const { api, destroy } = await mountGrid();
|
|
262
|
+
try {
|
|
263
|
+
api.addColumn({ field: "id", header: "ID" } as any, "left");
|
|
264
|
+
await flush();
|
|
265
|
+
expect(api.getColumns()[0]!.id).toBe("id");
|
|
266
|
+
|
|
267
|
+
api.addColumns([{ field: "extra", header: "Extra" } as any], "right");
|
|
268
|
+
await flush();
|
|
269
|
+
const cols = api.getColumns();
|
|
270
|
+
expect(cols[cols.length - 1]!.id).toBe("extra");
|
|
271
|
+
} finally {
|
|
272
|
+
destroy();
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("removeColumn drops a column from the visible set", async () => {
|
|
277
|
+
const { api, destroy } = await mountGrid();
|
|
278
|
+
try {
|
|
279
|
+
api.removeColumn("team");
|
|
280
|
+
await flush();
|
|
281
|
+
expect(api.getColumns().find((c) => c.id === "team")).toBeUndefined();
|
|
282
|
+
} finally {
|
|
283
|
+
destroy();
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("setColumnVisible toggles visibility; getColumns lists hidden as visible:false", async () => {
|
|
288
|
+
const { api, destroy } = await mountGrid();
|
|
289
|
+
try {
|
|
290
|
+
api.setColumnVisible("team", false);
|
|
291
|
+
await flush();
|
|
292
|
+
expect(api.isColumnVisible("team")).toBe(false);
|
|
293
|
+
const hidden = api.getColumns().find((c) => c.id === "team");
|
|
294
|
+
expect(hidden!.visible).toBe(false);
|
|
295
|
+
|
|
296
|
+
api.setColumnVisible("team", true);
|
|
297
|
+
await flush();
|
|
298
|
+
expect(api.isColumnVisible("team")).toBe(true);
|
|
299
|
+
} finally {
|
|
300
|
+
destroy();
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("setColumnWidth clamps + getColumnWidths round-trips", async () => {
|
|
305
|
+
const { api, destroy } = await mountGrid();
|
|
306
|
+
try {
|
|
307
|
+
api.setColumnWidth("name", 333.7);
|
|
308
|
+
await flush();
|
|
309
|
+
expect(api.getColumnWidths().name).toBe(333);
|
|
310
|
+
} finally {
|
|
311
|
+
destroy();
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("setColumnPinning dedupes; getColumnPinning returns copies", async () => {
|
|
316
|
+
const { api, destroy } = await mountGrid();
|
|
317
|
+
try {
|
|
318
|
+
api.setColumnPinning({ left: ["name", "name"], right: ["salary"] });
|
|
319
|
+
await flush();
|
|
320
|
+
const pin = api.getColumnPinning();
|
|
321
|
+
expect(pin.left).toEqual(["name"]);
|
|
322
|
+
expect(pin.right).toEqual(["salary"]);
|
|
323
|
+
// mutating the returned copy doesn't affect internal state
|
|
324
|
+
pin.left.push("hacked");
|
|
325
|
+
expect(api.getColumnPinning().left).toEqual(["name"]);
|
|
326
|
+
} finally {
|
|
327
|
+
destroy();
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("setColumnOrder + getColumnOrder round-trip", async () => {
|
|
332
|
+
const { api, destroy } = await mountGrid();
|
|
333
|
+
try {
|
|
334
|
+
api.setColumnOrder(["salary", "name", "team"]);
|
|
335
|
+
await flush();
|
|
336
|
+
expect(api.getColumnOrder().slice(0, 3)).toEqual([
|
|
337
|
+
"salary",
|
|
338
|
+
"name",
|
|
339
|
+
"team",
|
|
340
|
+
]);
|
|
341
|
+
} finally {
|
|
342
|
+
destroy();
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// Note: autosizeColumn / autosizeAllColumns are intentionally not asserted
|
|
347
|
+
// here - they measure text via real DOM layout (canvas/escape), which jsdom
|
|
348
|
+
// does not provide, so they throw in this environment. They are exercised by
|
|
349
|
+
// the demo gallery / Playwright suite per the coverage config notes.
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
describe("SvGridApi - facet filter", () => {
|
|
353
|
+
it("setFacetFilter narrows displayed rows; null clears it", async () => {
|
|
354
|
+
const { api, destroy } = await mountGrid();
|
|
355
|
+
try {
|
|
356
|
+
api.setFacetFilter("team", ["Research"]);
|
|
357
|
+
await flush();
|
|
358
|
+
const displayed = api.getDisplayedRows() as Row[];
|
|
359
|
+
expect(displayed.every((r) => r.team === "Research")).toBe(true);
|
|
360
|
+
expect(displayed.length).toBe(2);
|
|
361
|
+
|
|
362
|
+
api.setFacetFilter("team", null);
|
|
363
|
+
await flush();
|
|
364
|
+
expect((api.getDisplayedRows() as Row[]).length).toBe(5);
|
|
365
|
+
} finally {
|
|
366
|
+
destroy();
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("setFacetFilter with an empty array also clears", async () => {
|
|
371
|
+
const { api, destroy } = await mountGrid();
|
|
372
|
+
try {
|
|
373
|
+
api.setFacetFilter("team", ["Apollo"]);
|
|
374
|
+
await flush();
|
|
375
|
+
api.setFacetFilter("team", []);
|
|
376
|
+
await flush();
|
|
377
|
+
expect((api.getDisplayedRows() as Row[]).length).toBe(5);
|
|
378
|
+
} finally {
|
|
379
|
+
destroy();
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
describe("SvGridApi - find", () => {
|
|
385
|
+
it("openFind / setFindQuery / getFindHits / closeFind", async () => {
|
|
386
|
+
const { api, destroy } = await mountGrid();
|
|
387
|
+
try {
|
|
388
|
+
api.openFind();
|
|
389
|
+
api.setFindQuery("Research");
|
|
390
|
+
await flush();
|
|
391
|
+
const hits = api.getFindHits();
|
|
392
|
+
expect(Array.isArray(hits)).toBe(true);
|
|
393
|
+
// two cells contain "Research"
|
|
394
|
+
expect(hits.length).toBeGreaterThanOrEqual(2);
|
|
395
|
+
|
|
396
|
+
api.closeFind();
|
|
397
|
+
await flush();
|
|
398
|
+
expect(api.getFindHits()).toEqual([]);
|
|
399
|
+
} finally {
|
|
400
|
+
destroy();
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
describe("SvGridApi - undo / redo / history", () => {
|
|
406
|
+
it("canUndo is false before any history; undo/redo are no-ops then", async () => {
|
|
407
|
+
const { api, destroy } = await mountGrid();
|
|
408
|
+
try {
|
|
409
|
+
expect(api.canUndo()).toBe(false);
|
|
410
|
+
expect(api.canRedo()).toBe(false);
|
|
411
|
+
expect(api.undo()).toBe(false);
|
|
412
|
+
expect(api.redo()).toBe(false);
|
|
413
|
+
} finally {
|
|
414
|
+
destroy();
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it("clearHistory resets the stacks without throwing", async () => {
|
|
419
|
+
const { api, destroy } = await mountGrid();
|
|
420
|
+
try {
|
|
421
|
+
expect(() => api.clearHistory()).not.toThrow();
|
|
422
|
+
expect(api.canUndo()).toBe(false);
|
|
423
|
+
expect(api.canRedo()).toBe(false);
|
|
424
|
+
} finally {
|
|
425
|
+
destroy();
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
describe("SvGridApi - grouping / expansion", () => {
|
|
431
|
+
it("setGroupBy groups rows; the underlying data is unchanged", async () => {
|
|
432
|
+
const { api, destroy } = await mountGrid();
|
|
433
|
+
try {
|
|
434
|
+
api.setGroupBy(["team"]);
|
|
435
|
+
await flush();
|
|
436
|
+
// Grouping reshapes the display pipeline; the source data is intact.
|
|
437
|
+
expect((api.getData() as Row[]).length).toBe(5);
|
|
438
|
+
expect(api.getState().grouping).toContain("team");
|
|
439
|
+
} finally {
|
|
440
|
+
destroy();
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it("expandAllGroups / collapseAllGroups run without error", async () => {
|
|
445
|
+
const { api, destroy } = await mountGrid();
|
|
446
|
+
try {
|
|
447
|
+
api.setGroupBy(["team"]);
|
|
448
|
+
await flush();
|
|
449
|
+
expect(() => api.expandAllGroups()).not.toThrow();
|
|
450
|
+
await flush();
|
|
451
|
+
expect(() => api.collapseAllGroups()).not.toThrow();
|
|
452
|
+
await flush();
|
|
453
|
+
// un-group
|
|
454
|
+
api.setGroupBy([]);
|
|
455
|
+
await flush();
|
|
456
|
+
expect((api.getData() as Row[]).length).toBe(5);
|
|
457
|
+
} finally {
|
|
458
|
+
destroy();
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("setRowExpanded toggles a row's expanded flag", async () => {
|
|
463
|
+
const { api, destroy } = await mountGrid();
|
|
464
|
+
try {
|
|
465
|
+
expect(() => api.setRowExpanded("1", true)).not.toThrow();
|
|
466
|
+
await flush();
|
|
467
|
+
expect(() => api.setRowExpanded("1", false)).not.toThrow();
|
|
468
|
+
} finally {
|
|
469
|
+
destroy();
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
describe("SvGridApi - sort opt-out + refresh", () => {
|
|
475
|
+
it("setSort with a direction sets a single active clause", async () => {
|
|
476
|
+
const { api, destroy } = await mountGrid();
|
|
477
|
+
try {
|
|
478
|
+
api.setSort("salary", "asc");
|
|
479
|
+
await flush();
|
|
480
|
+
expect(api.getState().sorting).toEqual([{ id: "salary", desc: false }]);
|
|
481
|
+
|
|
482
|
+
api.setSort("name", "desc");
|
|
483
|
+
await flush();
|
|
484
|
+
// Setting a direction replaces the active sort clause.
|
|
485
|
+
expect(api.getState().sorting).toEqual([{ id: "name", desc: true }]);
|
|
486
|
+
} finally {
|
|
487
|
+
destroy();
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("setSort with a falsy direction removes that column's clause", async () => {
|
|
492
|
+
const { api, destroy } = await mountGrid();
|
|
493
|
+
try {
|
|
494
|
+
api.setSort("salary", "asc");
|
|
495
|
+
await flush();
|
|
496
|
+
api.setSort("salary", null as any);
|
|
497
|
+
await flush();
|
|
498
|
+
expect(
|
|
499
|
+
api.getState().sorting.find((s) => s.id === "salary"),
|
|
500
|
+
).toBeUndefined();
|
|
501
|
+
} finally {
|
|
502
|
+
destroy();
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it("setSort is ignored for a non-sortable column", async () => {
|
|
507
|
+
const { api, destroy } = await mountGrid({
|
|
508
|
+
columns: [
|
|
509
|
+
{ field: "name", header: "Name", width: 200, sortable: false },
|
|
510
|
+
{ field: "team", header: "Team", width: 160 },
|
|
511
|
+
],
|
|
512
|
+
});
|
|
513
|
+
try {
|
|
514
|
+
api.setSort("name", "asc");
|
|
515
|
+
await flush();
|
|
516
|
+
expect(api.getState().sorting.find((s) => s.id === "name")).toBeUndefined();
|
|
517
|
+
} finally {
|
|
518
|
+
destroy();
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it("refresh re-runs the pipeline without throwing or losing data", async () => {
|
|
523
|
+
const { api, destroy } = await mountGrid();
|
|
524
|
+
try {
|
|
525
|
+
expect(() => api.refresh()).not.toThrow();
|
|
526
|
+
await flush();
|
|
527
|
+
expect((api.getData() as Row[]).length).toBe(5);
|
|
528
|
+
} finally {
|
|
529
|
+
destroy();
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
});
|