@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,450 @@
1
+
2
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3
+ import React from 'react';
4
+ import { createRoot } from 'react-dom/client';
5
+ import { act } from 'react';
6
+ import { ExplorerWorkspace } from './ExplorerWorkspace';
7
+
8
+ import { loadSchema, getSchema } from '../../services/schema';
9
+ import { getHistory } from '../../services/queryHistory';
10
+ import { registerKqlLanguage, setKqlSchemaResolver } from './kqlLanguage';
11
+ import { saveActiveConnectionId } from './ExplorerWorkspace.logic';
12
+
13
+ vi.mock('../EditorToolbar/EditorToolbar', () => ({
14
+ EditorToolbar: (p: Record<string, unknown>) => React.createElement('div', { 'data-testid': 'editor-toolbar', 'data-show-cancel': String(p['showCancel']) }),
15
+ }));
16
+ vi.mock('../ResultsPanel/ResultsPanel', () => ({
17
+ ResultsPanel: (p: Record<string, unknown>) => React.createElement('div', { 'data-testid': 'results-panel', 'data-columns': JSON.stringify(p['displayColumns']), 'data-rows': p['displayRows'] ? 'yes' : 'no' }),
18
+ }));
19
+ vi.mock('../SchemaSidebar/SchemaSidebar', () => ({
20
+ SchemaSidebar: (p: Record<string, unknown>) => React.createElement('div', { 'data-testid': 'schema-sidebar', 'data-loading': String(p['loading'] ?? false) }),
21
+ }));
22
+ vi.mock('../TabBar/TabBar', () => ({
23
+ TabBar: () => React.createElement('div', { 'data-testid': 'tab-bar' }),
24
+ }));
25
+ vi.mock('@monaco-editor/react', () => ({
26
+ Editor: (p: Record<string, unknown>) => {
27
+ const onMount = p['onMount'] as ((editor: unknown, monaco: unknown) => void) | undefined;
28
+ React.useEffect(() => {
29
+ if (onMount) {
30
+ const mockEditor = {
31
+ getModel: () => ({
32
+ onDidChangeContent: vi.fn(),
33
+ getValue: () => 'TestTable | take 10',
34
+ getLineCount: () => 1,
35
+ getLineContent: () => 'TestTable | take 10',
36
+ getLineMaxColumn: () => 20,
37
+ setValue: vi.fn(),
38
+ }),
39
+ onDidChangeCursorPosition: vi.fn(),
40
+ onDidChangeCursorSelection: vi.fn(),
41
+ onDidChangeModelContent: vi.fn(),
42
+ onDidFocusEditorWidget: vi.fn(),
43
+ getPosition: () => ({ lineNumber: 1, column: 1 }),
44
+ getSelection: () => null,
45
+ createDecorationsCollection: () => ({ set: vi.fn(), clear: vi.fn() }),
46
+ focus: vi.fn(),
47
+ setPosition: vi.fn(),
48
+ revealLineInCenter: vi.fn(),
49
+ addAction: vi.fn(),
50
+ addCommand: vi.fn(),
51
+ executeEdits: vi.fn(),
52
+ setValue: vi.fn(),
53
+ getValue: () => 'TestTable | take 10',
54
+ };
55
+ const mockMonaco = {
56
+ languages: { register: vi.fn(), setMonarchTokensProvider: vi.fn(), registerCompletionItemProvider: vi.fn() },
57
+ editor: { defineTheme: vi.fn() },
58
+ KeyMod: { CtrlCmd: 2048, Shift: 1024, Alt: 512 },
59
+ KeyCode: { Enter: 3, KeyR: 48, KeyF: 36 },
60
+ };
61
+ onMount(mockEditor, mockMonaco);
62
+ }
63
+ }, [onMount]);
64
+ return React.createElement('div', { 'data-testid': 'monaco-editor', 'data-value': p['value'] as string });
65
+ },
66
+ }));
67
+ vi.mock('../../context/ExplorerColorContext', () => ({
68
+ useExplorerColors: () => ({
69
+ semantic: {
70
+ backdrop: 'rgba(0,0,0,0.4)', functionBadge: '#4caf50', highlightHoverBg: 'rgba(255,200,0,0.2)',
71
+ lookupBadge: '#e8912d', materializedViewBadge: '#9c6ade', scrollThumb: 'rgba(128,128,128,0.4)',
72
+ scrollThumbHover: 'rgba(128,128,128,0.6)', selectionBg: 'rgba(0,120,212,0.15)',
73
+ selectionSubtle: 'rgba(0,120,212,0.06)', shadowLight: 'rgba(0,0,0,0.15)', shadowMedium: 'rgba(0,0,0,0.3)',
74
+ },
75
+ chart: { palette: ['#6a8799', '#909d63', '#ebc17a'] },
76
+ }),
77
+ }));
78
+
79
+ const mockDispatch = vi.fn();
80
+
81
+ vi.mock('../../context/ExplorerStateContext', () => {
82
+ const state = {
83
+ schema: [], connections: [{ id: 'c1', name: 'Test', clusterUrl: 'https://test.kusto.windows.net', database: 'DB', color: '#aaa' }],
84
+ tabs: [{ id: 't1', name: 'Tab 1', kql: 'StormEvents | take 10', connectionId: 'c1' }],
85
+ activeTabId: 't1', splitEnabled: false, splitDirection: 'vertical' as const, splitTabId: null, focusedPane: 'primary' as const,
86
+ loading: false, runningQueryKey: null,
87
+ rows: null, columns: [], columnTypes: {}, resultSets: [], activeResultSet: 0,
88
+ history: [], editorHeight: 300, canRecall: false, hasSelection: false, editorDropTarget: null,
89
+ };
90
+ return {
91
+ useExplorerState: () => state,
92
+ useExplorerDispatch: () => mockDispatch,
93
+ useActiveTabs: () => ({
94
+ activeTab: state.tabs[0],
95
+ splitTab: null,
96
+ }),
97
+ useFocusedConnection: () => state.connections[0],
98
+ };
99
+ });
100
+ vi.mock('../../context/KustoClientContext', () => ({
101
+ useKustoClient: () => ({
102
+ queryKusto: vi.fn().mockResolvedValue({ rows: [], columns: [], resultSets: [] }),
103
+ queryKustoMgmt: vi.fn().mockResolvedValue({ rows: [], columns: [] }),
104
+ clearQueryCache: vi.fn(),
105
+ getQueryCacheSize: vi.fn().mockReturnValue(0),
106
+ }),
107
+ }));
108
+ vi.mock('../../services/queryHistory', () => ({
109
+ normalizeQuery: (q: string) => (q ?? '').trim(),
110
+ getHistory: vi.fn().mockResolvedValue([]),
111
+ saveHistoryEntry: vi.fn().mockResolvedValue(undefined),
112
+ recallResult: vi.fn().mockResolvedValue(null),
113
+ }));
114
+ vi.mock('../../services/schema', () => ({
115
+ getSchema: vi.fn().mockReturnValue([]),
116
+ loadSchema: vi.fn().mockResolvedValue(undefined),
117
+ }));
118
+ vi.mock('./ExplorerWorkspace.logic', () => ({
119
+ formatKql: (s: string) => s,
120
+ getQueryToRunFromEditor: (ed: unknown) => {
121
+ if (!ed) {
122
+ return null;
123
+ }
124
+ return { query: 'StormEvents | take 10', startLine: 1, endLine: 1 };
125
+ },
126
+ parseResultColumns: () => ({ columns: ['Col1'], columnTypes: { Col1: 'string' } }),
127
+ buildSuccessEntry: () => ({ key: 'k', query: 'q', timestamp: Date.now(), status: 'success' as const, rowCount: 0, columnCount: 0, elapsed: 0 }),
128
+ buildErrorEntry: () => ({ key: 'k', query: 'q', timestamp: Date.now(), status: 'error' as const, rowCount: 0, columnCount: 0, elapsed: 0, error: 'err' }),
129
+ saveActiveConnectionId: vi.fn(),
130
+ getEditorDropTarget: (_rect: unknown, _x: number, _y: number) => 'left' as const,
131
+ getShortcutAction: (e: { metaKey: boolean; ctrlKey: boolean; key: string }, tabCount: number, activeTabKql: string) => {
132
+ const mod = e.metaKey || e.ctrlKey;
133
+ if (!mod) {
134
+ return null;
135
+ }
136
+ if (e.key === 't') {
137
+ return 'add-tab';
138
+ }
139
+ if (e.key === 'w' && tabCount > 1) {
140
+ if (activeTabKql.trim()) {
141
+ return 'close-tab-confirm';
142
+ }
143
+ return 'close-tab';
144
+ }
145
+ return null;
146
+ },
147
+ CONNECTION_COLORS: ['#aaa', '#bbb'],
148
+ DEFAULT_CONNECTION: { id: 'c1', name: 'Test', clusterUrl: 'https://test.kusto.windows.net', database: 'DB', color: '#aaa' },
149
+ loadConnections: vi.fn().mockReturnValue([]),
150
+ saveConnections: vi.fn(),
151
+ buildWellKnownClusters: vi.fn().mockReturnValue([]),
152
+ KEYBOARD_SHORTCUTS: [],
153
+ }));
154
+ vi.mock('./ExplorerWorkspace.styles', () => ({
155
+ useExplorerStyles: () => new Proxy({}, { get: (_, p) => String(p) }),
156
+ }));
157
+ vi.mock('./kqlLanguage', () => ({
158
+ registerKqlLanguage: vi.fn(),
159
+ setKqlSchemaResolver: vi.fn(),
160
+ }));
161
+
162
+
163
+ let container: HTMLDivElement;
164
+ let root: ReturnType<typeof createRoot>;
165
+
166
+ beforeEach(() => {
167
+ vi.spyOn(console, 'error').mockImplementation(() => {});
168
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
169
+ container = document.createElement('div');
170
+ document.body.appendChild(container);
171
+ root = createRoot(container);
172
+ mockDispatch.mockClear();
173
+ });
174
+
175
+ afterEach(() => {
176
+ act(() => { root.unmount(); });
177
+ container.remove();
178
+ vi.restoreAllMocks();
179
+ });
180
+
181
+ const defaultProps = {
182
+ isDark: false,
183
+ kustoClient: {} as never,
184
+ colors: {} as never,
185
+ clusters: [],
186
+ };
187
+
188
+ describe('ExplorerWorkspace', () => {
189
+ it('renders toolbar, tab bar, editor, and results panel', () => {
190
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
191
+
192
+ expect(container.querySelector('[data-testid="editor-toolbar"]')).toBeTruthy();
193
+ expect(container.querySelector('[data-testid="tab-bar"]')).toBeTruthy();
194
+ expect(container.querySelector('[data-testid="monaco-editor"]')).toBeTruthy();
195
+ expect(container.querySelector('[data-testid="results-panel"]')).toBeTruthy();
196
+ });
197
+
198
+ it('renders schema sidebar', () => {
199
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
200
+
201
+ expect(container.querySelector('[data-testid="schema-sidebar"]')).toBeTruthy();
202
+ });
203
+
204
+ it('passes isDark to editor theme', () => {
205
+ act(() => { root.render(React.createElement(ExplorerWorkspace, { ...defaultProps, isDark: true })); });
206
+
207
+ const editor = container.querySelector('[data-testid="monaco-editor"]');
208
+ expect(editor).toBeTruthy();
209
+ });
210
+
211
+ it('renders with className prop', () => {
212
+ act(() => { root.render(React.createElement(ExplorerWorkspace, { ...defaultProps, className: 'my-class' })); });
213
+
214
+ expect(container.innerHTML).toBeTruthy();
215
+ });
216
+
217
+ it('renders drag handle between editor and results', () => {
218
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
219
+
220
+ const dragHandle = container.querySelector('[role="separator"]');
221
+ expect(dragHandle).toBeTruthy();
222
+ });
223
+
224
+ it('handles editor mount callback', () => {
225
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
226
+
227
+ expect(container.querySelector('[data-testid="monaco-editor"]')).toBeTruthy();
228
+ });
229
+
230
+ it('renders editor with active tab query', () => {
231
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
232
+
233
+ const editor = container.querySelector('[data-testid="monaco-editor"]');
234
+ expect(editor?.getAttribute('data-value')).toBe('StormEvents | take 10');
235
+ });
236
+
237
+ it('renders drag handle that responds to mousedown', () => {
238
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
239
+
240
+ const separators = container.querySelectorAll('[role="separator"]');
241
+ expect(separators.length).toBeGreaterThan(0);
242
+ // Simulate drag start
243
+ act(() => {
244
+ separators[0].dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientY: 200 }));
245
+ });
246
+ // Simulate drag end via document mouseup
247
+ act(() => {
248
+ document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
249
+ });
250
+ });
251
+
252
+ it('renders with split mode disabled', () => {
253
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
254
+
255
+ // Only one editor when split is disabled
256
+ const editors = container.querySelectorAll('[data-testid="monaco-editor"]');
257
+ expect(editors).toHaveLength(1);
258
+ });
259
+
260
+ // --- Keyboard shortcuts ---
261
+ it('Cmd+T dispatches ADD_TAB when enableTabShortcuts is true', () => {
262
+ act(() => { root.render(React.createElement(ExplorerWorkspace, { ...defaultProps, enableTabShortcuts: true })); });
263
+
264
+ act(() => {
265
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 't', metaKey: true, bubbles: true }));
266
+ });
267
+
268
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'ADD_TAB' });
269
+ });
270
+
271
+ it('Ctrl+T also dispatches ADD_TAB', () => {
272
+ act(() => { root.render(React.createElement(ExplorerWorkspace, { ...defaultProps, enableTabShortcuts: true })); });
273
+
274
+ act(() => {
275
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 't', ctrlKey: true, bubbles: true }));
276
+ });
277
+
278
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'ADD_TAB' });
279
+ });
280
+
281
+ it('keyboard shortcut does nothing when enableTabShortcuts is false', () => {
282
+ act(() => { root.render(React.createElement(ExplorerWorkspace, { ...defaultProps, enableTabShortcuts: false })); });
283
+
284
+ act(() => {
285
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 't', metaKey: true, bubbles: true }));
286
+ });
287
+
288
+ expect(mockDispatch).not.toHaveBeenCalledWith({ type: 'ADD_TAB' });
289
+ });
290
+
291
+ it('non-shortcut key does nothing', () => {
292
+ act(() => { root.render(React.createElement(ExplorerWorkspace, { ...defaultProps, enableTabShortcuts: true })); });
293
+
294
+ act(() => {
295
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'a', bubbles: true }));
296
+ });
297
+
298
+ expect(mockDispatch).not.toHaveBeenCalledWith({ type: 'ADD_TAB' });
299
+ });
300
+
301
+ // --- Schema loading ---
302
+ it('triggers loadSchema on mount with connection target', () => {
303
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
304
+
305
+ expect(loadSchema).toHaveBeenCalled();
306
+ });
307
+
308
+ it('calls loadSchema and getSchema for the connection target', () => {
309
+ vi.mocked(getSchema).mockReturnValue([{ name: 'T1', folder: '', kind: 'table', description: '', columns: [] }]);
310
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
311
+
312
+ expect(loadSchema).toHaveBeenCalled();
313
+ // getSchema is called during the schema resolver setup
314
+ expect(getSchema).toHaveBeenCalled();
315
+ });
316
+
317
+ // --- Drag resize ---
318
+ it('drag resize adjusts editor height via mousemove', () => {
319
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
320
+
321
+ // Find the last separator (the one between editor and results)
322
+ const separators = container.querySelectorAll('[role="separator"]');
323
+ const dragHandle = separators[separators.length - 1];
324
+
325
+ act(() => {
326
+ dragHandle.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientY: 200 }));
327
+ });
328
+
329
+ act(() => {
330
+ document.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientY: 250 }));
331
+ });
332
+
333
+ act(() => {
334
+ document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
335
+ });
336
+
337
+ expect(mockDispatch).toHaveBeenCalledWith(expect.objectContaining({ type: 'SET_EDITOR_HEIGHT' }));
338
+ });
339
+
340
+ // --- Schema sidebar resize ---
341
+ it('schema resize handle responds to mousedown + mousemove', () => {
342
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
343
+
344
+ const separators = container.querySelectorAll('[role="separator"]');
345
+ // First separator is the schema resize handle
346
+ const schemaHandle = separators[0];
347
+
348
+ act(() => {
349
+ schemaHandle.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: 220 }));
350
+ });
351
+
352
+ act(() => {
353
+ document.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX: 280 }));
354
+ });
355
+
356
+ act(() => {
357
+ document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
358
+ });
359
+
360
+ // Schema sidebar should have resized (the style should have changed)
361
+ expect(container.innerHTML).toBeTruthy();
362
+ });
363
+
364
+ // --- Primary editor pane click sets focus ---
365
+ it('clicking primary editor pane dispatches SET_FOCUSED_PANE', () => {
366
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
367
+
368
+ const editorPane = container.querySelector('[role="tabpanel"]') as HTMLElement;
369
+ expect(editorPane).toBeTruthy();
370
+ act(() => { editorPane.click(); });
371
+
372
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_FOCUSED_PANE', pane: 'primary' });
373
+ });
374
+
375
+ // --- History loaded on mount ---
376
+ it('loads query history on mount', () => {
377
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
378
+ expect(getHistory).toHaveBeenCalled();
379
+ });
380
+
381
+ // --- Injects run-highlight CSS on mount ---
382
+ it('injects traverse-run-highlight style element', () => {
383
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
384
+
385
+ const styleEl = document.getElementById('traverse-run-highlight-style');
386
+ expect(styleEl).toBeTruthy();
387
+ expect(styleEl?.textContent).toContain('traverse-run-highlight');
388
+ });
389
+
390
+ // --- DragOver on primary editor ---
391
+ it('primary editor pane handles dragover', () => {
392
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
393
+
394
+ const editorPane = container.querySelector('[role="tabpanel"]') as HTMLElement;
395
+ // Simulate a drag event (no dragTabIdRef set, so it should be a no-op)
396
+ const dragEvent = new Event('dragover', { bubbles: true }) as unknown as DragEvent;
397
+ Object.defineProperty(dragEvent, 'preventDefault', { value: vi.fn() });
398
+ Object.defineProperty(dragEvent, 'dataTransfer', { value: { dropEffect: '' } });
399
+ act(() => { editorPane.dispatchEvent(dragEvent); });
400
+ });
401
+
402
+ // --- DragLeave resets drop target ---
403
+ it('dragleave on editor pane resets state', () => {
404
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
405
+
406
+ const editorPane = container.querySelector('[role="tabpanel"]') as HTMLElement;
407
+ act(() => {
408
+ editorPane.dispatchEvent(new Event('dragleave', { bubbles: true }));
409
+ });
410
+ expect(container.innerHTML).toBeTruthy();
411
+ });
412
+
413
+ // --- EditorToolbar receives showCancel ---
414
+ it('EditorToolbar receives showCancel as false when not loading', () => {
415
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
416
+
417
+ const toolbar = container.querySelector('[data-testid="editor-toolbar"]');
418
+ expect(toolbar?.getAttribute('data-show-cancel')).toBe('false');
419
+ });
420
+
421
+ // --- setKqlSchemaResolver called ---
422
+ it('sets KQL schema resolver on mount', () => {
423
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
424
+ expect(setKqlSchemaResolver).toHaveBeenCalled();
425
+ });
426
+
427
+ // --- registerKqlLanguage called ---
428
+ it('registers KQL language on editor mount', () => {
429
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
430
+ expect(registerKqlLanguage).toHaveBeenCalled();
431
+ });
432
+
433
+ // --- saveActiveConnectionId called ---
434
+ it('saves active connection ID on mount', () => {
435
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
436
+ expect(saveActiveConnectionId).toHaveBeenCalledWith('c1');
437
+ });
438
+
439
+ // --- Keyboard Enter on primary pane ---
440
+ it('primary editor pane handles Enter keydown', () => {
441
+ act(() => { root.render(React.createElement(ExplorerWorkspace, defaultProps)); });
442
+
443
+ const editorPane = container.querySelector('[role="tabpanel"]') as HTMLElement;
444
+ act(() => {
445
+ editorPane.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
446
+ });
447
+
448
+ expect(mockDispatch).toHaveBeenCalledWith({ type: 'SET_FOCUSED_PANE', pane: 'primary' });
449
+ });
450
+ });