@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,929 @@
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 { TabBar } from './TabBar';
6
+
7
+ vi.mock('../../context/ExplorerStateContext', () => ({
8
+ useExplorerState: () => mockTabBarState(),
9
+ useExplorerDispatch: () => mockTabBarDispatch,
10
+ }));
11
+ vi.mock('../ExplorerWorkspace/ExplorerWorkspace.styles', () => ({
12
+ useExplorerStyles: () => new Proxy({}, { get: (_, p) => String(p) }),
13
+ }));
14
+ vi.mock('@fluentui/react-components', () => ({
15
+ Button: (p: Record<string, unknown>) => React.createElement('button', p, p['children'] as React.ReactNode),
16
+ Tooltip: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
17
+ Menu: (p: Record<string, unknown>) => p['open'] ? React.createElement('div', null, p['children'] as React.ReactNode) : null,
18
+ MenuList: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
19
+ MenuItem: (p: Record<string, unknown>) => React.createElement('div', { onClick: p['onClick'] as (() => void) }, p['children'] as React.ReactNode),
20
+ MenuPopover: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
21
+ MenuDivider: () => React.createElement('hr'),
22
+ Dialog: (p: Record<string, unknown>) => p['open'] ? React.createElement('div', null, p['children'] as React.ReactNode) : null,
23
+ DialogSurface: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
24
+ DialogBody: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
25
+ DialogTitle: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
26
+ DialogContent: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
27
+ DialogActions: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
28
+ DialogTrigger: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
29
+ tokens: { colorBrandStroke1: '#blue', colorBrandBackground: '#blue', colorPaletteGreenBackground3: '#green' },
30
+ }));
31
+ vi.mock('@fluentui/react-icons', () => ({
32
+ AddRegular: () => React.createElement('span', null, 'icon'),
33
+ DismissRegular: () => React.createElement('span', null, 'icon'),
34
+ SplitVerticalRegular: () => React.createElement('span', null, 'icon'),
35
+ SplitHorizontalRegular: () => React.createElement('span', null, 'icon'),
36
+ RenameRegular: () => React.createElement('span', null, 'icon'),
37
+ CopyRegular: () => React.createElement('span', null, 'icon'),
38
+ DismissCircleRegular: () => React.createElement('span', null, 'icon'),
39
+ }));
40
+
41
+ const defaultTabBarState = {
42
+ tabs: [{ id: '1', query: '', title: 'Tab 1', kql: '', connectionId: 'test-conn' }],
43
+ activeTabId: '1',
44
+ splitEnabled: false,
45
+ splitDirection: 'vertical' as 'vertical' | 'horizontal',
46
+ splitTabId: null as string | null,
47
+ focusedPane: 'primary' as 'primary' | 'secondary',
48
+ connections: [{ id: 'test-conn', name: 'Test Cluster', clusterUrl: 'https://help.kusto.windows.net', database: 'Telemetry', color: '#909d63' }],
49
+ };
50
+ const mockTabBarState = vi.fn(() => defaultTabBarState);
51
+ const mockTabBarDispatch = vi.fn();
52
+
53
+
54
+ describe('TabBar', () => {
55
+ let container: HTMLDivElement;
56
+ let root: ReturnType<typeof createRoot>;
57
+ let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
58
+ let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
59
+
60
+ beforeEach(() => {
61
+ consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
62
+ consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
63
+ container = document.createElement('div');
64
+ document.body.appendChild(container);
65
+ root = createRoot(container);
66
+ mockTabBarState.mockReturnValue(defaultTabBarState);
67
+ mockTabBarDispatch.mockClear();
68
+ });
69
+
70
+ afterEach(() => {
71
+ act(() => {
72
+ root.unmount();
73
+ });
74
+ container.remove();
75
+ consoleErrorSpy.mockRestore();
76
+ consoleWarnSpy.mockRestore();
77
+ });
78
+
79
+ it('renders without crashing', () => {
80
+ const dragTabIdRef = { current: null };
81
+ const onSetEditorDropTarget = vi.fn();
82
+
83
+ act(() => {
84
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget }));
85
+ });
86
+ expect(container.innerHTML).not.toBe('');
87
+ });
88
+
89
+ it('renders multiple tabs', () => {
90
+ mockTabBarState.mockReturnValue({
91
+ ...defaultTabBarState,
92
+ tabs: [
93
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
94
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
95
+ { id: '3', query: '', title: 'Tab 3', connectionId: 'test-conn', kql: '' },
96
+ ],
97
+ });
98
+ const dragTabIdRef = { current: null };
99
+ act(() => {
100
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
101
+ });
102
+ expect(container.textContent).toContain('Tab 1');
103
+ expect(container.textContent).toContain('Tab 2');
104
+ expect(container.textContent).toContain('Tab 3');
105
+ });
106
+
107
+ it('switches tab on click', () => {
108
+ mockTabBarState.mockReturnValue({
109
+ ...defaultTabBarState,
110
+ tabs: [
111
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
112
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
113
+ ],
114
+ });
115
+ const dragTabIdRef = { current: null };
116
+ act(() => {
117
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
118
+ });
119
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
120
+ const tab2 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 2'));
121
+ if (tab2) {
122
+ act(() => { (tab2 as HTMLElement).click(); });
123
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'SWITCH_TAB', tabId: '2' });
124
+ }
125
+ });
126
+
127
+ it('adds a new tab when add button is clicked', () => {
128
+ const dragTabIdRef = { current: null };
129
+ act(() => {
130
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
131
+ });
132
+ const buttons = container.querySelectorAll('button');
133
+ const addBtn = buttons[0];
134
+ if (addBtn) {
135
+ act(() => { addBtn.click(); });
136
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'ADD_TAB' });
137
+ }
138
+ });
139
+
140
+ it('closes a tab when close button is clicked', () => {
141
+ mockTabBarState.mockReturnValue({
142
+ ...defaultTabBarState,
143
+ tabs: [
144
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
145
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
146
+ ],
147
+ });
148
+ const dragTabIdRef = { current: null };
149
+ act(() => {
150
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
151
+ });
152
+ // Close buttons are spans with 'icon' text inside tabs
153
+ const closeSpans = container.querySelectorAll('span');
154
+ const closeBtn = Array.from(closeSpans).filter((s) => s.textContent === 'icon' && s.parentElement?.getAttribute('tabindex') === '0');
155
+ if (closeBtn.length > 0) {
156
+ act(() => { (closeBtn[0] as HTMLElement).click(); });
157
+ expect(mockTabBarDispatch).toHaveBeenCalledWith(expect.objectContaining({ type: 'CLOSE_TAB' }));
158
+ }
159
+ });
160
+
161
+ it('starts rename on double click', () => {
162
+ const dragTabIdRef = { current: null };
163
+ act(() => {
164
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
165
+ });
166
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
167
+ if (tabEl) {
168
+ act(() => {
169
+ tabEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
170
+ });
171
+ // Should show an input for renaming
172
+ const input = container.querySelector('input');
173
+ expect(input).toBeTruthy();
174
+ }
175
+ });
176
+
177
+ it('commits rename on Enter', () => {
178
+ const dragTabIdRef = { current: null };
179
+ act(() => {
180
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
181
+ });
182
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
183
+ if (tabEl) {
184
+ act(() => {
185
+ tabEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
186
+ });
187
+ const input = container.querySelector('input') as HTMLInputElement;
188
+ if (input) {
189
+ act(() => {
190
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, 'New Name');
191
+ input.dispatchEvent(new Event('change', { bubbles: true }));
192
+ });
193
+ act(() => {
194
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
195
+ });
196
+ expect(mockTabBarDispatch).toHaveBeenCalledWith(expect.objectContaining({ type: 'RENAME_TAB' }));
197
+ }
198
+ }
199
+ });
200
+
201
+ it('opens context menu on right click', () => {
202
+ const dragTabIdRef = { current: null };
203
+ act(() => {
204
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
205
+ });
206
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
207
+ if (tabEl) {
208
+ act(() => {
209
+ const ev = new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 });
210
+ tabEl.dispatchEvent(ev);
211
+ });
212
+ expect(container.textContent).toContain('Rename');
213
+ }
214
+ });
215
+
216
+ it('toggles split vertical', () => {
217
+ const dragTabIdRef = { current: null };
218
+ act(() => {
219
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
220
+ });
221
+ // Split buttons are the last two regular buttons
222
+ const buttons = container.querySelectorAll('button');
223
+ const splitVertBtn = buttons[buttons.length - 2];
224
+ if (splitVertBtn) {
225
+ act(() => { splitVertBtn.click(); });
226
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'TOGGLE_SPLIT', direction: 'vertical' });
227
+ }
228
+ });
229
+
230
+ it('toggles split horizontal', () => {
231
+ const dragTabIdRef = { current: null };
232
+ act(() => {
233
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
234
+ });
235
+ const buttons = container.querySelectorAll('button');
236
+ const splitHorizBtn = buttons[buttons.length - 1];
237
+ if (splitHorizBtn) {
238
+ act(() => { splitHorizBtn.click(); });
239
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'TOGGLE_SPLIT', direction: 'horizontal' });
240
+ }
241
+ });
242
+
243
+ it('renders with split enabled showing primary/secondary markers', () => {
244
+ mockTabBarState.mockReturnValue({
245
+ ...defaultTabBarState,
246
+ tabs: [
247
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
248
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
249
+ ],
250
+ splitEnabled: true,
251
+ splitTabId: '2',
252
+ });
253
+ const dragTabIdRef = { current: null };
254
+ act(() => {
255
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
256
+ });
257
+ expect(container.textContent).toContain('L');
258
+ expect(container.textContent).toContain('R');
259
+ });
260
+
261
+ it('handles keyboard navigation on tab', () => {
262
+ const dragTabIdRef = { current: null };
263
+ act(() => {
264
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
265
+ });
266
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
267
+ if (tabEl) {
268
+ act(() => {
269
+ tabEl.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
270
+ });
271
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'SWITCH_TAB', tabId: '1' });
272
+ }
273
+ });
274
+
275
+ it('switches tab on Space keydown', () => {
276
+ mockTabBarState.mockReturnValue({
277
+ ...defaultTabBarState,
278
+ tabs: [
279
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
280
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
281
+ ],
282
+ });
283
+ const dragTabIdRef = { current: null };
284
+ act(() => {
285
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
286
+ });
287
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
288
+ const tab2 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 2')) as HTMLElement;
289
+ expect(tab2).toBeTruthy();
290
+ act(() => {
291
+ tab2.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));
292
+ });
293
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'SWITCH_TAB', tabId: '2' });
294
+ });
295
+
296
+ it('does not switch tab on unrelated key', () => {
297
+ const dragTabIdRef = { current: null };
298
+ act(() => {
299
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
300
+ });
301
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
302
+ expect(tabEl).toBeTruthy();
303
+ mockTabBarDispatch.mockClear();
304
+ act(() => {
305
+ tabEl.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true }));
306
+ });
307
+ expect(mockTabBarDispatch).not.toHaveBeenCalled();
308
+ });
309
+
310
+ it('cancels rename on Escape', () => {
311
+ const dragTabIdRef = { current: null };
312
+ act(() => {
313
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
314
+ });
315
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
316
+ act(() => {
317
+ tabEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
318
+ });
319
+ const input = container.querySelector('input') as HTMLInputElement;
320
+ expect(input).toBeTruthy();
321
+ act(() => {
322
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
323
+ });
324
+ expect(container.querySelector('input')).toBeNull();
325
+ expect(mockTabBarDispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'RENAME_TAB' }));
326
+ });
327
+
328
+ it('commits rename on blur', () => {
329
+ const dragTabIdRef = { current: null };
330
+ act(() => {
331
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
332
+ });
333
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
334
+ act(() => {
335
+ tabEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
336
+ });
337
+ const input = container.querySelector('input') as HTMLInputElement;
338
+ expect(input).toBeTruthy();
339
+ act(() => {
340
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, 'Blurred Name');
341
+ input.dispatchEvent(new Event('change', { bubbles: true }));
342
+ });
343
+ act(() => {
344
+ input.dispatchEvent(new FocusEvent('focusout', { bubbles: true }));
345
+ });
346
+ expect(mockTabBarDispatch).toHaveBeenCalledWith(expect.objectContaining({ type: 'RENAME_TAB', title: 'Blurred Name' }));
347
+ });
348
+
349
+ it('does not dispatch rename when value is whitespace only', () => {
350
+ const dragTabIdRef = { current: null };
351
+ act(() => {
352
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
353
+ });
354
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
355
+ act(() => {
356
+ tabEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
357
+ });
358
+ const input = container.querySelector('input') as HTMLInputElement;
359
+ expect(input).toBeTruthy();
360
+ act(() => {
361
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, ' ');
362
+ input.dispatchEvent(new Event('change', { bubbles: true }));
363
+ });
364
+ act(() => {
365
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
366
+ });
367
+ expect(mockTabBarDispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'RENAME_TAB' }));
368
+ });
369
+
370
+ it('clicking the rename input does not switch tab', () => {
371
+ const dragTabIdRef = { current: null };
372
+ act(() => {
373
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
374
+ });
375
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
376
+ act(() => {
377
+ tabEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
378
+ });
379
+ const input = container.querySelector('input') as HTMLInputElement;
380
+ expect(input).toBeTruthy();
381
+ mockTabBarDispatch.mockClear();
382
+ act(() => {
383
+ input.click();
384
+ });
385
+ expect(mockTabBarDispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'SWITCH_TAB' }));
386
+ });
387
+
388
+ it('does not show close button for a single tab', () => {
389
+ mockTabBarState.mockReturnValue({
390
+ ...defaultTabBarState,
391
+ tabs: [{ id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' }],
392
+ });
393
+ const dragTabIdRef = { current: null };
394
+ act(() => {
395
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
396
+ });
397
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
398
+ expect(tabEl).toBeTruthy();
399
+ const closeSpans = tabEl.querySelectorAll('[tabindex="0"]');
400
+ expect(closeSpans.length).toBe(0);
401
+ });
402
+
403
+ it('closes tab via keyboard Enter on close button', () => {
404
+ mockTabBarState.mockReturnValue({
405
+ ...defaultTabBarState,
406
+ tabs: [
407
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
408
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
409
+ ],
410
+ });
411
+ const dragTabIdRef = { current: null };
412
+ act(() => {
413
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
414
+ });
415
+ const closeSpan = container.querySelector('.queryTabClose') as HTMLElement;
416
+ expect(closeSpan).toBeTruthy();
417
+ act(() => {
418
+ closeSpan.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
419
+ });
420
+ expect(mockTabBarDispatch).toHaveBeenCalledWith(expect.objectContaining({ type: 'CLOSE_TAB' }));
421
+ });
422
+
423
+ it('closes tab via keyboard Space on close button', () => {
424
+ mockTabBarState.mockReturnValue({
425
+ ...defaultTabBarState,
426
+ tabs: [
427
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
428
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
429
+ ],
430
+ });
431
+ const dragTabIdRef = { current: null };
432
+ act(() => {
433
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
434
+ });
435
+ const closeSpan = container.querySelector('.queryTabClose') as HTMLElement;
436
+ expect(closeSpan).toBeTruthy();
437
+ act(() => {
438
+ closeSpan.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));
439
+ });
440
+ expect(mockTabBarDispatch).toHaveBeenCalledWith(expect.objectContaining({ type: 'CLOSE_TAB' }));
441
+ });
442
+
443
+ it('does not close tab on unrelated key on close button', () => {
444
+ mockTabBarState.mockReturnValue({
445
+ ...defaultTabBarState,
446
+ tabs: [
447
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
448
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
449
+ ],
450
+ });
451
+ const dragTabIdRef = { current: null };
452
+ act(() => {
453
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
454
+ });
455
+ const closeSpan = container.querySelector('.queryTabClose') as HTMLElement;
456
+ expect(closeSpan).toBeTruthy();
457
+ mockTabBarDispatch.mockClear();
458
+ act(() => {
459
+ closeSpan.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true }));
460
+ });
461
+ expect(mockTabBarDispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'CLOSE_TAB' }));
462
+ });
463
+
464
+ it('handles drag start, drag over, drop, and drag end', () => {
465
+ mockTabBarState.mockReturnValue({
466
+ ...defaultTabBarState,
467
+ tabs: [
468
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
469
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
470
+ { id: '3', query: '', title: 'Tab 3', connectionId: 'test-conn', kql: '' },
471
+ ],
472
+ });
473
+ const dragTabIdRef: { current: string | null } = { current: null };
474
+ const onSetEditorDropTarget = vi.fn();
475
+ act(() => {
476
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget }));
477
+ });
478
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
479
+ const tab1 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 1')) as HTMLElement;
480
+ const tab3 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 3')) as HTMLElement;
481
+ expect(tab1).toBeTruthy();
482
+ expect(tab3).toBeTruthy();
483
+
484
+ // Drag start on first tab
485
+ const dragStartEvent = new Event('dragstart', { bubbles: true });
486
+ (dragStartEvent as unknown as Record<string, unknown>)['dataTransfer'] = { setData: vi.fn(), effectAllowed: '' };
487
+ act(() => {
488
+ tab1.dispatchEvent(dragStartEvent);
489
+ });
490
+ expect(dragTabIdRef.current).toBe('1');
491
+
492
+ // Drag over third tab
493
+ const dragOverEvent = new Event('dragover', { bubbles: true, cancelable: true });
494
+ (dragOverEvent as unknown as Record<string, unknown>)['dataTransfer'] = { dropEffect: '' };
495
+ act(() => {
496
+ tab3.dispatchEvent(dragOverEvent);
497
+ });
498
+
499
+ // Drop on third tab
500
+ act(() => {
501
+ tab3.dispatchEvent(new Event('drop', { bubbles: true }));
502
+ });
503
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'REORDER_TABS', fromIdx: 0, toIdx: 2 });
504
+
505
+ // Drag end
506
+ act(() => {
507
+ tab1.dispatchEvent(new Event('dragend', { bubbles: true }));
508
+ });
509
+ expect(dragTabIdRef.current).toBeNull();
510
+ expect(onSetEditorDropTarget).toHaveBeenCalledWith(null);
511
+ });
512
+
513
+ it('does not reorder when dropping on same position', () => {
514
+ mockTabBarState.mockReturnValue({
515
+ ...defaultTabBarState,
516
+ tabs: [
517
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
518
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
519
+ ],
520
+ });
521
+ const dragTabIdRef: { current: string | null } = { current: null };
522
+ act(() => {
523
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
524
+ });
525
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
526
+ const tab1 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 1')) as HTMLElement;
527
+
528
+ const dragStart = new Event('dragstart', { bubbles: true });
529
+ (dragStart as unknown as Record<string, unknown>)['dataTransfer'] = { setData: vi.fn(), effectAllowed: '' };
530
+ act(() => {
531
+ tab1.dispatchEvent(dragStart);
532
+ });
533
+ mockTabBarDispatch.mockClear();
534
+ act(() => {
535
+ tab1.dispatchEvent(new Event('drop', { bubbles: true }));
536
+ });
537
+ expect(mockTabBarDispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'REORDER_TABS' }));
538
+ });
539
+
540
+ it('renames from context menu', () => {
541
+ const dragTabIdRef = { current: null };
542
+ act(() => {
543
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
544
+ });
545
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
546
+ act(() => {
547
+ tabEl.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
548
+ });
549
+ const renameItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Rename') as HTMLElement;
550
+ expect(renameItem).toBeTruthy();
551
+ act(() => {
552
+ renameItem.click();
553
+ });
554
+ const input = container.querySelector('input');
555
+ expect(input).toBeTruthy();
556
+ });
557
+
558
+ it('closes from context menu with multiple tabs', () => {
559
+ mockTabBarState.mockReturnValue({
560
+ ...defaultTabBarState,
561
+ tabs: [
562
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
563
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
564
+ ],
565
+ });
566
+ const dragTabIdRef = { current: null };
567
+ act(() => {
568
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
569
+ });
570
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
571
+ const tab2 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 2')) as HTMLElement;
572
+ act(() => {
573
+ tab2.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
574
+ });
575
+ const closeItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Close') as HTMLElement;
576
+ expect(closeItem).toBeTruthy();
577
+ act(() => {
578
+ closeItem.click();
579
+ });
580
+ // Tab has no content so it closes directly
581
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'CLOSE_TAB', tabId: '2' });
582
+ });
583
+
584
+ it('does not show close in context menu for single tab', () => {
585
+ mockTabBarState.mockReturnValue({
586
+ ...defaultTabBarState,
587
+ tabs: [{ id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' }],
588
+ });
589
+ const dragTabIdRef = { current: null };
590
+ act(() => {
591
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
592
+ });
593
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
594
+ act(() => {
595
+ tabEl.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
596
+ });
597
+ const closeItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Close');
598
+ expect(closeItem).toBeUndefined();
599
+ });
600
+
601
+ it('closes context menu on document click', () => {
602
+ const dragTabIdRef = { current: null };
603
+ act(() => {
604
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
605
+ });
606
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
607
+ act(() => {
608
+ tabEl.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
609
+ });
610
+ expect(container.textContent).toContain('Rename');
611
+ act(() => {
612
+ document.dispatchEvent(new MouseEvent('click', { bubbles: true }));
613
+ });
614
+ const renameItem = Array.from(container.querySelectorAll('[tabindex="0"]')).find((el) => el.textContent === 'Rename');
615
+ expect(renameItem).toBeUndefined();
616
+ });
617
+
618
+ it('tab is not draggable when renaming', () => {
619
+ const dragTabIdRef = { current: null };
620
+ act(() => {
621
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
622
+ });
623
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
624
+ expect(tabEl.getAttribute('draggable')).toBe('true');
625
+ act(() => {
626
+ tabEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
627
+ });
628
+ const tabAfterRename = container.querySelector('[tabindex="0"]') as HTMLElement;
629
+ expect(tabAfterRename.getAttribute('draggable')).toBe('false');
630
+ });
631
+
632
+ it('does not show primary marker when split is disabled', () => {
633
+ mockTabBarState.mockReturnValue({
634
+ ...defaultTabBarState,
635
+ tabs: [
636
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
637
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
638
+ ],
639
+ splitEnabled: false,
640
+ });
641
+ const dragTabIdRef = { current: null };
642
+ act(() => {
643
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
644
+ });
645
+ expect(container.textContent).not.toContain('\u2460');
646
+ expect(container.textContent).not.toContain('\u2461');
647
+ });
648
+
649
+ it('marks secondary pane tab as active when focusedPane is secondary', () => {
650
+ mockTabBarState.mockReturnValue({
651
+ ...defaultTabBarState,
652
+ tabs: [
653
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
654
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
655
+ ],
656
+ splitEnabled: true,
657
+ splitTabId: '2',
658
+ focusedPane: 'secondary' as const,
659
+ });
660
+ const dragTabIdRef = { current: null };
661
+ act(() => {
662
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
663
+ });
664
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
665
+ const tab2 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 2')) as HTMLElement;
666
+ expect(tab2).toBeTruthy();
667
+ expect(tab2.className).toBe('queryTabActive');
668
+ });
669
+
670
+ it('applies activeFilter class to split vertical button when split is vertical', () => {
671
+ mockTabBarState.mockReturnValue({
672
+ ...defaultTabBarState,
673
+ splitEnabled: true,
674
+ splitDirection: 'vertical' as const,
675
+ splitTabId: '1',
676
+ });
677
+ const dragTabIdRef = { current: null };
678
+ act(() => {
679
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
680
+ });
681
+ const buttons = container.querySelectorAll('button');
682
+ const splitVertBtn = buttons[buttons.length - 2];
683
+ expect(splitVertBtn.className).toBe('activeFilter');
684
+ });
685
+
686
+ it('applies activeFilter class to split horizontal button when split is horizontal', () => {
687
+ mockTabBarState.mockReturnValue({
688
+ ...defaultTabBarState,
689
+ splitEnabled: true,
690
+ splitDirection: 'horizontal' as const,
691
+ splitTabId: '1',
692
+ });
693
+ const dragTabIdRef = { current: null };
694
+ act(() => {
695
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
696
+ });
697
+ const buttons = container.querySelectorAll('button');
698
+ const splitHorizBtn = buttons[buttons.length - 1];
699
+ expect(splitHorizBtn.className).toBe('activeFilter');
700
+ });
701
+
702
+ it('renders zero tabs without crashing', () => {
703
+ mockTabBarState.mockReturnValue({
704
+ ...defaultTabBarState,
705
+ tabs: [],
706
+ activeTabId: '',
707
+ });
708
+ const dragTabIdRef = { current: null };
709
+ act(() => {
710
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
711
+ });
712
+ expect(container.innerHTML).not.toBe('');
713
+ const tabItems = container.querySelectorAll('[draggable]');
714
+ expect(tabItems.length).toBe(0);
715
+ });
716
+
717
+ it('does not dispatch close when unrelated key pressed on context menu items', () => {
718
+ mockTabBarState.mockReturnValue({
719
+ ...defaultTabBarState,
720
+ tabs: [
721
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
722
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
723
+ ],
724
+ });
725
+ const dragTabIdRef = { current: null };
726
+ act(() => {
727
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
728
+ });
729
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
730
+ act(() => {
731
+ tabEl.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
732
+ });
733
+ // Fluent UI Menu handles keyboard nav internally; just verify the menu rendered
734
+ const closeItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Close');
735
+ expect(closeItem).toBeTruthy();
736
+ mockTabBarDispatch.mockClear();
737
+ // Pressing Tab key should not trigger any dispatch
738
+ act(() => {
739
+ closeItem!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true }));
740
+ });
741
+ expect(mockTabBarDispatch).not.toHaveBeenCalled();
742
+ });
743
+
744
+ it('duplicates from context menu', () => {
745
+ const dragTabIdRef = { current: null };
746
+ act(() => {
747
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
748
+ });
749
+ const tabEl = container.querySelector('[tabindex="0"]') as HTMLElement;
750
+ act(() => {
751
+ tabEl.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
752
+ });
753
+ const dupItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Duplicate') as HTMLElement;
754
+ expect(dupItem).toBeTruthy();
755
+ act(() => {
756
+ dupItem.click();
757
+ });
758
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'DUPLICATE_TAB', tabId: '1' });
759
+ });
760
+
761
+ it('shows confirmation dialog when closing tab with content', () => {
762
+ mockTabBarState.mockReturnValue({
763
+ ...defaultTabBarState,
764
+ tabs: [
765
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: 'StormEvents | take 10' },
766
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
767
+ ],
768
+ });
769
+ const dragTabIdRef = { current: null };
770
+ act(() => {
771
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
772
+ });
773
+ // Click close on Tab 1 (has content)
774
+ const closeSpan = container.querySelector('.queryTabClose') as HTMLElement;
775
+ act(() => {
776
+ closeSpan.click();
777
+ });
778
+ // Should show dialog, not dispatch close yet
779
+ expect(container.textContent).toContain('Close tab?');
780
+ expect(mockTabBarDispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'CLOSE_TAB' }));
781
+ });
782
+
783
+ it('confirms close dialog dispatches CLOSE_TAB', () => {
784
+ mockTabBarState.mockReturnValue({
785
+ ...defaultTabBarState,
786
+ tabs: [
787
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: 'StormEvents' },
788
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
789
+ ],
790
+ });
791
+ const dragTabIdRef = { current: null };
792
+ act(() => {
793
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
794
+ });
795
+ const closeSpan = container.querySelector('.queryTabClose') as HTMLElement;
796
+ act(() => {
797
+ closeSpan.click();
798
+ });
799
+ // Click the Close button in the dialog
800
+ const closeBtn = Array.from(container.querySelectorAll('button')).find((el) => el.textContent === 'Close') as HTMLElement;
801
+ expect(closeBtn).toBeTruthy();
802
+ act(() => {
803
+ closeBtn.click();
804
+ });
805
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'CLOSE_TAB', tabId: '1' });
806
+ });
807
+
808
+ it('close others shows confirmation when tabs have content', () => {
809
+ mockTabBarState.mockReturnValue({
810
+ ...defaultTabBarState,
811
+ tabs: [
812
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: 'query1' },
813
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: 'query2' },
814
+ ],
815
+ });
816
+ const dragTabIdRef = { current: null };
817
+ act(() => {
818
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
819
+ });
820
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
821
+ const tab1 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 1')) as HTMLElement;
822
+ act(() => {
823
+ tab1.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
824
+ });
825
+ const closeOthersItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Close Others') as HTMLElement;
826
+ expect(closeOthersItem).toBeTruthy();
827
+ act(() => {
828
+ closeOthersItem.click();
829
+ });
830
+ expect(container.textContent).toContain('Close other tabs?');
831
+ });
832
+
833
+ it('middle-click closes empty tab', () => {
834
+ mockTabBarState.mockReturnValue({
835
+ ...defaultTabBarState,
836
+ tabs: [
837
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: '' },
838
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
839
+ ],
840
+ });
841
+ const dragTabIdRef = { current: null };
842
+ act(() => {
843
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
844
+ });
845
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
846
+ const tab2 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 2')) as HTMLElement;
847
+ act(() => {
848
+ tab2.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, button: 1 }));
849
+ });
850
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'CLOSE_TAB', tabId: '2' });
851
+ });
852
+
853
+ it('cancel close dialog does not dispatch', () => {
854
+ mockTabBarState.mockReturnValue({
855
+ ...defaultTabBarState,
856
+ tabs: [
857
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: 'some query' },
858
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
859
+ ],
860
+ });
861
+ const dragTabIdRef = { current: null };
862
+ act(() => {
863
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
864
+ });
865
+ const closeSpan = container.querySelector('.queryTabClose') as HTMLElement;
866
+ act(() => {
867
+ closeSpan.click();
868
+ });
869
+ expect(container.textContent).toContain('Close tab?');
870
+ const cancelBtn = Array.from(container.querySelectorAll('button')).find((el) => el.textContent === 'Cancel') as HTMLElement;
871
+ act(() => {
872
+ cancelBtn.click();
873
+ });
874
+ expect(mockTabBarDispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'CLOSE_TAB' }));
875
+ });
876
+
877
+ it('confirm close others dispatches CLOSE_OTHER_TABS', () => {
878
+ mockTabBarState.mockReturnValue({
879
+ ...defaultTabBarState,
880
+ tabs: [
881
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: 'query1' },
882
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: 'query2' },
883
+ ],
884
+ });
885
+ const dragTabIdRef = { current: null };
886
+ act(() => {
887
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
888
+ });
889
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
890
+ const tab1 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 1')) as HTMLElement;
891
+ act(() => {
892
+ tab1.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
893
+ });
894
+ const closeOthersItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Close Others') as HTMLElement;
895
+ act(() => {
896
+ closeOthersItem.click();
897
+ });
898
+ const confirmBtn = Array.from(container.querySelectorAll('button')).find((el) => el.textContent === 'Close Others') as HTMLElement;
899
+ expect(confirmBtn).toBeTruthy();
900
+ act(() => {
901
+ confirmBtn.click();
902
+ });
903
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'CLOSE_OTHER_TABS', tabId: '1' });
904
+ });
905
+
906
+ it('close others skips dialog when other tabs are empty', () => {
907
+ mockTabBarState.mockReturnValue({
908
+ ...defaultTabBarState,
909
+ tabs: [
910
+ { id: '1', query: '', title: 'Tab 1', connectionId: 'test-conn', kql: 'query1' },
911
+ { id: '2', query: '', title: 'Tab 2', connectionId: 'test-conn', kql: '' },
912
+ ],
913
+ });
914
+ const dragTabIdRef = { current: null };
915
+ act(() => {
916
+ root.render(React.createElement(TabBar, { dragTabIdRef, onSetEditorDropTarget: vi.fn() }));
917
+ });
918
+ const tabEls = container.querySelectorAll('[tabindex="0"]');
919
+ const tab1 = Array.from(tabEls).find((el) => el.textContent?.includes('Tab 1')) as HTMLElement;
920
+ act(() => {
921
+ tab1.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 50, clientY: 50 }));
922
+ });
923
+ const closeOthersItem = Array.from(container.querySelectorAll('div')).find((el) => el.textContent === 'Close Others') as HTMLElement;
924
+ act(() => {
925
+ closeOthersItem.click();
926
+ });
927
+ expect(mockTabBarDispatch).toHaveBeenCalledWith({ type: 'CLOSE_OTHER_TABS', tabId: '1' });
928
+ });
929
+ });