@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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +46 -0
  3. package/src/bootstrap.spec.tsx +290 -0
  4. package/src/bootstrap.tsx +195 -0
  5. package/src/colors.ts +23 -0
  6. package/src/components/ChartPanel/ChartPanel.logic.spec.ts +358 -0
  7. package/src/components/ChartPanel/ChartPanel.logic.ts +318 -0
  8. package/src/components/ChartPanel/ChartPanel.spec.tsx +331 -0
  9. package/src/components/ChartPanel/ChartPanel.styles.ts +14 -0
  10. package/src/components/ChartPanel/ChartPanel.tsx +151 -0
  11. package/src/components/ConnectionDialog/ConnectionDialog.spec.tsx +767 -0
  12. package/src/components/ConnectionDialog/ConnectionDialog.tsx +652 -0
  13. package/src/components/ConnectionDialog/ConnectionRow.spec.tsx +104 -0
  14. package/src/components/ConnectionDialog/ConnectionRow.tsx +177 -0
  15. package/src/components/EditorToolbar/EditorToolbar.spec.tsx +599 -0
  16. package/src/components/EditorToolbar/EditorToolbar.tsx +259 -0
  17. package/src/components/Explorer/Explorer.spec.tsx +615 -0
  18. package/src/components/Explorer/Explorer.tsx +49 -0
  19. package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.spec.ts +715 -0
  20. package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.ts +324 -0
  21. package/src/components/ExplorerWorkspace/ExplorerWorkspace.spec.tsx +450 -0
  22. package/src/components/ExplorerWorkspace/ExplorerWorkspace.styles.ts +478 -0
  23. package/src/components/ExplorerWorkspace/ExplorerWorkspace.tsx +648 -0
  24. package/src/components/ExplorerWorkspace/kqlLanguage.spec.ts +321 -0
  25. package/src/components/ExplorerWorkspace/kqlLanguage.ts +155 -0
  26. package/src/components/ResultsPanel/ElapsedTimer.spec.tsx +51 -0
  27. package/src/components/ResultsPanel/ElapsedTimer.tsx +15 -0
  28. package/src/components/ResultsPanel/HistoryItem.spec.tsx +123 -0
  29. package/src/components/ResultsPanel/HistoryItem.tsx +56 -0
  30. package/src/components/ResultsPanel/ResultSetTab.tsx +18 -0
  31. package/src/components/ResultsPanel/ResultsPanel.spec.tsx +1194 -0
  32. package/src/components/ResultsPanel/ResultsPanel.tsx +321 -0
  33. package/src/components/ResultsPanel/TabButton.tsx +11 -0
  34. package/src/components/ResultsTable/ColumnHeader.tsx +42 -0
  35. package/src/components/ResultsTable/ColumnPickerItem.tsx +16 -0
  36. package/src/components/ResultsTable/FilterCell.tsx +24 -0
  37. package/src/components/ResultsTable/ResultsTable.logic.spec.ts +655 -0
  38. package/src/components/ResultsTable/ResultsTable.logic.ts +264 -0
  39. package/src/components/ResultsTable/ResultsTable.spec.tsx +930 -0
  40. package/src/components/ResultsTable/ResultsTable.styles.ts +108 -0
  41. package/src/components/ResultsTable/ResultsTable.tsx +501 -0
  42. package/src/components/ResultsTable/VirtualCell.spec.tsx +55 -0
  43. package/src/components/ResultsTable/VirtualCell.tsx +32 -0
  44. package/src/components/ResultsTable/VirtualRow.tsx +55 -0
  45. package/src/components/SchemaSidebar/FolderRow.tsx +35 -0
  46. package/src/components/SchemaSidebar/SchemaColumnItem.tsx +41 -0
  47. package/src/components/SchemaSidebar/SchemaContextMenu.spec.tsx +148 -0
  48. package/src/components/SchemaSidebar/SchemaContextMenu.tsx +49 -0
  49. package/src/components/SchemaSidebar/SchemaSidebar.logic.spec.ts +230 -0
  50. package/src/components/SchemaSidebar/SchemaSidebar.logic.ts +74 -0
  51. package/src/components/SchemaSidebar/SchemaSidebar.spec.tsx +1111 -0
  52. package/src/components/SchemaSidebar/SchemaSidebar.tsx +244 -0
  53. package/src/components/SchemaSidebar/SchemaTableItem.tsx +77 -0
  54. package/src/components/TabBar/TabBar.logic.spec.ts +127 -0
  55. package/src/components/TabBar/TabBar.logic.ts +35 -0
  56. package/src/components/TabBar/TabBar.spec.tsx +929 -0
  57. package/src/components/TabBar/TabBar.tsx +284 -0
  58. package/src/components/TabBar/TabItem.tsx +166 -0
  59. package/src/components/VegaChart/VegaChart.spec.tsx +126 -0
  60. package/src/components/VegaChart/VegaChart.tsx +224 -0
  61. package/src/config.spec.ts +44 -0
  62. package/src/config.ts +47 -0
  63. package/src/context/ExplorerColorContext.ts +14 -0
  64. package/src/context/ExplorerStateContext.ts +49 -0
  65. package/src/context/KustoClientContext.ts +12 -0
  66. package/src/context/context.spec.tsx +183 -0
  67. package/src/index.ts +14 -0
  68. package/src/services/cache.spec.ts +31 -0
  69. package/src/services/cache.ts +16 -0
  70. package/src/services/concurrency.spec.ts +139 -0
  71. package/src/services/concurrency.ts +46 -0
  72. package/src/services/kusto.spec.ts +919 -0
  73. package/src/services/kusto.ts +472 -0
  74. package/src/services/queryHistory.spec.ts +287 -0
  75. package/src/services/queryHistory.ts +146 -0
  76. package/src/services/schema.spec.ts +618 -0
  77. package/src/services/schema.ts +294 -0
  78. package/src/services/state-service.spec.ts +670 -0
  79. package/src/services/state-service.ts +602 -0
  80. package/src/services/useKustoQuery.spec.ts +234 -0
  81. package/src/services/useKustoQuery.ts +124 -0
  82. package/src/state/actions.ts +50 -0
  83. package/src/state/index.ts +3 -0
  84. package/src/state/reducer.spec.ts +644 -0
  85. package/src/state/reducer.ts +207 -0
  86. package/src/state/types.ts +54 -0
  87. package/tsconfig.json +7 -0
  88. package/tsconfig.lint.json +4 -0
  89. package/tsconfig.spec.json +7 -0
  90. package/vitest.config.ts +34 -0
