@mhjuma/traverse 0.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 +21 -0
- package/package.json +46 -0
- package/src/bootstrap.spec.tsx +290 -0
- package/src/bootstrap.tsx +195 -0
- package/src/colors.ts +23 -0
- package/src/components/ChartPanel/ChartPanel.logic.spec.ts +358 -0
- package/src/components/ChartPanel/ChartPanel.logic.ts +318 -0
- package/src/components/ChartPanel/ChartPanel.spec.tsx +331 -0
- package/src/components/ChartPanel/ChartPanel.styles.ts +14 -0
- package/src/components/ChartPanel/ChartPanel.tsx +151 -0
- package/src/components/ConnectionDialog/ConnectionDialog.spec.tsx +767 -0
- package/src/components/ConnectionDialog/ConnectionDialog.tsx +652 -0
- package/src/components/ConnectionDialog/ConnectionRow.spec.tsx +104 -0
- package/src/components/ConnectionDialog/ConnectionRow.tsx +177 -0
- package/src/components/EditorToolbar/EditorToolbar.spec.tsx +599 -0
- package/src/components/EditorToolbar/EditorToolbar.tsx +259 -0
- package/src/components/Explorer/Explorer.spec.tsx +615 -0
- package/src/components/Explorer/Explorer.tsx +49 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.spec.ts +715 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.ts +324 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.spec.tsx +450 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.styles.ts +478 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.tsx +648 -0
- package/src/components/ExplorerWorkspace/kqlLanguage.spec.ts +321 -0
- package/src/components/ExplorerWorkspace/kqlLanguage.ts +155 -0
- package/src/components/ResultsPanel/ElapsedTimer.spec.tsx +51 -0
- package/src/components/ResultsPanel/ElapsedTimer.tsx +15 -0
- package/src/components/ResultsPanel/HistoryItem.spec.tsx +123 -0
- package/src/components/ResultsPanel/HistoryItem.tsx +56 -0
- package/src/components/ResultsPanel/ResultSetTab.tsx +18 -0
- package/src/components/ResultsPanel/ResultsPanel.spec.tsx +1194 -0
- package/src/components/ResultsPanel/ResultsPanel.tsx +321 -0
- package/src/components/ResultsPanel/TabButton.tsx +11 -0
- package/src/components/ResultsTable/ColumnHeader.tsx +42 -0
- package/src/components/ResultsTable/ColumnPickerItem.tsx +16 -0
- package/src/components/ResultsTable/FilterCell.tsx +24 -0
- package/src/components/ResultsTable/ResultsTable.logic.spec.ts +655 -0
- package/src/components/ResultsTable/ResultsTable.logic.ts +264 -0
- package/src/components/ResultsTable/ResultsTable.spec.tsx +930 -0
- package/src/components/ResultsTable/ResultsTable.styles.ts +108 -0
- package/src/components/ResultsTable/ResultsTable.tsx +501 -0
- package/src/components/ResultsTable/VirtualCell.spec.tsx +55 -0
- package/src/components/ResultsTable/VirtualCell.tsx +32 -0
- package/src/components/ResultsTable/VirtualRow.tsx +55 -0
- package/src/components/SchemaSidebar/FolderRow.tsx +35 -0
- package/src/components/SchemaSidebar/SchemaColumnItem.tsx +41 -0
- package/src/components/SchemaSidebar/SchemaContextMenu.spec.tsx +148 -0
- package/src/components/SchemaSidebar/SchemaContextMenu.tsx +49 -0
- package/src/components/SchemaSidebar/SchemaSidebar.logic.spec.ts +230 -0
- package/src/components/SchemaSidebar/SchemaSidebar.logic.ts +74 -0
- package/src/components/SchemaSidebar/SchemaSidebar.spec.tsx +1111 -0
- package/src/components/SchemaSidebar/SchemaSidebar.tsx +244 -0
- package/src/components/SchemaSidebar/SchemaTableItem.tsx +77 -0
- package/src/components/TabBar/TabBar.logic.spec.ts +127 -0
- package/src/components/TabBar/TabBar.logic.ts +35 -0
- package/src/components/TabBar/TabBar.spec.tsx +929 -0
- package/src/components/TabBar/TabBar.tsx +284 -0
- package/src/components/TabBar/TabItem.tsx +166 -0
- package/src/components/VegaChart/VegaChart.spec.tsx +126 -0
- package/src/components/VegaChart/VegaChart.tsx +224 -0
- package/src/config.spec.ts +44 -0
- package/src/config.ts +47 -0
- package/src/context/ExplorerColorContext.ts +14 -0
- package/src/context/ExplorerStateContext.ts +49 -0
- package/src/context/KustoClientContext.ts +12 -0
- package/src/context/context.spec.tsx +183 -0
- package/src/index.ts +14 -0
- package/src/services/cache.spec.ts +31 -0
- package/src/services/cache.ts +16 -0
- package/src/services/concurrency.spec.ts +139 -0
- package/src/services/concurrency.ts +46 -0
- package/src/services/kusto.spec.ts +919 -0
- package/src/services/kusto.ts +472 -0
- package/src/services/queryHistory.spec.ts +287 -0
- package/src/services/queryHistory.ts +146 -0
- package/src/services/schema.spec.ts +618 -0
- package/src/services/schema.ts +294 -0
- package/src/services/state-service.spec.ts +670 -0
- package/src/services/state-service.ts +602 -0
- package/src/services/useKustoQuery.spec.ts +234 -0
- package/src/services/useKustoQuery.ts +124 -0
- package/src/state/actions.ts +50 -0
- package/src/state/index.ts +3 -0
- package/src/state/reducer.spec.ts +644 -0
- package/src/state/reducer.ts +207 -0
- package/src/state/types.ts +54 -0
- package/tsconfig.json +7 -0
- package/tsconfig.lint.json +4 -0
- package/tsconfig.spec.json +7 -0
- package/vitest.config.ts +34 -0
|
@@ -0,0 +1,930 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { act } from 'react';
|
|
5
|
+
import { isCellInRange, parseHighlightExpr, matchesHighlight, computeAggregates, computeDateDelta, findEmptyColumns, buildSelectionTsv } from './ResultsTable.logic';
|
|
6
|
+
import { ResultsTable } from './ResultsTable';
|
|
7
|
+
|
|
8
|
+
vi.mock('@tanstack/react-virtual', () => ({
|
|
9
|
+
useVirtualizer: () => mockUseVirtualizer(),
|
|
10
|
+
}));
|
|
11
|
+
vi.mock('@monaco-editor/react', () => ({
|
|
12
|
+
default: () => React.createElement('div', { 'data-testid': 'monaco-editor' }),
|
|
13
|
+
}));
|
|
14
|
+
vi.mock('../../context/ExplorerColorContext', () => ({
|
|
15
|
+
useExplorerColors: () => ({
|
|
16
|
+
semantic: { scrollThumb: '#ccc', scrollThumbHover: '#aaa', backdrop: '#000', shadowMedium: '#000', shadowLight: '#000', functionBadge: '#0f0', materializedViewBadge: '#90f', lookupBadge: '#f90', selectionBg: '#00f', selectionSubtle: '#eef', highlightHoverBg: '#ffa' },
|
|
17
|
+
chart: { palette: [] },
|
|
18
|
+
}),
|
|
19
|
+
}));
|
|
20
|
+
vi.mock('./ResultsTable.logic', () => ({
|
|
21
|
+
isCellInRange: vi.fn(() => false),
|
|
22
|
+
serializeCellValue: vi.fn((value: unknown) => value === null || value === undefined ? '' : typeof value === 'object' ? JSON.stringify(value) : String(value)),
|
|
23
|
+
formatCellDisplayValue: vi.fn((value: unknown) => value === null || value === undefined ? '' : typeof value === 'object' ? JSON.stringify(value) : String(value)),
|
|
24
|
+
buildSelectionTsv: vi.fn((_rows: unknown[], _columns: string[], selection: unknown) => selection ? 'copied-data' : ''),
|
|
25
|
+
parseHighlightExpr: vi.fn(() => null),
|
|
26
|
+
matchesHighlight: vi.fn(() => false),
|
|
27
|
+
computeAggregates: vi.fn(() => ({})),
|
|
28
|
+
computeDateDelta: vi.fn(() => null),
|
|
29
|
+
shortType: vi.fn((t: string) => t),
|
|
30
|
+
computeColumnWidths: vi.fn(() => ({})),
|
|
31
|
+
sortRows: vi.fn((rows: unknown[]) => rows),
|
|
32
|
+
filterRows: vi.fn((rows: unknown[]) => rows),
|
|
33
|
+
findEmptyColumns: vi.fn(() => new Set()),
|
|
34
|
+
}));
|
|
35
|
+
vi.mock('./ResultsTable.styles', () => ({
|
|
36
|
+
useStyles: () => new Proxy({}, { get: (_, p) => String(p) }),
|
|
37
|
+
}));
|
|
38
|
+
vi.mock('@fluentui/react-components', () => ({
|
|
39
|
+
Input: (p: Record<string, unknown>) => {
|
|
40
|
+
const { onChange, ...rest } = p;
|
|
41
|
+
const handleChange = onChange ? (e: Event) => {
|
|
42
|
+
(onChange as (e: Event, d: { value: string }) => void)(e, { value: (e.target as HTMLInputElement).value });
|
|
43
|
+
} : undefined;
|
|
44
|
+
return React.createElement('input', { ...rest, onChange: handleChange });
|
|
45
|
+
},
|
|
46
|
+
Button: (p: Record<string, unknown>) => React.createElement('button', p, p['children'] as React.ReactNode),
|
|
47
|
+
Tooltip: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
|
|
48
|
+
Popover: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
|
|
49
|
+
PopoverTrigger: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
|
|
50
|
+
PopoverSurface: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
|
|
51
|
+
Checkbox: (p: Record<string, unknown>) => {
|
|
52
|
+
const { onChange, label, ...rest } = p;
|
|
53
|
+
const handleChange = onChange ? () => {
|
|
54
|
+
(onChange as () => void)();
|
|
55
|
+
} : undefined;
|
|
56
|
+
return React.createElement('label', null,
|
|
57
|
+
React.createElement('input', { type: 'checkbox', ...rest, onChange: handleChange }),
|
|
58
|
+
label as React.ReactNode,
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
}));
|
|
62
|
+
vi.mock('@fluentui/react-icons', () => ({
|
|
63
|
+
SearchRegular: () => React.createElement('span', null, 'icon'),
|
|
64
|
+
ColumnTripleRegular: () => React.createElement('span', null, 'icon'),
|
|
65
|
+
EyeOffRegular: () => React.createElement('span', null, 'icon'),
|
|
66
|
+
FilterRegular: () => React.createElement('span', null, 'icon'),
|
|
67
|
+
ArrowSortDownRegular: () => React.createElement('span', null, 'icon'),
|
|
68
|
+
ArrowSortUpRegular: () => React.createElement('span', null, 'icon'),
|
|
69
|
+
DismissRegular: () => React.createElement('span', null, 'icon'),
|
|
70
|
+
ChevronRightRegular: () => React.createElement('span', null, 'icon'),
|
|
71
|
+
DismissCircleRegular: () => React.createElement('span', null, 'icon'),
|
|
72
|
+
HighlightRegular: () => React.createElement('span', null, 'icon'),
|
|
73
|
+
CodeRegular: () => React.createElement('span', null, 'icon'),
|
|
74
|
+
TableSimpleRegular: () => React.createElement('span', null, 'icon'),
|
|
75
|
+
TextBulletListRegular: () => React.createElement('span', null, 'icon'),
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
const mockUseVirtualizer = vi.fn(() => ({
|
|
79
|
+
getVirtualItems: () => [] as { index: number; start: number; key: string | number; size: number }[],
|
|
80
|
+
getTotalSize: () => 0 as number,
|
|
81
|
+
measureElement: vi.fn(),
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const mockedIsCellInRange = vi.mocked(isCellInRange);
|
|
86
|
+
const mockedParseHighlightExpr = vi.mocked(parseHighlightExpr);
|
|
87
|
+
const mockedMatchesHighlight = vi.mocked(matchesHighlight);
|
|
88
|
+
const mockedComputeAggregates = vi.mocked(computeAggregates);
|
|
89
|
+
const mockedComputeDateDelta = vi.mocked(computeDateDelta);
|
|
90
|
+
const mockedFindEmptyColumns = vi.mocked(findEmptyColumns);
|
|
91
|
+
const mockedBuildSelectionTsv = vi.mocked(buildSelectionTsv);
|
|
92
|
+
|
|
93
|
+
const makeVirtualItems = (count: number) =>
|
|
94
|
+
Array.from({ length: count }, (_, i) => ({ index: i, start: i * 28, key: String(i), size: 28 }));
|
|
95
|
+
|
|
96
|
+
describe('ResultsTable', () => {
|
|
97
|
+
let container: HTMLDivElement;
|
|
98
|
+
let root: ReturnType<typeof createRoot>;
|
|
99
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
100
|
+
let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
|
|
101
|
+
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
if (!Element.prototype.scrollTo) {
|
|
104
|
+
Element.prototype.scrollTo = vi.fn();
|
|
105
|
+
}
|
|
106
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
107
|
+
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
108
|
+
container = document.createElement('div');
|
|
109
|
+
document.body.appendChild(container);
|
|
110
|
+
root = createRoot(container);
|
|
111
|
+
mockUseVirtualizer.mockReturnValue({
|
|
112
|
+
getVirtualItems: () => [],
|
|
113
|
+
getTotalSize: () => 0,
|
|
114
|
+
measureElement: vi.fn(),
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
afterEach(() => {
|
|
119
|
+
act(() => {
|
|
120
|
+
root.unmount();
|
|
121
|
+
});
|
|
122
|
+
container.remove();
|
|
123
|
+
consoleErrorSpy.mockRestore();
|
|
124
|
+
consoleWarnSpy.mockRestore();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('renders with empty data', () => {
|
|
128
|
+
act(() => {
|
|
129
|
+
root.render(React.createElement(ResultsTable, {
|
|
130
|
+
columns: [],
|
|
131
|
+
rows: [],
|
|
132
|
+
}));
|
|
133
|
+
});
|
|
134
|
+
expect(container.innerHTML).not.toBe('');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('renders with sample data', () => {
|
|
138
|
+
act(() => {
|
|
139
|
+
root.render(React.createElement(ResultsTable, {
|
|
140
|
+
columns: ['Name', 'Value'],
|
|
141
|
+
rows: [
|
|
142
|
+
{ Name: 'alpha', Value: 1 },
|
|
143
|
+
{ Name: 'beta', Value: 2 },
|
|
144
|
+
],
|
|
145
|
+
isDark: false,
|
|
146
|
+
columnTypes: { Name: 'string', Value: 'long' },
|
|
147
|
+
}));
|
|
148
|
+
});
|
|
149
|
+
expect(container.innerHTML).not.toBe('');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('renders toolbar with search, filter, and column picker', () => {
|
|
153
|
+
act(() => {
|
|
154
|
+
root.render(React.createElement(ResultsTable, {
|
|
155
|
+
columns: ['Name', 'Value'],
|
|
156
|
+
rows: [{ Name: 'alpha', Value: 1 }],
|
|
157
|
+
isDark: false,
|
|
158
|
+
columnTypes: { Name: 'string', Value: 'long' },
|
|
159
|
+
}));
|
|
160
|
+
});
|
|
161
|
+
// Should have search input
|
|
162
|
+
const inputs = container.querySelectorAll('input');
|
|
163
|
+
expect(inputs.length).toBeGreaterThan(0);
|
|
164
|
+
// Should have buttons for filter, hide empty, column picker
|
|
165
|
+
const buttons = container.querySelectorAll('button');
|
|
166
|
+
expect(buttons.length).toBeGreaterThan(0);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('renders with headerLeft and headerRight props', () => {
|
|
170
|
+
act(() => {
|
|
171
|
+
root.render(React.createElement(ResultsTable, {
|
|
172
|
+
columns: ['A'],
|
|
173
|
+
rows: [{ A: 1 }],
|
|
174
|
+
headerLeft: React.createElement('span', null, 'left-header'),
|
|
175
|
+
headerRight: React.createElement('span', null, 'right-header'),
|
|
176
|
+
}));
|
|
177
|
+
});
|
|
178
|
+
expect(container.textContent).toContain('left-header');
|
|
179
|
+
expect(container.textContent).toContain('right-header');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('shows status bar with row and column counts', () => {
|
|
183
|
+
act(() => {
|
|
184
|
+
root.render(React.createElement(ResultsTable, {
|
|
185
|
+
columns: ['Name', 'Value', 'Extra'],
|
|
186
|
+
rows: [
|
|
187
|
+
{ Name: 'a', Value: 1, Extra: 'x' },
|
|
188
|
+
{ Name: 'b', Value: 2, Extra: 'y' },
|
|
189
|
+
],
|
|
190
|
+
}));
|
|
191
|
+
});
|
|
192
|
+
expect(container.textContent).toContain('2');
|
|
193
|
+
expect(container.textContent).toContain('3');
|
|
194
|
+
expect(container.textContent).toContain('columns');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('renders column headers with type annotations', () => {
|
|
198
|
+
act(() => {
|
|
199
|
+
root.render(React.createElement(ResultsTable, {
|
|
200
|
+
columns: ['Timestamp', 'Count'],
|
|
201
|
+
rows: [{ Timestamp: '2024-01-01', Count: 42 }],
|
|
202
|
+
columnTypes: { Timestamp: 'datetime', Count: 'long' },
|
|
203
|
+
}));
|
|
204
|
+
});
|
|
205
|
+
expect(container.textContent).toContain('Timestamp');
|
|
206
|
+
expect(container.textContent).toContain('Count');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('renders highlight input', () => {
|
|
210
|
+
act(() => {
|
|
211
|
+
root.render(React.createElement(ResultsTable, {
|
|
212
|
+
columns: ['Name'],
|
|
213
|
+
rows: [{ Name: 'test' }],
|
|
214
|
+
}));
|
|
215
|
+
});
|
|
216
|
+
// There should be a highlight input with placeholder
|
|
217
|
+
const inputs = container.querySelectorAll('input');
|
|
218
|
+
const highlightInput = Array.from(inputs).find(
|
|
219
|
+
(i) => i.getAttribute('placeholder')?.includes('Highlight'),
|
|
220
|
+
);
|
|
221
|
+
expect(highlightInput).toBeTruthy();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('renders checkbox items in column picker', () => {
|
|
225
|
+
act(() => {
|
|
226
|
+
root.render(React.createElement(ResultsTable, {
|
|
227
|
+
columns: ['Col1', 'Col2', 'Col3'],
|
|
228
|
+
rows: [{ Col1: 'a', Col2: 'b', Col3: 'c' }],
|
|
229
|
+
}));
|
|
230
|
+
});
|
|
231
|
+
// Column picker should have checkboxes for each column
|
|
232
|
+
const checkboxes = container.querySelectorAll('input[type="checkbox"]');
|
|
233
|
+
expect(checkboxes.length).toBe(3);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('handles search input changes', () => {
|
|
237
|
+
act(() => {
|
|
238
|
+
root.render(React.createElement(ResultsTable, {
|
|
239
|
+
columns: ['Name', 'Value'],
|
|
240
|
+
rows: [{ Name: 'alpha', Value: 1 }, { Name: 'beta', Value: 2 }],
|
|
241
|
+
}));
|
|
242
|
+
});
|
|
243
|
+
// Find search input by placeholder
|
|
244
|
+
const inputs = container.querySelectorAll('input');
|
|
245
|
+
const searchInput = Array.from(inputs).find(
|
|
246
|
+
(i) => i.getAttribute('placeholder')?.includes('Search') || i.getAttribute('placeholder')?.includes('Filter'),
|
|
247
|
+
);
|
|
248
|
+
if (searchInput) {
|
|
249
|
+
act(() => {
|
|
250
|
+
const event = new Event('change', { bubbles: true });
|
|
251
|
+
searchInput.dispatchEvent(event);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
expect(container.innerHTML).toBeTruthy();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('handles column header click for sorting', () => {
|
|
258
|
+
act(() => {
|
|
259
|
+
root.render(React.createElement(ResultsTable, {
|
|
260
|
+
columns: ['Name', 'Value'],
|
|
261
|
+
rows: [{ Name: 'alpha', Value: 1 }, { Name: 'beta', Value: 2 }],
|
|
262
|
+
columnTypes: { Name: 'string', Value: 'long' },
|
|
263
|
+
}));
|
|
264
|
+
});
|
|
265
|
+
// Click on column header text to toggle sort
|
|
266
|
+
const headerCells = container.querySelectorAll('th, [class*="headerCell"]');
|
|
267
|
+
if (headerCells.length > 0) {
|
|
268
|
+
act(() => { (headerCells[0] as HTMLElement).click(); });
|
|
269
|
+
}
|
|
270
|
+
expect(container.innerHTML).toBeTruthy();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('handles checkbox toggle in column picker', () => {
|
|
274
|
+
act(() => {
|
|
275
|
+
root.render(React.createElement(ResultsTable, {
|
|
276
|
+
columns: ['Col1', 'Col2', 'Col3'],
|
|
277
|
+
rows: [{ Col1: 'a', Col2: 'b', Col3: 'c' }],
|
|
278
|
+
}));
|
|
279
|
+
});
|
|
280
|
+
const checkboxes = container.querySelectorAll('input[type="checkbox"]');
|
|
281
|
+
if (checkboxes.length > 0) {
|
|
282
|
+
act(() => {
|
|
283
|
+
(checkboxes[0] as HTMLInputElement).click();
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
expect(container.innerHTML).toBeTruthy();
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('handles filter button click', () => {
|
|
290
|
+
act(() => {
|
|
291
|
+
root.render(React.createElement(ResultsTable, {
|
|
292
|
+
columns: ['Name'],
|
|
293
|
+
rows: [{ Name: 'test' }],
|
|
294
|
+
}));
|
|
295
|
+
});
|
|
296
|
+
// Find and click buttons
|
|
297
|
+
const buttons = container.querySelectorAll('button');
|
|
298
|
+
for (const btn of Array.from(buttons)) {
|
|
299
|
+
act(() => { btn.click(); });
|
|
300
|
+
}
|
|
301
|
+
expect(container.innerHTML).toBeTruthy();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('handles highlight input', () => {
|
|
305
|
+
act(() => {
|
|
306
|
+
root.render(React.createElement(ResultsTable, {
|
|
307
|
+
columns: ['Name'],
|
|
308
|
+
rows: [{ Name: 'test' }],
|
|
309
|
+
}));
|
|
310
|
+
});
|
|
311
|
+
const inputs = container.querySelectorAll('input');
|
|
312
|
+
const highlightInput = Array.from(inputs).find(
|
|
313
|
+
(i) => i.getAttribute('placeholder')?.includes('Highlight'),
|
|
314
|
+
);
|
|
315
|
+
if (highlightInput) {
|
|
316
|
+
act(() => {
|
|
317
|
+
highlightInput.dispatchEvent(new Event('change', { bubbles: true }));
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
expect(container.innerHTML).toBeTruthy();
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('renders with isDark prop', () => {
|
|
324
|
+
act(() => {
|
|
325
|
+
root.render(React.createElement(ResultsTable, {
|
|
326
|
+
columns: ['Name'],
|
|
327
|
+
rows: [{ Name: 'test' }],
|
|
328
|
+
isDark: true,
|
|
329
|
+
}));
|
|
330
|
+
});
|
|
331
|
+
expect(container.innerHTML).toBeTruthy();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// --- Virtual rows rendering and interactions ---
|
|
335
|
+
|
|
336
|
+
const renderWithVirtualRows = (props?: Partial<{
|
|
337
|
+
columns: string[];
|
|
338
|
+
rows: Record<string, unknown>[];
|
|
339
|
+
isDark: boolean;
|
|
340
|
+
columnTypes: Record<string, string>;
|
|
341
|
+
headerLeft: React.ReactNode;
|
|
342
|
+
headerRight: React.ReactNode;
|
|
343
|
+
}>) => {
|
|
344
|
+
const columns = props?.columns ?? ['Name', 'Value'];
|
|
345
|
+
const rows = props?.rows ?? [
|
|
346
|
+
{ Name: 'alpha', Value: 1 },
|
|
347
|
+
{ Name: 'beta', Value: 2 },
|
|
348
|
+
];
|
|
349
|
+
mockUseVirtualizer.mockReturnValue({
|
|
350
|
+
getVirtualItems: () => makeVirtualItems(rows.length),
|
|
351
|
+
getTotalSize: () => rows.length * 28,
|
|
352
|
+
measureElement: vi.fn(),
|
|
353
|
+
});
|
|
354
|
+
act(() => {
|
|
355
|
+
root.render(React.createElement(ResultsTable, {
|
|
356
|
+
columns,
|
|
357
|
+
rows,
|
|
358
|
+
isDark: props?.isDark ?? false,
|
|
359
|
+
columnTypes: props?.columnTypes ?? { Name: 'string', Value: 'long' },
|
|
360
|
+
headerLeft: props?.headerLeft,
|
|
361
|
+
headerRight: props?.headerRight,
|
|
362
|
+
}));
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
it('renders virtual rows when virtualizer returns items', () => {
|
|
367
|
+
renderWithVirtualRows();
|
|
368
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
369
|
+
expect(expandBtns.length).toBe(2);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('copies the selected cells as plain text', () => {
|
|
373
|
+
renderWithVirtualRows();
|
|
374
|
+
const firstCell = container.querySelector('div[class="td"]');
|
|
375
|
+
const scrollContainer = container.querySelector('div[class*="scrollContainer"]');
|
|
376
|
+
expect(firstCell).toBeTruthy();
|
|
377
|
+
expect(scrollContainer).toBeTruthy();
|
|
378
|
+
|
|
379
|
+
act(() => {
|
|
380
|
+
firstCell!.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const setData = vi.fn();
|
|
384
|
+
const copyEvent = new Event('copy', { bubbles: true, cancelable: true });
|
|
385
|
+
Object.defineProperty(copyEvent, 'clipboardData', {
|
|
386
|
+
value: { setData },
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
act(() => {
|
|
390
|
+
scrollContainer!.dispatchEvent(copyEvent);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
expect(mockedBuildSelectionTsv).toHaveBeenCalled();
|
|
394
|
+
expect(setData).toHaveBeenCalledWith('text/plain', 'copied-data');
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('toggleSort cycles through asc, desc, null on same column', () => {
|
|
398
|
+
renderWithVirtualRows();
|
|
399
|
+
const headerBtns = container.querySelectorAll('button[class="th"]');
|
|
400
|
+
expect(headerBtns.length).toBeGreaterThan(0);
|
|
401
|
+
const nameHeader = headerBtns[0] as HTMLElement;
|
|
402
|
+
// First click: asc
|
|
403
|
+
act(() => { nameHeader.click(); });
|
|
404
|
+
// Second click: desc
|
|
405
|
+
act(() => { nameHeader.click(); });
|
|
406
|
+
// Third click: null (reset)
|
|
407
|
+
act(() => { nameHeader.click(); });
|
|
408
|
+
expect(container.innerHTML).toBeTruthy();
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('toggleSort switches column when clicking different column', () => {
|
|
412
|
+
renderWithVirtualRows();
|
|
413
|
+
const headerBtns = container.querySelectorAll('button[class="th"]');
|
|
414
|
+
// Click Name column
|
|
415
|
+
act(() => { (headerBtns[0] as HTMLElement).click(); });
|
|
416
|
+
// Click Value column — should switch sort to Value
|
|
417
|
+
act(() => { (headerBtns[1] as HTMLElement).click(); });
|
|
418
|
+
expect(container.innerHTML).toBeTruthy();
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it('handles column header keyboard events (Enter and Space)', () => {
|
|
422
|
+
renderWithVirtualRows();
|
|
423
|
+
const headerBtns = container.querySelectorAll('button[class="th"]');
|
|
424
|
+
const header = headerBtns[0] as HTMLElement;
|
|
425
|
+
act(() => {
|
|
426
|
+
header.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
|
427
|
+
});
|
|
428
|
+
act(() => {
|
|
429
|
+
header.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));
|
|
430
|
+
});
|
|
431
|
+
// Non-matching key should not toggle
|
|
432
|
+
act(() => {
|
|
433
|
+
header.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true }));
|
|
434
|
+
});
|
|
435
|
+
expect(container.innerHTML).toBeTruthy();
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('handles column header double-click to select entire column', () => {
|
|
439
|
+
renderWithVirtualRows();
|
|
440
|
+
const headerBtns = container.querySelectorAll('button[class="th"]');
|
|
441
|
+
act(() => {
|
|
442
|
+
headerBtns[0].dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
|
|
443
|
+
});
|
|
444
|
+
expect(container.innerHTML).toBeTruthy();
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('toggles filter row visibility', () => {
|
|
448
|
+
renderWithVirtualRows();
|
|
449
|
+
const allBtns = Array.from(container.querySelectorAll('button'));
|
|
450
|
+
// The filter toggle button
|
|
451
|
+
// Click all toolbar buttons to find the filter toggle — use the third button after search
|
|
452
|
+
const toolbarBtns = allBtns.filter((b) => b.getAttribute('class') !== 'th' && b.getAttribute('class') !== 'expandBtn');
|
|
453
|
+
// Toggle filters on
|
|
454
|
+
if (toolbarBtns.length > 0) {
|
|
455
|
+
act(() => { toolbarBtns[0].click(); });
|
|
456
|
+
}
|
|
457
|
+
// Should now have filter inputs
|
|
458
|
+
expect(container.innerHTML).toBeTruthy();
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('toggles hide empty columns', () => {
|
|
462
|
+
renderWithVirtualRows();
|
|
463
|
+
const toolbarBtns = Array.from(container.querySelectorAll('button')).filter(
|
|
464
|
+
(b) => b.getAttribute('class') !== 'th' && b.getAttribute('class') !== 'expandBtn',
|
|
465
|
+
);
|
|
466
|
+
// Second toolbar button is hide empty
|
|
467
|
+
if (toolbarBtns.length > 1) {
|
|
468
|
+
act(() => { toolbarBtns[1].click(); });
|
|
469
|
+
}
|
|
470
|
+
expect(container.innerHTML).toBeTruthy();
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it('handles global search change and clear', () => {
|
|
474
|
+
renderWithVirtualRows();
|
|
475
|
+
const searchInput = Array.from(container.querySelectorAll('input')).find(
|
|
476
|
+
(i) => i.getAttribute('placeholder')?.includes('Search'),
|
|
477
|
+
);
|
|
478
|
+
expect(searchInput).toBeTruthy();
|
|
479
|
+
// Type into search
|
|
480
|
+
act(() => {
|
|
481
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(searchInput, 'alpha');
|
|
482
|
+
searchInput!.dispatchEvent(new Event('input', { bubbles: true }));
|
|
483
|
+
searchInput!.dispatchEvent(new Event('change', { bubbles: true }));
|
|
484
|
+
});
|
|
485
|
+
// After search has value, contentAfter dismiss button should appear
|
|
486
|
+
// Re-render to check
|
|
487
|
+
expect(container.innerHTML).toBeTruthy();
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it('resets table view state when a new result set is rendered', () => {
|
|
491
|
+
renderWithVirtualRows();
|
|
492
|
+
|
|
493
|
+
const searchInput = Array.from(container.querySelectorAll('input')).find(
|
|
494
|
+
(i) => i.getAttribute('placeholder')?.includes('Search'),
|
|
495
|
+
) as HTMLInputElement | undefined;
|
|
496
|
+
expect(searchInput).toBeTruthy();
|
|
497
|
+
|
|
498
|
+
act(() => {
|
|
499
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(searchInput, 'alpha');
|
|
500
|
+
searchInput!.dispatchEvent(new Event('input', { bubbles: true }));
|
|
501
|
+
searchInput!.dispatchEvent(new Event('change', { bubbles: true }));
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
const toolbarBtns = Array.from(container.querySelectorAll('button')).filter(
|
|
505
|
+
(b) => b.getAttribute('class') !== 'th' && b.getAttribute('class') !== 'expandBtn',
|
|
506
|
+
);
|
|
507
|
+
act(() => { toolbarBtns[0].click(); });
|
|
508
|
+
expect(container.querySelectorAll('input[placeholder="filter..."]').length).toBeGreaterThan(0);
|
|
509
|
+
|
|
510
|
+
renderWithVirtualRows({
|
|
511
|
+
columns: ['FeatureName', 'State'],
|
|
512
|
+
rows: [{ FeatureName: 'MyFlight', State: 'Enabled' }],
|
|
513
|
+
columnTypes: { FeatureName: 'string', State: 'string' },
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
const nextSearchInput = Array.from(container.querySelectorAll('input')).find(
|
|
517
|
+
(i) => i.getAttribute('placeholder')?.includes('Search'),
|
|
518
|
+
) as HTMLInputElement | undefined;
|
|
519
|
+
expect(nextSearchInput?.value).toBe('');
|
|
520
|
+
expect(container.querySelectorAll('input[placeholder="filter..."]')).toHaveLength(0);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it('handles highlight input change and clear', () => {
|
|
524
|
+
renderWithVirtualRows();
|
|
525
|
+
const highlightInput = Array.from(container.querySelectorAll('input')).find(
|
|
526
|
+
(i) => i.getAttribute('placeholder')?.includes('Highlight'),
|
|
527
|
+
);
|
|
528
|
+
expect(highlightInput).toBeTruthy();
|
|
529
|
+
act(() => {
|
|
530
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(highlightInput, 'Name == alpha');
|
|
531
|
+
highlightInput!.dispatchEvent(new Event('input', { bubbles: true }));
|
|
532
|
+
highlightInput!.dispatchEvent(new Event('change', { bubbles: true }));
|
|
533
|
+
});
|
|
534
|
+
expect(container.innerHTML).toBeTruthy();
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
it('shows all and hides all columns via column picker', () => {
|
|
538
|
+
renderWithVirtualRows();
|
|
539
|
+
const allBtns = Array.from(container.querySelectorAll('button'));
|
|
540
|
+
const showAllBtn = allBtns.find((b) => b.textContent === 'Show all');
|
|
541
|
+
const hideAllBtn = allBtns.find((b) => b.textContent === 'Hide all');
|
|
542
|
+
expect(showAllBtn).toBeTruthy();
|
|
543
|
+
expect(hideAllBtn).toBeTruthy();
|
|
544
|
+
act(() => { hideAllBtn!.click(); });
|
|
545
|
+
act(() => { showAllBtn!.click(); });
|
|
546
|
+
expect(container.innerHTML).toBeTruthy();
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('toggles column visibility via checkbox', () => {
|
|
550
|
+
renderWithVirtualRows();
|
|
551
|
+
const checkboxes = container.querySelectorAll('input[type="checkbox"]');
|
|
552
|
+
expect(checkboxes.length).toBe(2);
|
|
553
|
+
// Uncheck first column
|
|
554
|
+
act(() => { (checkboxes[0] as HTMLInputElement).click(); });
|
|
555
|
+
// Check it back
|
|
556
|
+
act(() => { (checkboxes[0] as HTMLInputElement).click(); });
|
|
557
|
+
expect(container.innerHTML).toBeTruthy();
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
it('expands row detail and switches detail modes', () => {
|
|
561
|
+
renderWithVirtualRows();
|
|
562
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
563
|
+
expect(expandBtns.length).toBe(2);
|
|
564
|
+
// Expand first row
|
|
565
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
566
|
+
// Detail panel should appear with Row 1
|
|
567
|
+
expect(container.textContent).toContain('Row 1');
|
|
568
|
+
// Find the 3 mode buttons and close button in the detail header
|
|
569
|
+
const detailHeaderBtns = Array.from(container.querySelectorAll('[class="detailHeaderLeft"] button'));
|
|
570
|
+
if (detailHeaderBtns.length >= 3) {
|
|
571
|
+
// Click list mode
|
|
572
|
+
act(() => { (detailHeaderBtns[1] as HTMLElement).click(); });
|
|
573
|
+
expect(container.innerHTML).toBeTruthy();
|
|
574
|
+
// Click json mode
|
|
575
|
+
act(() => { (detailHeaderBtns[2] as HTMLElement).click(); });
|
|
576
|
+
expect(container.innerHTML).toBeTruthy();
|
|
577
|
+
// Click table mode again
|
|
578
|
+
act(() => { (detailHeaderBtns[0] as HTMLElement).click(); });
|
|
579
|
+
expect(container.innerHTML).toBeTruthy();
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it('closes detail panel', () => {
|
|
584
|
+
renderWithVirtualRows();
|
|
585
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
586
|
+
// Open detail
|
|
587
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
588
|
+
expect(container.textContent).toContain('Row 1');
|
|
589
|
+
// Find and click the close button in detail panel header
|
|
590
|
+
// The close button has dismissCircleIcon — it's the last button in the detail header area
|
|
591
|
+
// Find it by looking for the button directly inside detailHeader (not detailHeaderLeft)
|
|
592
|
+
const closeBtn = container.querySelector('[class="detailPanel"] > [class="detailHeader"] > button');
|
|
593
|
+
if (closeBtn) {
|
|
594
|
+
act(() => { (closeBtn as HTMLElement).click(); });
|
|
595
|
+
}
|
|
596
|
+
// After close, Row 1 detail should not be visible
|
|
597
|
+
expect(container.innerHTML).toBeTruthy();
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it('toggles detail open/closed on same row expand button', () => {
|
|
601
|
+
renderWithVirtualRows();
|
|
602
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
603
|
+
// Open
|
|
604
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
605
|
+
expect(container.textContent).toContain('Row 1');
|
|
606
|
+
// Close by clicking same expand button
|
|
607
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
608
|
+
expect(container.innerHTML).toBeTruthy();
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it('handles expand button keyboard Enter and Space', () => {
|
|
612
|
+
renderWithVirtualRows();
|
|
613
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
614
|
+
act(() => {
|
|
615
|
+
expandBtns[0].dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
|
616
|
+
});
|
|
617
|
+
expect(container.textContent).toContain('Row 1');
|
|
618
|
+
act(() => {
|
|
619
|
+
expandBtns[0].dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));
|
|
620
|
+
});
|
|
621
|
+
// Non-matching key
|
|
622
|
+
act(() => {
|
|
623
|
+
expandBtns[0].dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
|
|
624
|
+
});
|
|
625
|
+
expect(container.innerHTML).toBeTruthy();
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
it('handles cell mousedown to start selection', () => {
|
|
629
|
+
renderWithVirtualRows();
|
|
630
|
+
const cells = container.querySelectorAll('[class="td"]');
|
|
631
|
+
expect(cells.length).toBeGreaterThan(0);
|
|
632
|
+
// Click a cell
|
|
633
|
+
act(() => {
|
|
634
|
+
cells[0].dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
635
|
+
});
|
|
636
|
+
expect(container.innerHTML).toBeTruthy();
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it('handles cell mousedown with shift key to extend selection', () => {
|
|
640
|
+
renderWithVirtualRows();
|
|
641
|
+
const cells = container.querySelectorAll('[class="td"]');
|
|
642
|
+
// First click without shift
|
|
643
|
+
act(() => {
|
|
644
|
+
cells[0].dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
645
|
+
});
|
|
646
|
+
// Second click with shift
|
|
647
|
+
act(() => {
|
|
648
|
+
cells[cells.length - 1].dispatchEvent(new MouseEvent('mousedown', { bubbles: true, shiftKey: true }));
|
|
649
|
+
});
|
|
650
|
+
expect(container.innerHTML).toBeTruthy();
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it('handles cell mouse enter during drag', () => {
|
|
654
|
+
renderWithVirtualRows();
|
|
655
|
+
const cells = container.querySelectorAll('[class="td"]');
|
|
656
|
+
// Start dragging
|
|
657
|
+
act(() => {
|
|
658
|
+
cells[0].dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
659
|
+
});
|
|
660
|
+
// Drag to another cell
|
|
661
|
+
act(() => {
|
|
662
|
+
cells[1].dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
|
|
663
|
+
});
|
|
664
|
+
// Mouseup to stop dragging
|
|
665
|
+
act(() => {
|
|
666
|
+
document.dispatchEvent(new MouseEvent('mouseup'));
|
|
667
|
+
});
|
|
668
|
+
// Enter after mouseup — should not extend selection
|
|
669
|
+
act(() => {
|
|
670
|
+
cells[2].dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
|
|
671
|
+
});
|
|
672
|
+
expect(container.innerHTML).toBeTruthy();
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
it('handles mouse enter without active drag (no-op)', () => {
|
|
676
|
+
renderWithVirtualRows();
|
|
677
|
+
const cells = container.querySelectorAll('[class="td"]');
|
|
678
|
+
// mouseenter without prior mousedown
|
|
679
|
+
act(() => {
|
|
680
|
+
cells[0].dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
|
|
681
|
+
});
|
|
682
|
+
expect(container.innerHTML).toBeTruthy();
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it('renders filter row when showFilters is toggled', () => {
|
|
686
|
+
renderWithVirtualRows();
|
|
687
|
+
// Find filter toggle button — it has filterIcon
|
|
688
|
+
const toolbarBtn = Array.from(container.querySelectorAll('button')).find(
|
|
689
|
+
(b) => b.getAttribute('class') !== 'th' && b.getAttribute('class') !== 'expandBtn',
|
|
690
|
+
);
|
|
691
|
+
// Toggle filters on (first toolbar button after search area)
|
|
692
|
+
act(() => { toolbarBtn!.click(); });
|
|
693
|
+
// Filter inputs should be rendered
|
|
694
|
+
const filterInputs = container.querySelectorAll('input[placeholder="filter..."]');
|
|
695
|
+
expect(filterInputs.length).toBe(2);
|
|
696
|
+
// Type in a filter
|
|
697
|
+
act(() => {
|
|
698
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(filterInputs[0], 'alpha');
|
|
699
|
+
filterInputs[0].dispatchEvent(new Event('input', { bubbles: true }));
|
|
700
|
+
filterInputs[0].dispatchEvent(new Event('change', { bubbles: true }));
|
|
701
|
+
});
|
|
702
|
+
expect(container.innerHTML).toBeTruthy();
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it('renders detail panel with object values in table mode', () => {
|
|
706
|
+
renderWithVirtualRows({
|
|
707
|
+
columns: ['Name', 'Data'],
|
|
708
|
+
rows: [
|
|
709
|
+
{ Name: 'alpha', Data: { nested: 'obj' } },
|
|
710
|
+
],
|
|
711
|
+
columnTypes: { Name: 'string', Data: 'dynamic' },
|
|
712
|
+
});
|
|
713
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
714
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
715
|
+
expect(container.textContent).toContain('nested');
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
it('renders detail panel with null/undefined values', () => {
|
|
719
|
+
renderWithVirtualRows({
|
|
720
|
+
columns: ['Name', 'Empty'],
|
|
721
|
+
rows: [
|
|
722
|
+
{ Name: 'alpha', Empty: null },
|
|
723
|
+
],
|
|
724
|
+
columnTypes: { Name: 'string', Empty: 'string' },
|
|
725
|
+
});
|
|
726
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
727
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
728
|
+
expect(container.textContent).toContain('Row 1');
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it('renders detail panel in list mode with object values', () => {
|
|
732
|
+
renderWithVirtualRows({
|
|
733
|
+
columns: ['Name', 'Data'],
|
|
734
|
+
rows: [
|
|
735
|
+
{ Name: 'alpha', Data: { x: 1 } },
|
|
736
|
+
],
|
|
737
|
+
columnTypes: { Name: 'string', Data: 'dynamic' },
|
|
738
|
+
});
|
|
739
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
740
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
741
|
+
// Switch to list mode
|
|
742
|
+
const detailHeaderBtns = Array.from(container.querySelectorAll('[class="detailHeaderLeft"] button'));
|
|
743
|
+
if (detailHeaderBtns.length >= 2) {
|
|
744
|
+
act(() => { (detailHeaderBtns[1] as HTMLElement).click(); });
|
|
745
|
+
}
|
|
746
|
+
expect(container.innerHTML).toBeTruthy();
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
it('renders detail panel in json mode', () => {
|
|
750
|
+
renderWithVirtualRows({
|
|
751
|
+
isDark: true,
|
|
752
|
+
});
|
|
753
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
754
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
755
|
+
const detailHeaderBtns = Array.from(container.querySelectorAll('[class="detailHeaderLeft"] button'));
|
|
756
|
+
if (detailHeaderBtns.length >= 3) {
|
|
757
|
+
act(() => { (detailHeaderBtns[2] as HTMLElement).click(); });
|
|
758
|
+
}
|
|
759
|
+
expect(container.innerHTML).toBeTruthy();
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
it('handles detail panel drag resize', () => {
|
|
763
|
+
renderWithVirtualRows();
|
|
764
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
765
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
766
|
+
const dragHandle = container.querySelector('[class="detailDragHandle"]');
|
|
767
|
+
expect(dragHandle).toBeTruthy();
|
|
768
|
+
// Simulate drag start
|
|
769
|
+
act(() => {
|
|
770
|
+
dragHandle!.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: 400 }));
|
|
771
|
+
});
|
|
772
|
+
// Simulate drag move
|
|
773
|
+
act(() => {
|
|
774
|
+
document.dispatchEvent(new MouseEvent('mousemove', { clientX: 350 }));
|
|
775
|
+
});
|
|
776
|
+
// Simulate drag end
|
|
777
|
+
act(() => {
|
|
778
|
+
document.dispatchEvent(new MouseEvent('mouseup'));
|
|
779
|
+
});
|
|
780
|
+
expect(container.innerHTML).toBeTruthy();
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
it('renders cells with null, undefined, and number values', () => {
|
|
784
|
+
renderWithVirtualRows({
|
|
785
|
+
columns: ['A', 'B', 'C'],
|
|
786
|
+
rows: [
|
|
787
|
+
{ A: null, B: undefined, C: 42 },
|
|
788
|
+
],
|
|
789
|
+
columnTypes: { A: 'string', B: 'string', C: 'long' },
|
|
790
|
+
});
|
|
791
|
+
const cells = container.querySelectorAll('[class="td"]');
|
|
792
|
+
expect(cells.length).toBe(3);
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
it('renders with colType undefined (no type annotation)', () => {
|
|
796
|
+
renderWithVirtualRows({
|
|
797
|
+
columns: ['Name'],
|
|
798
|
+
rows: [{ Name: 'test' }],
|
|
799
|
+
columnTypes: undefined,
|
|
800
|
+
});
|
|
801
|
+
const headerBtns = container.querySelectorAll('button[class="th"]');
|
|
802
|
+
expect(headerBtns.length).toBe(1);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it('highlights matching rows when parsedHighlight is set', () => {
|
|
806
|
+
mockedParseHighlightExpr.mockReturnValue({ column: 'Name', op: '==', value: 'alpha' });
|
|
807
|
+
mockedMatchesHighlight.mockReturnValue(true);
|
|
808
|
+
renderWithVirtualRows();
|
|
809
|
+
// Rows should have highlight class
|
|
810
|
+
const highlightedRows = container.querySelectorAll('[class="trExprHighlight"]');
|
|
811
|
+
expect(highlightedRows.length).toBe(2);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it('shows highlight expr in status bar when parsedHighlight is set', () => {
|
|
815
|
+
mockedParseHighlightExpr.mockReturnValue({ column: 'Name', op: '==', value: 'alpha' });
|
|
816
|
+
renderWithVirtualRows();
|
|
817
|
+
expect(container.textContent).toContain('Highlighting');
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it('shows selection stats in status bar with aggregates', () => {
|
|
821
|
+
mockedComputeAggregates.mockReturnValue({ sum: '3', avg: '1.5', min: '1', max: '2' });
|
|
822
|
+
mockedComputeDateDelta.mockReturnValue('2 days');
|
|
823
|
+
mockedIsCellInRange.mockReturnValue(true);
|
|
824
|
+
renderWithVirtualRows();
|
|
825
|
+
const cells = container.querySelectorAll('[class="td"]');
|
|
826
|
+
// Select from first cell
|
|
827
|
+
act(() => {
|
|
828
|
+
cells[0].dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
829
|
+
});
|
|
830
|
+
// Extend to last cell with shift
|
|
831
|
+
act(() => {
|
|
832
|
+
cells[cells.length - 1].dispatchEvent(new MouseEvent('mousedown', { bubbles: true, shiftKey: true }));
|
|
833
|
+
});
|
|
834
|
+
// Status bar should contain aggregate info
|
|
835
|
+
expect(container.textContent).toContain('Selected');
|
|
836
|
+
expect(container.textContent).toContain('cells');
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
it('renders selected cells with tdSelected class', () => {
|
|
840
|
+
mockedIsCellInRange.mockReturnValue(true);
|
|
841
|
+
renderWithVirtualRows();
|
|
842
|
+
// Start a selection
|
|
843
|
+
const cells = container.querySelectorAll('[class="td"], [class="tdSelected"]');
|
|
844
|
+
act(() => {
|
|
845
|
+
cells[0].dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
846
|
+
});
|
|
847
|
+
// After re-render, cells should have tdSelected
|
|
848
|
+
const selectedCells = container.querySelectorAll('[class="tdSelected"]');
|
|
849
|
+
expect(selectedCells.length).toBeGreaterThan(0);
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
it('renders detail row open with trDetailOpen class', () => {
|
|
853
|
+
renderWithVirtualRows();
|
|
854
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
855
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
856
|
+
const detailOpenRow = container.querySelector('[class="trDetailOpen"]');
|
|
857
|
+
expect(detailOpenRow).toBeTruthy();
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
it('does not add scrollbar style element twice', () => {
|
|
861
|
+
// Render once to inject style
|
|
862
|
+
act(() => {
|
|
863
|
+
root.render(React.createElement(ResultsTable, {
|
|
864
|
+
columns: ['Name'],
|
|
865
|
+
rows: [{ Name: 'test' }],
|
|
866
|
+
}));
|
|
867
|
+
});
|
|
868
|
+
const stylesBefore = document.querySelectorAll('#traverse-scrollbar-style').length;
|
|
869
|
+
// Render again — should not add another style element
|
|
870
|
+
act(() => {
|
|
871
|
+
root.render(React.createElement(ResultsTable, {
|
|
872
|
+
columns: ['Name'],
|
|
873
|
+
rows: [{ Name: 'test2' }],
|
|
874
|
+
}));
|
|
875
|
+
});
|
|
876
|
+
const stylesAfter = document.querySelectorAll('#traverse-scrollbar-style').length;
|
|
877
|
+
expect(stylesAfter).toBe(stylesBefore);
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
it('handles detailRowIdx beyond sorted rows length', () => {
|
|
881
|
+
renderWithVirtualRows({
|
|
882
|
+
columns: ['Name'],
|
|
883
|
+
rows: [{ Name: 'alpha' }],
|
|
884
|
+
});
|
|
885
|
+
// This tests the `detailRowIdx >= sortedRows.length` branch
|
|
886
|
+
// by opening detail, then rendering with fewer rows
|
|
887
|
+
const expandBtns = container.querySelectorAll('button[class="expandBtn"]');
|
|
888
|
+
act(() => { (expandBtns[0] as HTMLElement).click(); });
|
|
889
|
+
// Now re-render with empty rows (detail idx will be out of bounds)
|
|
890
|
+
mockUseVirtualizer.mockReturnValue({
|
|
891
|
+
getVirtualItems: () => [],
|
|
892
|
+
getTotalSize: () => 0,
|
|
893
|
+
measureElement: vi.fn(),
|
|
894
|
+
});
|
|
895
|
+
act(() => {
|
|
896
|
+
root.render(React.createElement(ResultsTable, {
|
|
897
|
+
columns: ['Name'],
|
|
898
|
+
rows: [],
|
|
899
|
+
}));
|
|
900
|
+
});
|
|
901
|
+
// Detail panel should not be visible
|
|
902
|
+
const detailPanel = container.querySelector('[class="detailPanel"]');
|
|
903
|
+
expect(detailPanel).toBeNull();
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
it('renders ColumnPickerItem with empty column label', () => {
|
|
907
|
+
mockedFindEmptyColumns.mockReturnValue(new Set(['EmptyCol']));
|
|
908
|
+
renderWithVirtualRows({
|
|
909
|
+
columns: ['Name', 'EmptyCol'],
|
|
910
|
+
rows: [{ Name: 'alpha', EmptyCol: null }],
|
|
911
|
+
columnTypes: { Name: 'string', EmptyCol: 'string' },
|
|
912
|
+
});
|
|
913
|
+
// The column picker checkbox for EmptyCol should show '(empty)'
|
|
914
|
+
const checkboxes = container.querySelectorAll('input[type="checkbox"]');
|
|
915
|
+
expect(checkboxes.length).toBe(2);
|
|
916
|
+
// Check that label includes '(empty)' text
|
|
917
|
+
expect(container.textContent).toContain('(empty)');
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
it('handles selection stats with single cell (no stats shown)', () => {
|
|
921
|
+
renderWithVirtualRows();
|
|
922
|
+
const cells = container.querySelectorAll('[class="td"]');
|
|
923
|
+
// Click single cell
|
|
924
|
+
act(() => {
|
|
925
|
+
cells[0].dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
926
|
+
});
|
|
927
|
+
// Single cell: cellCount < 2, selectionStats returns null
|
|
928
|
+
expect(container.textContent).not.toContain('Selected');
|
|
929
|
+
});
|
|
930
|
+
});
|