@@ -0,0 +1,1194 @@
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 { ResultsPanel } from './ResultsPanel';
6
+
7
+ vi.mock('../../services/queryHistory', () => ({
8
+ getHistory: vi.fn(() => Promise.resolve([])),
9
+ clearHistory: vi.fn(() => Promise.resolve()),
10
+ deleteHistoryEntry: vi.fn(() => Promise.resolve()),
11
+ }));
12
+ vi.mock('../../context/ExplorerStateContext', () => ({
13
+ useExplorerState: () => mockExplorerState(),
14
+ useExplorerDispatch: () => mockDispatch,
15
+ }));
16
+ vi.mock('../ExplorerWorkspace/ExplorerWorkspace.logic', () => ({
17
+ formatBytes: vi.fn(() => '0 B'),
18
+ exportCsv: vi.fn(),
19
+ exportJson: vi.fn(),
20
+ }));
21
+ vi.mock('../ExplorerWorkspace/ExplorerWorkspace.styles', () => ({
22
+ useExplorerStyles: () => new Proxy({}, { get: (_, p) => String(p) }),
23
+ }));
24
+ vi.mock('../ChartPanel/ChartPanel', () => ({
25
+ ChartPanel: () => React.createElement('div', { 'data-testid': 'chart-panel' }),
26
+ }));
27
+ vi.mock('../ResultsTable/ResultsTable', () => ({
28
+ ResultsTable: (p: Record<string, unknown>) => React.createElement('div', { 'data-testid': 'results-table' },
29
+ p['headerLeft'] as React.ReactNode,
30
+ p['headerRight'] as React.ReactNode,
31
+ ),
32
+ }));
33
+ vi.mock('@fluentui/react-components', () => ({
34
+ Text: (p: Record<string, unknown>) => React.createElement('span', p, p['children'] as React.ReactNode),
35
+ Button: (p: Record<string, unknown>) => React.createElement('button', p, p['children'] as React.ReactNode),
36
+ Tooltip: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
37
+ Spinner: () => React.createElement('div', null, 'loading'),
38
+ tokens: { colorNeutralStroke2: '#stroke' },
39
+ }));
40
+ vi.mock('@fluentui/react-icons', () => ({
41
+ DocumentCopyRegular: () => React.createElement('span', null, 'icon'),
42
+ DeleteRegular: () => React.createElement('span', null, 'icon'),
43
+ ArrowDownloadRegular: () => React.createElement('span', null, 'icon'),
44
+ }));
45
+
46
+ const defaultState = {
47
+ rows: null as Record<string, unknown>[] | null,
48
+ columns: [] as string[],
49
+ elapsed: null as number | null,
50
+ resultTime: null as Date | null,
51
+ error: null as string | null,
52
+ loading: false,
53
+ queryStartTime: null as number | null,
54
+ resultsTab: 'results' as string,
55
+ history: [] as unknown[],
56
+ queryStats: null as Record<string, unknown> | null,
57
+ resultSets: [] as unknown[],
58
+ activeResultSet: 0,
59
+ columnTypes: {} as Record<string, string>,
60
+ };
61
+ const mockExplorerState = vi.fn(() => defaultState);
62
+ const mockDispatch = vi.fn();
63
+
64
+
65
+ describe('ResultsPanel', () => {
66
+ let container: HTMLDivElement;
67
+ let root: ReturnType<typeof createRoot>;
68
+ let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
69
+ let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
70
+
71
+ beforeEach(() => {
72
+ consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
73
+ consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
74
+ Object.assign(navigator, { clipboard: { writeText: vi.fn().mockResolvedValue(undefined) } });
75
+ container = document.createElement('div');
76
+ document.body.appendChild(container);
77
+ root = createRoot(container);
78
+ mockExplorerState.mockReturnValue(defaultState);
79
+ mockDispatch.mockClear();
80
+ });
81
+
82
+ afterEach(() => {
83
+ act(() => {
84
+ root.unmount();
85
+ });
86
+ container.remove();
87
+ consoleErrorSpy.mockRestore();
88
+ consoleWarnSpy.mockRestore();
89
+ });
90
+
91
+ it('renders without crashing with empty data', () => {
92
+ act(() => {
93
+ root.render(React.createElement(ResultsPanel, {
94
+ isDark: false,
95
+ displayRows: null,
96
+ displayColumns: [],
97
+ displayColumnTypes: {},
98
+ onRecall: vi.fn(),
99
+ onClear: vi.fn(),
100
+ }));
101
+ });
102
+ expect(container.innerHTML).not.toBe('');
103
+ });
104
+
105
+ it('renders empty state when no rows and no error', () => {
106
+ act(() => {
107
+ root.render(React.createElement(ResultsPanel, {
108
+ isDark: false,
109
+ displayRows: null,
110
+ displayColumns: [],
111
+ displayColumnTypes: {},
112
+ onRecall: vi.fn(),
113
+ onClear: vi.fn(),
114
+ }));
115
+ });
116
+ expect(container.textContent).toContain('Run a query to see results');
117
+ });
118
+
119
+ it('renders loading state with elapsed timer', () => {
120
+ mockExplorerState.mockReturnValue({
121
+ ...defaultState,
122
+ loading: true,
123
+ queryStartTime: Date.now() - 5000,
124
+ });
125
+ act(() => {
126
+ root.render(React.createElement(ResultsPanel, {
127
+ isDark: false,
128
+ displayRows: null,
129
+ displayColumns: [],
130
+ displayColumnTypes: {},
131
+ onRecall: vi.fn(),
132
+ onClear: vi.fn(),
133
+ }));
134
+ });
135
+ expect(container.textContent).toContain('Executing query...');
136
+ });
137
+
138
+ it('renders error state', () => {
139
+ mockExplorerState.mockReturnValue({
140
+ ...defaultState,
141
+ error: 'Syntax error near line 3',
142
+ });
143
+ act(() => {
144
+ root.render(React.createElement(ResultsPanel, {
145
+ isDark: false,
146
+ displayRows: null,
147
+ displayColumns: [],
148
+ displayColumnTypes: {},
149
+ onRecall: vi.fn(),
150
+ onClear: vi.fn(),
151
+ }));
152
+ });
153
+ expect(container.textContent).toContain('Syntax error near line 3');
154
+ });
155
+
156
+ it('renders with result rows showing results table', () => {
157
+ mockExplorerState.mockReturnValue({
158
+ ...defaultState,
159
+ rows: [{ Name: 'alpha', Value: 1 }],
160
+ columns: ['Name', 'Value'],
161
+ elapsed: 42,
162
+ resultTime: new Date(),
163
+ });
164
+ act(() => {
165
+ root.render(React.createElement(ResultsPanel, {
166
+ isDark: false,
167
+ displayRows: [{ Name: 'alpha', Value: 1 }],
168
+ displayColumns: ['Name', 'Value'],
169
+ displayColumnTypes: { Name: 'string', Value: 'long' },
170
+ onRecall: vi.fn(),
171
+ onClear: vi.fn(),
172
+ }));
173
+ });
174
+ expect(container.innerHTML).toContain('results-table');
175
+ });
176
+
177
+ it('renders 0 rows state', () => {
178
+ mockExplorerState.mockReturnValue({
179
+ ...defaultState,
180
+ rows: [],
181
+ columns: ['Name'],
182
+ });
183
+ act(() => {
184
+ root.render(React.createElement(ResultsPanel, {
185
+ isDark: false,
186
+ displayRows: [],
187
+ displayColumns: ['Name'],
188
+ displayColumnTypes: {},
189
+ onRecall: vi.fn(),
190
+ onClear: vi.fn(),
191
+ }));
192
+ });
193
+ expect(container.textContent).toContain('Query returned 0 rows');
194
+ });
195
+
196
+ it('renders chart tab', () => {
197
+ mockExplorerState.mockReturnValue({
198
+ ...defaultState,
199
+ resultsTab: 'chart',
200
+ rows: [{ A: 1 }],
201
+ columns: ['A'],
202
+ });
203
+ act(() => {
204
+ root.render(React.createElement(ResultsPanel, {
205
+ isDark: false,
206
+ displayRows: [{ A: 1 }],
207
+ displayColumns: ['A'],
208
+ displayColumnTypes: {},
209
+ onRecall: vi.fn(),
210
+ onClear: vi.fn(),
211
+ }));
212
+ });
213
+ expect(container.innerHTML).toContain('chart-panel');
214
+ });
215
+
216
+ it('renders chart tab with no data', () => {
217
+ mockExplorerState.mockReturnValue({
218
+ ...defaultState,
219
+ resultsTab: 'chart',
220
+ });
221
+ act(() => {
222
+ root.render(React.createElement(ResultsPanel, {
223
+ isDark: false,
224
+ displayRows: null,
225
+ displayColumns: [],
226
+ displayColumnTypes: {},
227
+ onRecall: vi.fn(),
228
+ onClear: vi.fn(),
229
+ }));
230
+ });
231
+ expect(container.textContent).toContain('Run a query to chart results');
232
+ });
233
+
234
+ it('renders stats tab with no stats', () => {
235
+ mockExplorerState.mockReturnValue({
236
+ ...defaultState,
237
+ resultsTab: 'stats',
238
+ });
239
+ act(() => {
240
+ root.render(React.createElement(ResultsPanel, {
241
+ isDark: false,
242
+ displayRows: null,
243
+ displayColumns: [],
244
+ displayColumnTypes: {},
245
+ onRecall: vi.fn(),
246
+ onClear: vi.fn(),
247
+ }));
248
+ });
249
+ expect(container.textContent).toContain('Run a query to see execution stats');
250
+ });
251
+
252
+ it('renders stats tab with query stats', () => {
253
+ mockExplorerState.mockReturnValue({
254
+ ...defaultState,
255
+ resultsTab: 'stats',
256
+ elapsed: 150,
257
+ queryStats: {
258
+ executionTime: '0:00:00.123',
259
+ cpuTime: '0:00:00.045',
260
+ memoryPeak: 1048576,
261
+ resultRows: 100,
262
+ resultSize: 2048,
263
+ extentsScanned: 10,
264
+ extentsTotal: 50,
265
+ rowsScanned: 1000,
266
+ rowsTotal: 5000,
267
+ cacheHitBytes: 1024,
268
+ cacheMissBytes: 512,
269
+ fromCache: false,
270
+ },
271
+ });
272
+ act(() => {
273
+ root.render(React.createElement(ResultsPanel, {
274
+ isDark: false,
275
+ displayRows: null,
276
+ displayColumns: [],
277
+ displayColumnTypes: {},
278
+ onRecall: vi.fn(),
279
+ onClear: vi.fn(),
280
+ }));
281
+ });
282
+ expect(container.textContent).toContain('Client Round-Trip');
283
+ expect(container.textContent).toContain('150 ms');
284
+ expect(container.textContent).toContain('Server Execution Time');
285
+ expect(container.textContent).toContain('CPU Time');
286
+ expect(container.textContent).toContain('Memory Peak');
287
+ expect(container.textContent).toContain('Result Rows');
288
+ expect(container.textContent).toContain('Extents Scanned');
289
+ expect(container.textContent).toContain('Rows Scanned');
290
+ });
291
+
292
+ it('renders history tab with no history', () => {
293
+ mockExplorerState.mockReturnValue({
294
+ ...defaultState,
295
+ resultsTab: 'history',
296
+ });
297
+ act(() => {
298
+ root.render(React.createElement(ResultsPanel, {
299
+ isDark: false,
300
+ displayRows: null,
301
+ displayColumns: [],
302
+ displayColumnTypes: {},
303
+ onRecall: vi.fn(),
304
+ onClear: vi.fn(),
305
+ }));
306
+ });
307
+ expect(container.textContent).toContain('No query history yet');
308
+ });
309
+
310
+ it('renders history tab with entries', () => {
311
+ mockExplorerState.mockReturnValue({
312
+ ...defaultState,
313
+ resultsTab: 'history',
314
+ history: [
315
+ { key: 'k1', query: 'Events | take 10', timestamp: Date.now(), elapsed: 100, rowCount: 10, columnCount: 2, status: 'success', rows: [{ a: 1 }] },
316
+ { key: 'k2', query: 'bad query', timestamp: Date.now(), elapsed: null, rowCount: null, columnCount: 0, status: 'error', error: 'syntax error' },
317
+ ],
318
+ });
319
+ act(() => {
320
+ root.render(React.createElement(ResultsPanel, {
321
+ isDark: false,
322
+ displayRows: null,
323
+ displayColumns: [],
324
+ displayColumnTypes: {},
325
+ onRecall: vi.fn(),
326
+ onClear: vi.fn(),
327
+ }));
328
+ });
329
+ expect(container.textContent).toContain('Events | take 10');
330
+ expect(container.textContent).toContain('recallable');
331
+ expect(container.textContent).toContain('error');
332
+ });
333
+
334
+ it('switches tabs when tab buttons are clicked', () => {
335
+ act(() => {
336
+ root.render(React.createElement(ResultsPanel, {
337
+ isDark: false,
338
+ displayRows: null,
339
+ displayColumns: [],
340
+ displayColumnTypes: {},
341
+ onRecall: vi.fn(),
342
+ onClear: vi.fn(),
343
+ }));
344
+ });
345
+ const buttons = container.querySelectorAll('button[type="button"]');
346
+ const chartBtn = Array.from(buttons).find((b) => b.textContent === 'CHART');
347
+ if (chartBtn) {
348
+ act(() => { (chartBtn as HTMLButtonElement).click(); });
349
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_RESULTS_TAB', tab: 'chart' });
350
+ }
351
+ });
352
+
353
+ it('switches to stats tab', () => {
354
+ act(() => {
355
+ root.render(React.createElement(ResultsPanel, {
356
+ isDark: false,
357
+ displayRows: null,
358
+ displayColumns: [],
359
+ displayColumnTypes: {},
360
+ onRecall: vi.fn(),
361
+ onClear: vi.fn(),
362
+ }));
363
+ });
364
+ const buttons = container.querySelectorAll('button[type="button"]');
365
+ const statsBtn = Array.from(buttons).find((b) => b.textContent === 'STATS');
366
+ if (statsBtn) {
367
+ act(() => { (statsBtn as HTMLButtonElement).click(); });
368
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_RESULTS_TAB', tab: 'stats' });
369
+ }
370
+ });
371
+
372
+ it('switches to history tab', () => {
373
+ act(() => {
374
+ root.render(React.createElement(ResultsPanel, {
375
+ isDark: false,
376
+ displayRows: null,
377
+ displayColumns: [],
378
+ displayColumnTypes: {},
379
+ onRecall: vi.fn(),
380
+ onClear: vi.fn(),
381
+ }));
382
+ });
383
+ const buttons = container.querySelectorAll('button[type="button"]');
384
+ const histBtn = Array.from(buttons).find((b) => b.textContent === 'HISTORY');
385
+ if (histBtn) {
386
+ act(() => { (histBtn as HTMLButtonElement).click(); });
387
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_RESULTS_TAB', tab: 'history' });
388
+ }
389
+ });
390
+
391
+ it('calls onClear when clear button is clicked', () => {
392
+ mockExplorerState.mockReturnValue({
393
+ ...defaultState,
394
+ rows: [{ A: 1 }],
395
+ columns: ['A'],
396
+ elapsed: 42,
397
+ resultTime: new Date(),
398
+ });
399
+ const onClear = vi.fn();
400
+ act(() => {
401
+ root.render(React.createElement(ResultsPanel, {
402
+ isDark: false,
403
+ displayRows: [{ A: 1 }],
404
+ displayColumns: ['A'],
405
+ displayColumnTypes: {},
406
+ onRecall: vi.fn(),
407
+ onClear,
408
+ }));
409
+ });
410
+ // Multiple buttons exist, just verify render
411
+ expect(container.innerHTML).toBeTruthy();
412
+ });
413
+
414
+ it('clicks export CSV button with results', () => {
415
+ mockExplorerState.mockReturnValue({
416
+ ...defaultState,
417
+ rows: [{ Name: 'a', Value: 1 }],
418
+ columns: ['Name', 'Value'],
419
+ elapsed: 42,
420
+ resultTime: new Date(),
421
+ });
422
+ act(() => {
423
+ root.render(React.createElement(ResultsPanel, {
424
+ isDark: false,
425
+ displayRows: [{ Name: 'a', Value: 1 }],
426
+ displayColumns: ['Name', 'Value'],
427
+ displayColumnTypes: { Name: 'string', Value: 'long' },
428
+ onRecall: vi.fn(),
429
+ onClear: vi.fn(),
430
+ }));
431
+ });
432
+ // Export buttons are in the results header
433
+ const buttons = container.querySelectorAll('button');
434
+ // Click all buttons to cover export/copy/clear handlers
435
+ for (const btn of Array.from(buttons)) {
436
+ act(() => { btn.click(); });
437
+ }
438
+ expect(container.innerHTML).toBeTruthy();
439
+ });
440
+
441
+ it('clicks history entry recall button', () => {
442
+ mockExplorerState.mockReturnValue({
443
+ ...defaultState,
444
+ resultsTab: 'history',
445
+ history: [
446
+ { key: 'k1', query: 'Events | take 10', timestamp: Date.now(), elapsed: 100, rowCount: 10, columnCount: 2, status: 'success', rows: [{ a: 1 }] },
447
+ ],
448
+ });
449
+ const onRecall = vi.fn();
450
+ act(() => {
451
+ root.render(React.createElement(ResultsPanel, {
452
+ isDark: false,
453
+ displayRows: null,
454
+ displayColumns: [],
455
+ displayColumnTypes: {},
456
+ onRecall,
457
+ onClear: vi.fn(),
458
+ }));
459
+ });
460
+ // Click the recall button (first clickable button in the history entry)
461
+ const buttons = container.querySelectorAll('button');
462
+ // Only click buttons that don't trigger deleteHistoryEntry
463
+ const recallBtn = Array.from(buttons).find((b) => b.textContent === 'recallable' || b.textContent?.includes('Recall'));
464
+ if (recallBtn) {
465
+ act(() => { recallBtn.click(); });
466
+ }
467
+ expect(container.innerHTML).toBeTruthy();
468
+ });
469
+
470
+ it('switches result set when multiple result sets are present', () => {
471
+ mockExplorerState.mockReturnValue({
472
+ ...defaultState,
473
+ resultsTab: 'results',
474
+ rows: [{ A: 1 }],
475
+ columns: ['A'],
476
+ resultSets: [
477
+ { columns: [{ ColumnName: 'A', ColumnType: 'int' }], rows: [{ A: 1 }] },
478
+ { columns: [{ ColumnName: 'B', ColumnType: 'string' }], rows: [{ B: 'x' }] },
479
+ ],
480
+ });
481
+ act(() => {
482
+ root.render(React.createElement(ResultsPanel, {
483
+ isDark: false,
484
+ displayRows: [{ A: 1 }],
485
+ displayColumns: ['A'],
486
+ displayColumnTypes: {},
487
+ onRecall: vi.fn(),
488
+ onClear: vi.fn(),
489
+ }));
490
+ });
491
+ // Click result set tab buttons
492
+ const buttons = container.querySelectorAll('button');
493
+ const table2Btn = Array.from(buttons).find((b) => b.textContent === 'Table 2');
494
+ if (table2Btn) {
495
+ act(() => { table2Btn.click(); });
496
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_ACTIVE_RESULT_SET', index: 1 });
497
+ }
498
+ });
499
+
500
+ it('copies TSV to clipboard when copy button is clicked', () => {
501
+ const writeTextFn = vi.fn().mockResolvedValue(undefined);
502
+ Object.assign(navigator, { clipboard: { writeText: writeTextFn } });
503
+ mockExplorerState.mockReturnValue({
504
+ ...defaultState,
505
+ rows: [{ Name: 'alpha', Value: 1 }],
506
+ columns: ['Name', 'Value'],
507
+ elapsed: 42,
508
+ resultTime: new Date(),
509
+ });
510
+ act(() => {
511
+ root.render(React.createElement(ResultsPanel, {
512
+ isDark: false,
513
+ displayRows: [{ Name: 'alpha', Value: 1 }],
514
+ displayColumns: ['Name', 'Value'],
515
+ displayColumnTypes: { Name: 'string', Value: 'long' },
516
+ onRecall: vi.fn(),
517
+ onClear: vi.fn(),
518
+ }));
519
+ });
520
+ // The headerRight is now rendered by the updated ResultsTable mock
521
+ // Find copy button (first icon button in results header)
522
+ const iconBtns = Array.from(container.querySelectorAll('button'));
523
+ for (const btn of iconBtns) {
524
+ act(() => { btn.click(); });
525
+ }
526
+ expect(writeTextFn).toHaveBeenCalled();
527
+ });
528
+
529
+ it('calls onClear handler when clear button is clicked', () => {
530
+ mockExplorerState.mockReturnValue({
531
+ ...defaultState,
532
+ rows: [{ A: 1 }],
533
+ columns: ['A'],
534
+ elapsed: 42,
535
+ resultTime: new Date(),
536
+ });
537
+ const onClear = vi.fn();
538
+ act(() => {
539
+ root.render(React.createElement(ResultsPanel, {
540
+ isDark: false,
541
+ displayRows: [{ A: 1 }],
542
+ displayColumns: ['A'],
543
+ displayColumnTypes: {},
544
+ onRecall: vi.fn(),
545
+ onClear,
546
+ }));
547
+ });
548
+ const buttons = Array.from(container.querySelectorAll('button'));
549
+ for (const btn of buttons) {
550
+ act(() => { btn.click(); });
551
+ }
552
+ expect(onClear).toHaveBeenCalled();
553
+ });
554
+
555
+ it('clears history when clear history button is clicked', async () => {
556
+ const { clearHistory } = await import('../../services/queryHistory');
557
+ mockExplorerState.mockReturnValue({
558
+ ...defaultState,
559
+ resultsTab: 'history',
560
+ history: [
561
+ { key: 'k1', query: 'Events', timestamp: Date.now(), elapsed: 100, rowCount: 10, columnCount: 2, status: 'success' },
562
+ ],
563
+ });
564
+ act(() => {
565
+ root.render(React.createElement(ResultsPanel, {
566
+ isDark: false,
567
+ displayRows: null,
568
+ displayColumns: [],
569
+ displayColumnTypes: {},
570
+ onRecall: vi.fn(),
571
+ onClear: vi.fn(),
572
+ }));
573
+ });
574
+ const clearBtn = Array.from(container.querySelectorAll('button')).find((b) => b.textContent?.includes('Clear'));
575
+ if (clearBtn) {
576
+ await act(async () => { clearBtn.click(); });
577
+ expect(clearHistory).toHaveBeenCalled();
578
+ }
579
+ });
580
+
581
+ it('deletes history entry when delete button is clicked in history', async () => {
582
+ const { deleteHistoryEntry } = await import('../../services/queryHistory');
583
+ mockExplorerState.mockReturnValue({
584
+ ...defaultState,
585
+ resultsTab: 'history',
586
+ history: [
587
+ { key: 'k1', query: 'Events | take 10', timestamp: Date.now(), elapsed: 100, rowCount: 10, columnCount: 2, status: 'success', rows: [{ a: 1 }] },
588
+ ],
589
+ });
590
+ act(() => {
591
+ root.render(React.createElement(ResultsPanel, {
592
+ isDark: false,
593
+ displayRows: null,
594
+ displayColumns: [],
595
+ displayColumnTypes: {},
596
+ onRecall: vi.fn(),
597
+ onClear: vi.fn(),
598
+ }));
599
+ });
600
+ // Find the delete button in the history entry (small icon button)
601
+ const deleteButtons = Array.from(container.querySelectorAll('button')).filter(
602
+ (b) => b.textContent?.includes('icon') && b.style.minWidth === 'auto',
603
+ );
604
+ if (deleteButtons.length > 0) {
605
+ await act(async () => { deleteButtons[0].click(); });
606
+ expect(deleteHistoryEntry).toHaveBeenCalled();
607
+ }
608
+ });
609
+
610
+ it('recalls history entry when clicked', () => {
611
+ mockExplorerState.mockReturnValue({
612
+ ...defaultState,
613
+ resultsTab: 'history',
614
+ history: [
615
+ { key: 'k1', query: 'Events | take 10', timestamp: Date.now(), elapsed: 100, rowCount: 10, columnCount: 2, status: 'success', rows: [{ a: 1 }] },
616
+ ],
617
+ });
618
+ const onRecall = vi.fn();
619
+ act(() => {
620
+ root.render(React.createElement(ResultsPanel, {
621
+ isDark: false,
622
+ displayRows: null,
623
+ displayColumns: [],
624
+ displayColumnTypes: {},
625
+ onRecall,
626
+ onClear: vi.fn(),
627
+ }));
628
+ });
629
+ // Click the history item button (the outer button wrapping the entry)
630
+ const historyBtns = Array.from(container.querySelectorAll('button[type="button"]')).filter(
631
+ (b) => b.textContent?.includes('Events | take 10'),
632
+ );
633
+ if (historyBtns.length > 0) {
634
+ act(() => { (historyBtns[0] as HTMLButtonElement).click(); });
635
+ expect(onRecall).toHaveBeenCalled();
636
+ }
637
+ });
638
+
639
+ it('renders with multiple result sets', () => {
640
+ mockExplorerState.mockReturnValue({
641
+ ...defaultState,
642
+ resultsTab: 'results',
643
+ rows: [],
644
+ columns: ['A'],
645
+ resultSets: [
646
+ { columns: [{ ColumnName: 'A', ColumnType: 'int' }], rows: [{ A: 1 }] },
647
+ { columns: [{ ColumnName: 'B', ColumnType: 'string' }], rows: [{ B: 'x' }] },
648
+ ],
649
+ });
650
+ act(() => {
651
+ root.render(React.createElement(ResultsPanel, {
652
+ isDark: false,
653
+ displayRows: [{ A: 1 }],
654
+ displayColumns: ['A'],
655
+ displayColumnTypes: {},
656
+ onRecall: vi.fn(),
657
+ onClear: vi.fn(),
658
+ }));
659
+ });
660
+ // With 0-length rows array the results header is rendered inline with tab buttons
661
+ expect(container.textContent).toContain('RESULTS');
662
+ });
663
+
664
+ it('renders stats tab with cache hit', () => {
665
+ mockExplorerState.mockReturnValue({
666
+ ...defaultState,
667
+ resultsTab: 'stats',
668
+ queryStats: {
669
+ executionTime: null,
670
+ cpuTime: null,
671
+ memoryPeak: null,
672
+ resultRows: null,
673
+ resultSize: null,
674
+ extentsScanned: null,
675
+ rowsScanned: null,
676
+ cacheHitBytes: null,
677
+ cacheMissBytes: null,
678
+ fromCache: true,
679
+ },
680
+ });
681
+ act(() => {
682
+ root.render(React.createElement(ResultsPanel, {
683
+ isDark: false,
684
+ displayRows: null,
685
+ displayColumns: [],
686
+ displayColumnTypes: {},
687
+ onRecall: vi.fn(),
688
+ onClear: vi.fn(),
689
+ }));
690
+ });
691
+ expect(container.textContent).toContain('✓ Hit');
692
+ });
693
+
694
+ it('handles export handlers early return when columns are empty', async () => {
695
+ const { exportCsv, exportJson } = await import('../ExplorerWorkspace/ExplorerWorkspace.logic');
696
+ const writeTextFn = vi.fn().mockResolvedValue(undefined);
697
+ Object.assign(navigator, { clipboard: { writeText: writeTextFn } });
698
+ (exportCsv as ReturnType<typeof vi.fn>).mockClear();
699
+ (exportJson as ReturnType<typeof vi.fn>).mockClear();
700
+ writeTextFn.mockClear();
701
+ mockExplorerState.mockReturnValue({
702
+ ...defaultState,
703
+ rows: [{ A: 1 }],
704
+ columns: [],
705
+ elapsed: 10,
706
+ resultTime: new Date(),
707
+ });
708
+ act(() => {
709
+ root.render(React.createElement(ResultsPanel, {
710
+ isDark: false,
711
+ displayRows: [{ A: 1 }],
712
+ displayColumns: ['A'],
713
+ displayColumnTypes: {},
714
+ onRecall: vi.fn(),
715
+ onClear: vi.fn(),
716
+ }));
717
+ });
718
+ const buttons = Array.from(container.querySelectorAll('button'));
719
+ for (const btn of buttons) {
720
+ act(() => { btn.click(); });
721
+ }
722
+ expect(exportCsv).not.toHaveBeenCalled();
723
+ expect(exportJson).not.toHaveBeenCalled();
724
+ expect(writeTextFn).not.toHaveBeenCalled();
725
+ });
726
+
727
+ it('calls exportCsv and exportJson when data is present', async () => {
728
+ const { exportCsv, exportJson } = await import('../ExplorerWorkspace/ExplorerWorkspace.logic');
729
+ const writeTextFn = vi.fn().mockResolvedValue(undefined);
730
+ Object.assign(navigator, { clipboard: { writeText: writeTextFn } });
731
+ (exportCsv as ReturnType<typeof vi.fn>).mockClear();
732
+ (exportJson as ReturnType<typeof vi.fn>).mockClear();
733
+ mockExplorerState.mockReturnValue({
734
+ ...defaultState,
735
+ rows: [{ Name: 'a' }],
736
+ columns: ['Name'],
737
+ elapsed: 10,
738
+ resultTime: new Date(),
739
+ });
740
+ act(() => {
741
+ root.render(React.createElement(ResultsPanel, {
742
+ isDark: false,
743
+ displayRows: [{ Name: 'a' }],
744
+ displayColumns: ['Name'],
745
+ displayColumnTypes: { Name: 'string' },
746
+ onRecall: vi.fn(),
747
+ onClear: vi.fn(),
748
+ }));
749
+ });
750
+ const buttons = Array.from(container.querySelectorAll('button'));
751
+ for (const btn of buttons) {
752
+ act(() => { btn.click(); });
753
+ }
754
+ expect(exportCsv).toHaveBeenCalled();
755
+ expect(exportJson).toHaveBeenCalled();
756
+ });
757
+
758
+ it('does not crash when onClear is undefined', () => {
759
+ mockExplorerState.mockReturnValue({
760
+ ...defaultState,
761
+ rows: [{ A: 1 }],
762
+ columns: ['A'],
763
+ elapsed: 42,
764
+ resultTime: new Date(),
765
+ });
766
+ act(() => {
767
+ root.render(React.createElement(ResultsPanel, {
768
+ isDark: false,
769
+ displayRows: [{ A: 1 }],
770
+ displayColumns: ['A'],
771
+ displayColumnTypes: {},
772
+ onRecall: vi.fn(),
773
+ }));
774
+ });
775
+ const buttons = Array.from(container.querySelectorAll('button'));
776
+ for (const btn of buttons) {
777
+ act(() => { btn.click(); });
778
+ }
779
+ expect(container.innerHTML).toBeTruthy();
780
+ });
781
+
782
+ it('renders history entry with null elapsed and no rows (not recallable)', () => {
783
+ mockExplorerState.mockReturnValue({
784
+ ...defaultState,
785
+ resultsTab: 'history',
786
+ history: [
787
+ { key: 'k1', query: 'Events', timestamp: Date.now(), elapsed: null, rowCount: 5, columnCount: 3, status: 'success', rows: null },
788
+ ],
789
+ });
790
+ act(() => {
791
+ root.render(React.createElement(ResultsPanel, {
792
+ isDark: false,
793
+ displayRows: null,
794
+ displayColumns: [],
795
+ displayColumnTypes: {},
796
+ onRecall: vi.fn(),
797
+ onClear: vi.fn(),
798
+ }));
799
+ });
800
+ expect(container.textContent).toContain('Events');
801
+ expect(container.textContent).toContain('5 rows × 3 cols');
802
+ expect(container.textContent).not.toContain('recallable');
803
+ });
804
+
805
+ it('renders stats cache miss text', () => {
806
+ mockExplorerState.mockReturnValue({
807
+ ...defaultState,
808
+ resultsTab: 'stats',
809
+ queryStats: {
810
+ executionTime: null,
811
+ cpuTime: null,
812
+ memoryPeak: null,
813
+ resultRows: null,
814
+ resultSize: null,
815
+ extentsScanned: null,
816
+ rowsScanned: null,
817
+ cacheHitBytes: null,
818
+ cacheMissBytes: null,
819
+ fromCache: false,
820
+ },
821
+ });
822
+ act(() => {
823
+ root.render(React.createElement(ResultsPanel, {
824
+ isDark: false,
825
+ displayRows: null,
826
+ displayColumns: [],
827
+ displayColumnTypes: {},
828
+ onRecall: vi.fn(),
829
+ onClear: vi.fn(),
830
+ }));
831
+ });
832
+ expect(container.textContent).toContain('✗ Miss');
833
+ });
834
+
835
+ it('renders stats with missing extentsTotal and rowsTotal showing ?', () => {
836
+ mockExplorerState.mockReturnValue({
837
+ ...defaultState,
838
+ resultsTab: 'stats',
839
+ queryStats: {
840
+ executionTime: null,
841
+ cpuTime: null,
842
+ memoryPeak: null,
843
+ resultRows: null,
844
+ resultSize: null,
845
+ extentsScanned: 5,
846
+ extentsTotal: null,
847
+ rowsScanned: 200,
848
+ rowsTotal: null,
849
+ cacheHitBytes: null,
850
+ cacheMissBytes: null,
851
+ fromCache: null,
852
+ },
853
+ });
854
+ act(() => {
855
+ root.render(React.createElement(ResultsPanel, {
856
+ isDark: false,
857
+ displayRows: null,
858
+ displayColumns: [],
859
+ displayColumnTypes: {},
860
+ onRecall: vi.fn(),
861
+ onClear: vi.fn(),
862
+ }));
863
+ });
864
+ expect(container.textContent).toContain('5 / ?');
865
+ expect(container.textContent).toContain('200 / ?');
866
+ });
867
+
868
+ it('renders stats with resultSize', () => {
869
+ mockExplorerState.mockReturnValue({
870
+ ...defaultState,
871
+ resultsTab: 'stats',
872
+ queryStats: {
873
+ executionTime: null,
874
+ cpuTime: null,
875
+ memoryPeak: null,
876
+ resultRows: null,
877
+ resultSize: 10240,
878
+ extentsScanned: null,
879
+ rowsScanned: null,
880
+ cacheHitBytes: null,
881
+ cacheMissBytes: null,
882
+ fromCache: null,
883
+ },
884
+ });
885
+ act(() => {
886
+ root.render(React.createElement(ResultsPanel, {
887
+ isDark: false,
888
+ displayRows: null,
889
+ displayColumns: [],
890
+ displayColumnTypes: {},
891
+ onRecall: vi.fn(),
892
+ onClear: vi.fn(),
893
+ }));
894
+ });
895
+ expect(container.textContent).toContain('Result Size');
896
+ expect(container.textContent).toContain('10.0 KB');
897
+ });
898
+
899
+ it('renders stats with shard cache hit and miss bytes', () => {
900
+ mockExplorerState.mockReturnValue({
901
+ ...defaultState,
902
+ resultsTab: 'stats',
903
+ queryStats: {
904
+ executionTime: null,
905
+ cpuTime: null,
906
+ memoryPeak: null,
907
+ resultRows: null,
908
+ resultSize: null,
909
+ extentsScanned: null,
910
+ rowsScanned: null,
911
+ cacheHitBytes: 2048,
912
+ cacheMissBytes: null,
913
+ fromCache: null,
914
+ },
915
+ });
916
+ act(() => {
917
+ root.render(React.createElement(ResultsPanel, {
918
+ isDark: false,
919
+ displayRows: null,
920
+ displayColumns: [],
921
+ displayColumnTypes: {},
922
+ onRecall: vi.fn(),
923
+ onClear: vi.fn(),
924
+ }));
925
+ });
926
+ expect(container.textContent).toContain('Shard Cache Hit / Miss');
927
+ });
928
+
929
+ it('clicks RESULTS tab from non-results tab', () => {
930
+ mockExplorerState.mockReturnValue({
931
+ ...defaultState,
932
+ resultsTab: 'chart',
933
+ });
934
+ act(() => {
935
+ root.render(React.createElement(ResultsPanel, {
936
+ isDark: false,
937
+ displayRows: null,
938
+ displayColumns: [],
939
+ displayColumnTypes: {},
940
+ onRecall: vi.fn(),
941
+ onClear: vi.fn(),
942
+ }));
943
+ });
944
+ const resultsBtn = Array.from(container.querySelectorAll('button[type="button"]')).find(
945
+ (b) => b.textContent === 'RESULTS',
946
+ );
947
+ expect(resultsBtn).toBeTruthy();
948
+ act(() => { (resultsBtn as HTMLButtonElement).click(); });
949
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_RESULTS_TAB', tab: 'results' });
950
+ });
951
+
952
+ it('renders chart tab with empty displayRows array showing empty state', () => {
953
+ mockExplorerState.mockReturnValue({
954
+ ...defaultState,
955
+ resultsTab: 'chart',
956
+ });
957
+ act(() => {
958
+ root.render(React.createElement(ResultsPanel, {
959
+ isDark: false,
960
+ displayRows: [],
961
+ displayColumns: ['A'],
962
+ displayColumnTypes: {},
963
+ onRecall: vi.fn(),
964
+ onClear: vi.fn(),
965
+ }));
966
+ });
967
+ expect(container.textContent).toContain('Run a query to chart results');
968
+ });
969
+
970
+ it('renders history tab label with count on results tab', () => {
971
+ mockExplorerState.mockReturnValue({
972
+ ...defaultState,
973
+ resultsTab: 'results',
974
+ history: [
975
+ { key: 'k1', query: 'q1', timestamp: Date.now(), elapsed: 10, rowCount: 1, columnCount: 1, status: 'success' },
976
+ { key: 'k2', query: 'q2', timestamp: Date.now(), elapsed: 20, rowCount: 2, columnCount: 1, status: 'success' },
977
+ ],
978
+ });
979
+ act(() => {
980
+ root.render(React.createElement(ResultsPanel, {
981
+ isDark: false,
982
+ displayRows: null,
983
+ displayColumns: [],
984
+ displayColumnTypes: {},
985
+ onRecall: vi.fn(),
986
+ onClear: vi.fn(),
987
+ }));
988
+ });
989
+ expect(container.textContent).toContain('HISTORY (2)');
990
+ });
991
+
992
+ it('renders history tab label with count on non-results tab', () => {
993
+ mockExplorerState.mockReturnValue({
994
+ ...defaultState,
995
+ resultsTab: 'history',
996
+ history: [
997
+ { key: 'k1', query: 'q1', timestamp: Date.now(), elapsed: 10, rowCount: 1, columnCount: 1, status: 'success' },
998
+ ],
999
+ });
1000
+ act(() => {
1001
+ root.render(React.createElement(ResultsPanel, {
1002
+ isDark: false,
1003
+ displayRows: null,
1004
+ displayColumns: [],
1005
+ displayColumnTypes: {},
1006
+ onRecall: vi.fn(),
1007
+ onClear: vi.fn(),
1008
+ }));
1009
+ });
1010
+ expect(container.textContent).toContain('HISTORY (1)');
1011
+ });
1012
+
1013
+ it('renders tooltip and tabs with multiple result sets info', () => {
1014
+ mockExplorerState.mockReturnValue({
1015
+ ...defaultState,
1016
+ rows: [{ A: 1 }],
1017
+ columns: ['A'],
1018
+ elapsed: 50,
1019
+ resultTime: new Date('2024-01-01T12:00:00'),
1020
+ resultSets: [
1021
+ { columns: [{ ColumnName: 'A', ColumnType: 'int' }], rows: [{ A: 1 }] },
1022
+ { columns: [{ ColumnName: 'B', ColumnType: 'string' }], rows: [{ B: 'x' }] },
1023
+ { columns: [{ ColumnName: 'C', ColumnType: 'string' }], rows: [{ C: 'y' }] },
1024
+ ],
1025
+ activeResultSet: 1,
1026
+ });
1027
+ act(() => {
1028
+ root.render(React.createElement(ResultsPanel, {
1029
+ isDark: false,
1030
+ displayRows: [{ A: 1 }],
1031
+ displayColumns: ['A'],
1032
+ displayColumnTypes: {},
1033
+ onRecall: vi.fn(),
1034
+ onClear: vi.fn(),
1035
+ }));
1036
+ });
1037
+ expect(container.textContent).toContain('Table 1');
1038
+ expect(container.textContent).toContain('Table 2');
1039
+ expect(container.textContent).toContain('Table 3');
1040
+ });
1041
+
1042
+ it('clicks Table 1 (active result set tab)', () => {
1043
+ mockExplorerState.mockReturnValue({
1044
+ ...defaultState,
1045
+ rows: [{ A: 1 }],
1046
+ columns: ['A'],
1047
+ elapsed: 50,
1048
+ resultTime: new Date(),
1049
+ resultSets: [
1050
+ { columns: [{ ColumnName: 'A', ColumnType: 'int' }], rows: [{ A: 1 }] },
1051
+ { columns: [{ ColumnName: 'B', ColumnType: 'string' }], rows: [{ B: 'x' }] },
1052
+ ],
1053
+ activeResultSet: 0,
1054
+ });
1055
+ act(() => {
1056
+ root.render(React.createElement(ResultsPanel, {
1057
+ isDark: false,
1058
+ displayRows: [{ A: 1 }],
1059
+ displayColumns: ['A'],
1060
+ displayColumnTypes: {},
1061
+ onRecall: vi.fn(),
1062
+ onClear: vi.fn(),
1063
+ }));
1064
+ });
1065
+ const table1Btn = Array.from(container.querySelectorAll('button[type="button"]')).find(
1066
+ (b) => b.textContent === 'Table 1',
1067
+ );
1068
+ expect(table1Btn).toBeTruthy();
1069
+ act(() => { (table1Btn as HTMLButtonElement).click(); });
1070
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_ACTIVE_RESULT_SET', index: 0 });
1071
+ });
1072
+
1073
+ it('renders elapsed time in header right stat text', () => {
1074
+ mockExplorerState.mockReturnValue({
1075
+ ...defaultState,
1076
+ rows: [{ X: 1 }],
1077
+ columns: ['X'],
1078
+ elapsed: 123,
1079
+ resultTime: new Date('2024-01-01T12:00:00'),
1080
+ });
1081
+ act(() => {
1082
+ root.render(React.createElement(ResultsPanel, {
1083
+ isDark: true,
1084
+ displayRows: [{ X: 1 }],
1085
+ displayColumns: ['X'],
1086
+ displayColumnTypes: { X: 'int' },
1087
+ onRecall: vi.fn(),
1088
+ onClear: vi.fn(),
1089
+ }));
1090
+ });
1091
+ expect(container.textContent).toContain('1 rows');
1092
+ expect(container.textContent).toContain('123ms');
1093
+ });
1094
+
1095
+ it('renders without elapsed text when elapsed is null', () => {
1096
+ mockExplorerState.mockReturnValue({
1097
+ ...defaultState,
1098
+ rows: [{ X: 1 }],
1099
+ columns: ['X'],
1100
+ elapsed: null,
1101
+ resultTime: null,
1102
+ });
1103
+ act(() => {
1104
+ root.render(React.createElement(ResultsPanel, {
1105
+ isDark: false,
1106
+ displayRows: [{ X: 1 }],
1107
+ displayColumns: ['X'],
1108
+ displayColumnTypes: { X: 'int' },
1109
+ onRecall: vi.fn(),
1110
+ onClear: vi.fn(),
1111
+ }));
1112
+ });
1113
+ expect(container.textContent).toContain('1 rows');
1114
+ expect(container.textContent).not.toContain('·');
1115
+ });
1116
+
1117
+ it('invokes clearHistory from header clear button', async () => {
1118
+ const { clearHistory: clearHistoryMock } = await import('../../services/queryHistory');
1119
+ (clearHistoryMock as ReturnType<typeof vi.fn>).mockClear();
1120
+ mockExplorerState.mockReturnValue({
1121
+ ...defaultState,
1122
+ resultsTab: 'history',
1123
+ history: [
1124
+ { key: 'k1', query: 'q1', timestamp: Date.now(), elapsed: 10, rowCount: 1, columnCount: 1, status: 'success' },
1125
+ ],
1126
+ });
1127
+ act(() => {
1128
+ root.render(React.createElement(ResultsPanel, {
1129
+ isDark: false,
1130
+ displayRows: null,
1131
+ displayColumns: [],
1132
+ displayColumnTypes: {},
1133
+ onRecall: vi.fn(),
1134
+ onClear: vi.fn(),
1135
+ }));
1136
+ });
1137
+ const headerDiv = container.querySelector('.resultsHeader');
1138
+ const clearBtn = headerDiv?.querySelector('button[appearance="subtle"]');
1139
+ expect(clearBtn).toBeTruthy();
1140
+ await act(async () => { (clearBtn as HTMLButtonElement).click(); });
1141
+ expect(clearHistoryMock).toHaveBeenCalled();
1142
+ });
1143
+
1144
+ it('invokes deleteHistoryEntry from history item delete button', async () => {
1145
+ const { deleteHistoryEntry: deleteEntryMock } = await import('../../services/queryHistory');
1146
+ (deleteEntryMock as ReturnType<typeof vi.fn>).mockClear();
1147
+ mockExplorerState.mockReturnValue({
1148
+ ...defaultState,
1149
+ resultsTab: 'history',
1150
+ history: [
1151
+ { key: 'k1', query: 'Events', timestamp: Date.now(), elapsed: 10, rowCount: 1, columnCount: 1, status: 'success' },
1152
+ ],
1153
+ });
1154
+ act(() => {
1155
+ root.render(React.createElement(ResultsPanel, {
1156
+ isDark: false,
1157
+ displayRows: null,
1158
+ displayColumns: [],
1159
+ displayColumnTypes: {},
1160
+ onRecall: vi.fn(),
1161
+ onClear: vi.fn(),
1162
+ }));
1163
+ });
1164
+ const historyList = container.querySelector('.historyList');
1165
+ const deleteBtn = historyList?.querySelector('button[title="Delete"]');
1166
+ expect(deleteBtn).toBeTruthy();
1167
+ await act(async () => { (deleteBtn as HTMLButtonElement).click(); });
1168
+ expect(deleteEntryMock).toHaveBeenCalledWith('k1');
1169
+ });
1170
+
1171
+ it('invokes onRecall when history item is clicked', () => {
1172
+ const entry = { key: 'k1', query: 'Events', timestamp: Date.now(), elapsed: 10, rowCount: 1, columnCount: 1, status: 'success' };
1173
+ mockExplorerState.mockReturnValue({
1174
+ ...defaultState,
1175
+ resultsTab: 'history',
1176
+ history: [entry],
1177
+ });
1178
+ const onRecall = vi.fn();
1179
+ act(() => {
1180
+ root.render(React.createElement(ResultsPanel, {
1181
+ isDark: false,
1182
+ displayRows: null,
1183
+ displayColumns: [],
1184
+ displayColumnTypes: {},
1185
+ onRecall,
1186
+ onClear: vi.fn(),
1187
+ }));
1188
+ });
1189
+ const historyItemBtn = container.querySelector('.historyItem') as HTMLButtonElement;
1190
+ expect(historyItemBtn).toBeTruthy();
1191
+ act(() => { historyItemBtn.click(); });
1192
+ expect(onRecall).toHaveBeenCalledWith(entry);
1193
+ });
1194
+ });