@mhjuma/traverse 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +46 -0
- package/src/bootstrap.spec.tsx +290 -0
- package/src/bootstrap.tsx +195 -0
- package/src/colors.ts +23 -0
- package/src/components/ChartPanel/ChartPanel.logic.spec.ts +358 -0
- package/src/components/ChartPanel/ChartPanel.logic.ts +318 -0
- package/src/components/ChartPanel/ChartPanel.spec.tsx +331 -0
- package/src/components/ChartPanel/ChartPanel.styles.ts +14 -0
- package/src/components/ChartPanel/ChartPanel.tsx +151 -0
- package/src/components/ConnectionDialog/ConnectionDialog.spec.tsx +767 -0
- package/src/components/ConnectionDialog/ConnectionDialog.tsx +652 -0
- package/src/components/ConnectionDialog/ConnectionRow.spec.tsx +104 -0
- package/src/components/ConnectionDialog/ConnectionRow.tsx +177 -0
- package/src/components/EditorToolbar/EditorToolbar.spec.tsx +599 -0
- package/src/components/EditorToolbar/EditorToolbar.tsx +259 -0
- package/src/components/Explorer/Explorer.spec.tsx +615 -0
- package/src/components/Explorer/Explorer.tsx +49 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.spec.ts +715 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.ts +324 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.spec.tsx +450 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.styles.ts +478 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.tsx +648 -0
- package/src/components/ExplorerWorkspace/kqlLanguage.spec.ts +321 -0
- package/src/components/ExplorerWorkspace/kqlLanguage.ts +155 -0
- package/src/components/ResultsPanel/ElapsedTimer.spec.tsx +51 -0
- package/src/components/ResultsPanel/ElapsedTimer.tsx +15 -0
- package/src/components/ResultsPanel/HistoryItem.spec.tsx +123 -0
- package/src/components/ResultsPanel/HistoryItem.tsx +56 -0
- package/src/components/ResultsPanel/ResultSetTab.tsx +18 -0
- package/src/components/ResultsPanel/ResultsPanel.spec.tsx +1194 -0
- package/src/components/ResultsPanel/ResultsPanel.tsx +321 -0
- package/src/components/ResultsPanel/TabButton.tsx +11 -0
- package/src/components/ResultsTable/ColumnHeader.tsx +42 -0
- package/src/components/ResultsTable/ColumnPickerItem.tsx +16 -0
- package/src/components/ResultsTable/FilterCell.tsx +24 -0
- package/src/components/ResultsTable/ResultsTable.logic.spec.ts +655 -0
- package/src/components/ResultsTable/ResultsTable.logic.ts +264 -0
- package/src/components/ResultsTable/ResultsTable.spec.tsx +930 -0
- package/src/components/ResultsTable/ResultsTable.styles.ts +108 -0
- package/src/components/ResultsTable/ResultsTable.tsx +501 -0
- package/src/components/ResultsTable/VirtualCell.spec.tsx +55 -0
- package/src/components/ResultsTable/VirtualCell.tsx +32 -0
- package/src/components/ResultsTable/VirtualRow.tsx +55 -0
- package/src/components/SchemaSidebar/FolderRow.tsx +35 -0
- package/src/components/SchemaSidebar/SchemaColumnItem.tsx +41 -0
- package/src/components/SchemaSidebar/SchemaContextMenu.spec.tsx +148 -0
- package/src/components/SchemaSidebar/SchemaContextMenu.tsx +49 -0
- package/src/components/SchemaSidebar/SchemaSidebar.logic.spec.ts +230 -0
- package/src/components/SchemaSidebar/SchemaSidebar.logic.ts +74 -0
- package/src/components/SchemaSidebar/SchemaSidebar.spec.tsx +1111 -0
- package/src/components/SchemaSidebar/SchemaSidebar.tsx +244 -0
- package/src/components/SchemaSidebar/SchemaTableItem.tsx +77 -0
- package/src/components/TabBar/TabBar.logic.spec.ts +127 -0
- package/src/components/TabBar/TabBar.logic.ts +35 -0
- package/src/components/TabBar/TabBar.spec.tsx +929 -0
- package/src/components/TabBar/TabBar.tsx +284 -0
- package/src/components/TabBar/TabItem.tsx +166 -0
- package/src/components/VegaChart/VegaChart.spec.tsx +126 -0
- package/src/components/VegaChart/VegaChart.tsx +224 -0
- package/src/config.spec.ts +44 -0
- package/src/config.ts +47 -0
- package/src/context/ExplorerColorContext.ts +14 -0
- package/src/context/ExplorerStateContext.ts +49 -0
- package/src/context/KustoClientContext.ts +12 -0
- package/src/context/context.spec.tsx +183 -0
- package/src/index.ts +14 -0
- package/src/services/cache.spec.ts +31 -0
- package/src/services/cache.ts +16 -0
- package/src/services/concurrency.spec.ts +139 -0
- package/src/services/concurrency.ts +46 -0
- package/src/services/kusto.spec.ts +919 -0
- package/src/services/kusto.ts +472 -0
- package/src/services/queryHistory.spec.ts +287 -0
- package/src/services/queryHistory.ts +146 -0
- package/src/services/schema.spec.ts +618 -0
- package/src/services/schema.ts +294 -0
- package/src/services/state-service.spec.ts +670 -0
- package/src/services/state-service.ts +602 -0
- package/src/services/useKustoQuery.spec.ts +234 -0
- package/src/services/useKustoQuery.ts +124 -0
- package/src/state/actions.ts +50 -0
- package/src/state/index.ts +3 -0
- package/src/state/reducer.spec.ts +644 -0
- package/src/state/reducer.ts +207 -0
- package/src/state/types.ts +54 -0
- package/tsconfig.json +7 -0
- package/tsconfig.lint.json +4 -0
- package/tsconfig.spec.json +7 -0
- package/vitest.config.ts +34 -0
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
+
import { createInitialState, explorerReducer } from './reducer';
|
|
3
|
+
import type { ExplorerState, ExplorerAction } from './index';
|
|
4
|
+
|
|
5
|
+
vi.mock('../services/state-service', () => ({
|
|
6
|
+
stateService: {
|
|
7
|
+
get: (_store: string, key: string) => mockStore.get(key) ?? null,
|
|
8
|
+
set: (_store: string, key: string, value: unknown) => { mockStore.set(key, value); },
|
|
9
|
+
delete: (_store: string, key: string) => { mockStore.delete(key); },
|
|
10
|
+
subscribe: () => () => {},
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const mockStore = new Map<string, unknown>();
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// createInitialState
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
describe('createInitialState', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
mockStore.clear();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('creates state with the given initial query', () => {
|
|
28
|
+
const state = createInitialState({ initialQuery: 'Table | take 10', defaultClusters: [] });
|
|
29
|
+
expect(state.tabs).toHaveLength(1);
|
|
30
|
+
expect(state.tabs[0].kql).toBe('Table | take 10');
|
|
31
|
+
expect(state.tabs[0].title).toMatch(/Query/);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('sets default values for all fields', () => {
|
|
35
|
+
const state = createInitialState({ initialQuery: '', defaultClusters: [] });
|
|
36
|
+
expect(state.schema).toEqual([]);
|
|
37
|
+
expect(state.schemaSearch).toBe('');
|
|
38
|
+
expect(state.expandedFolders).toBeInstanceOf(Set);
|
|
39
|
+
expect(state.expandedFolders.size).toBe(0);
|
|
40
|
+
expect(state.expandedTables).toBeInstanceOf(Set);
|
|
41
|
+
expect(state.expandedTables.size).toBe(0);
|
|
42
|
+
expect(state.schemaContextMenu).toBeNull();
|
|
43
|
+
|
|
44
|
+
expect(state.activeTabId).toBe(state.tabs[0].id);
|
|
45
|
+
expect(state.splitEnabled).toBe(false);
|
|
46
|
+
expect(state.splitDirection).toBe('vertical');
|
|
47
|
+
expect(state.splitTabId).toBeNull();
|
|
48
|
+
expect(state.focusedPane).toBe('primary');
|
|
49
|
+
|
|
50
|
+
expect(state.loading).toBe(false);
|
|
51
|
+
expect(state.error).toBeNull();
|
|
52
|
+
expect(state.queryStartTime).toBeNull();
|
|
53
|
+
expect(state.runningQueryKey).toBeNull();
|
|
54
|
+
|
|
55
|
+
expect(state.rows).toBeNull();
|
|
56
|
+
expect(state.columns).toEqual([]);
|
|
57
|
+
expect(state.columnTypes).toEqual({});
|
|
58
|
+
expect(state.elapsed).toBeNull();
|
|
59
|
+
expect(state.resultTime).toBeNull();
|
|
60
|
+
expect(state.queryStats).toBeNull();
|
|
61
|
+
expect(state.resultSets).toEqual([]);
|
|
62
|
+
expect(state.activeResultSet).toBe(0);
|
|
63
|
+
expect(state.resultsTab).toBe('results');
|
|
64
|
+
|
|
65
|
+
expect(state.history).toEqual([]);
|
|
66
|
+
|
|
67
|
+
expect(state.editorHeight).toBe(50);
|
|
68
|
+
expect(state.hasSelection).toBe(false);
|
|
69
|
+
expect(state.canRecall).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('restores the persisted active connection for the first tab', () => {
|
|
73
|
+
mockStore.set('list', [
|
|
74
|
+
{ id: 'conn-1', name: 'Cluster A', clusterUrl: 'https://a.kusto.windows.net', database: 'DbA', color: '#909d63' },
|
|
75
|
+
{ id: 'conn-2', name: 'Cluster B', clusterUrl: 'https://b.kusto.windows.net', database: 'DbB', color: '#6a8799' },
|
|
76
|
+
]);
|
|
77
|
+
mockStore.set('explorer-active-connection', 'conn-2');
|
|
78
|
+
|
|
79
|
+
const state = createInitialState({ initialQuery: 'Table | take 10', defaultClusters: [] });
|
|
80
|
+
|
|
81
|
+
expect(state.tabs[0].connectionId).toBe('conn-2');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('falls back to the first connection when the persisted active connection is invalid', () => {
|
|
85
|
+
mockStore.set('list', [
|
|
86
|
+
{ id: 'conn-1', name: 'Cluster A', clusterUrl: 'https://a.kusto.windows.net', database: 'DbA', color: '#909d63' },
|
|
87
|
+
{ id: 'conn-2', name: 'Cluster B', clusterUrl: 'https://b.kusto.windows.net', database: 'DbB', color: '#6a8799' },
|
|
88
|
+
]);
|
|
89
|
+
mockStore.set('explorer-active-connection', 'missing');
|
|
90
|
+
|
|
91
|
+
const state = createInitialState({ initialQuery: 'Table | take 10', defaultClusters: [] });
|
|
92
|
+
|
|
93
|
+
expect(state.tabs[0].connectionId).toBe('conn-1');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// explorerReducer
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
describe('explorerReducer', () => {
|
|
102
|
+
const makeState = (overrides?: Partial<ExplorerState>): ExplorerState => ({
|
|
103
|
+
...createInitialState({ initialQuery: '', defaultClusters: [] }),
|
|
104
|
+
...overrides,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// --- Schema ---
|
|
108
|
+
|
|
109
|
+
describe('SET_SCHEMA', () => {
|
|
110
|
+
it('sets schema', () => {
|
|
111
|
+
const schema = [{ name: 'T1', folder: 'F', description: '', columns: [], kind: 'table' as const }];
|
|
112
|
+
const state = explorerReducer(makeState(), { type: 'SET_SCHEMA', schema });
|
|
113
|
+
expect(state.schema).toBe(schema);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('SET_SCHEMA_SEARCH', () => {
|
|
118
|
+
it('sets search string', () => {
|
|
119
|
+
const state = explorerReducer(makeState(), { type: 'SET_SCHEMA_SEARCH', search: 'foo' });
|
|
120
|
+
expect(state.schemaSearch).toBe('foo');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('TOGGLE_FOLDER', () => {
|
|
125
|
+
it('adds folder to expanded set', () => {
|
|
126
|
+
const state = explorerReducer(makeState(), { type: 'TOGGLE_FOLDER', folder: 'F1' });
|
|
127
|
+
expect(state.expandedFolders.has('F1')).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('removes folder from expanded set', () => {
|
|
131
|
+
const initial = makeState({ expandedFolders: new Set(['F1']) });
|
|
132
|
+
const state = explorerReducer(initial, { type: 'TOGGLE_FOLDER', folder: 'F1' });
|
|
133
|
+
expect(state.expandedFolders.has('F1')).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('TOGGLE_TABLE', () => {
|
|
138
|
+
it('adds table to expanded set', () => {
|
|
139
|
+
const state = explorerReducer(makeState(), { type: 'TOGGLE_TABLE', table: 'T1' });
|
|
140
|
+
expect(state.expandedTables.has('T1')).toBe(true);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('removes table from expanded set', () => {
|
|
144
|
+
const initial = makeState({ expandedTables: new Set(['T1']) });
|
|
145
|
+
const state = explorerReducer(initial, { type: 'TOGGLE_TABLE', table: 'T1' });
|
|
146
|
+
expect(state.expandedTables.has('T1')).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('EXPAND_ALL_FOLDERS', () => {
|
|
151
|
+
it('expands all folders and tables', () => {
|
|
152
|
+
const schema = [
|
|
153
|
+
{ name: 'T1', folder: 'F1', description: '', columns: [], kind: 'table' as const },
|
|
154
|
+
{ name: 'T2', folder: 'F2', description: '', columns: [], kind: 'table' as const },
|
|
155
|
+
];
|
|
156
|
+
const initial = makeState({ schema });
|
|
157
|
+
const state = explorerReducer(initial, { type: 'EXPAND_ALL_FOLDERS', folders: ['F1', 'F2'] });
|
|
158
|
+
expect(state.expandedFolders).toEqual(new Set(['F1', 'F2']));
|
|
159
|
+
expect(state.expandedTables).toEqual(new Set(['T1', 'T2']));
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('COLLAPSE_ALL_FOLDERS', () => {
|
|
164
|
+
it('collapses all folders and tables', () => {
|
|
165
|
+
const initial = makeState({
|
|
166
|
+
expandedFolders: new Set(['F1', 'F2']),
|
|
167
|
+
expandedTables: new Set(['T1', 'T2']),
|
|
168
|
+
});
|
|
169
|
+
const state = explorerReducer(initial, { type: 'COLLAPSE_ALL_FOLDERS' });
|
|
170
|
+
expect(state.expandedFolders.size).toBe(0);
|
|
171
|
+
expect(state.expandedTables.size).toBe(0);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('SET_SCHEMA_CONTEXT_MENU', () => {
|
|
176
|
+
it('sets context menu', () => {
|
|
177
|
+
const menu = { tableName: 'T1', x: 100, y: 200 };
|
|
178
|
+
const state = explorerReducer(makeState(), { type: 'SET_SCHEMA_CONTEXT_MENU', menu });
|
|
179
|
+
expect(state.schemaContextMenu).toEqual(menu);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('clears context menu with null', () => {
|
|
183
|
+
const initial = makeState({ schemaContextMenu: { tableName: 'T1', x: 0, y: 0 } });
|
|
184
|
+
const state = explorerReducer(initial, { type: 'SET_SCHEMA_CONTEXT_MENU', menu: null });
|
|
185
|
+
expect(state.schemaContextMenu).toBeNull();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// --- Tabs ---
|
|
190
|
+
|
|
191
|
+
describe('ADD_TAB', () => {
|
|
192
|
+
it('adds a new tab and makes it active', () => {
|
|
193
|
+
const initial = makeState();
|
|
194
|
+
const state = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
195
|
+
expect(state.tabs).toHaveLength(2);
|
|
196
|
+
expect(state.activeTabId).toBe(state.tabs[1].id);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('CLOSE_TAB', () => {
|
|
201
|
+
it('does not close the last tab', () => {
|
|
202
|
+
const initial = makeState();
|
|
203
|
+
const state = explorerReducer(initial, { type: 'CLOSE_TAB', tabId: initial.tabs[0].id });
|
|
204
|
+
expect(state.tabs).toHaveLength(1);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('closes a non-active tab', () => {
|
|
208
|
+
const initial = makeState();
|
|
209
|
+
const withTwo = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
210
|
+
const state = explorerReducer(withTwo, { type: 'CLOSE_TAB', tabId: withTwo.tabs[0].id });
|
|
211
|
+
expect(state.tabs).toHaveLength(1);
|
|
212
|
+
expect(state.tabs[0].id).toBe(withTwo.tabs[1].id);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('updates active tab when closing active tab', () => {
|
|
216
|
+
const initial = makeState();
|
|
217
|
+
const withTwo = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
218
|
+
const state = explorerReducer(withTwo, { type: 'CLOSE_TAB', tabId: withTwo.activeTabId });
|
|
219
|
+
expect(state.tabs).toHaveLength(1);
|
|
220
|
+
expect(state.activeTabId).toBe(state.tabs[0].id);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('disables split when closing split tab', () => {
|
|
224
|
+
const initial = makeState();
|
|
225
|
+
const withTwo = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
226
|
+
const withSplit: ExplorerState = {
|
|
227
|
+
...withTwo,
|
|
228
|
+
splitEnabled: true,
|
|
229
|
+
splitTabId: withTwo.tabs[1].id,
|
|
230
|
+
};
|
|
231
|
+
const state = explorerReducer(withSplit, { type: 'CLOSE_TAB', tabId: withTwo.tabs[1].id });
|
|
232
|
+
expect(state.splitEnabled).toBe(false);
|
|
233
|
+
expect(state.splitTabId).toBeNull();
|
|
234
|
+
expect(state.focusedPane).toBe('primary');
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('disables split when closing active tab leaves splitTabId === activeTabId', () => {
|
|
238
|
+
const initial = makeState();
|
|
239
|
+
const s1 = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
240
|
+
const s2 = explorerReducer(s1, { type: 'ADD_TAB' });
|
|
241
|
+
// tabs: [0, 1, 2], active = 2, split = 0
|
|
242
|
+
const withSplit: ExplorerState = {
|
|
243
|
+
...s2,
|
|
244
|
+
splitEnabled: true,
|
|
245
|
+
splitTabId: s2.tabs[0].id,
|
|
246
|
+
activeTabId: s2.tabs[1].id,
|
|
247
|
+
};
|
|
248
|
+
// Closing tab[1] (active) should set active to tab[0], which matches splitTabId
|
|
249
|
+
const state = explorerReducer(withSplit, { type: 'CLOSE_TAB', tabId: s2.tabs[1].id });
|
|
250
|
+
if (state.activeTabId === state.splitTabId) {
|
|
251
|
+
expect(state.splitEnabled).toBe(false);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('SWITCH_TAB', () => {
|
|
257
|
+
it('switches active tab in primary pane', () => {
|
|
258
|
+
const initial = makeState();
|
|
259
|
+
const withTwo = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
260
|
+
const state = explorerReducer(
|
|
261
|
+
{ ...withTwo, focusedPane: 'primary' },
|
|
262
|
+
{ type: 'SWITCH_TAB', tabId: withTwo.tabs[0].id },
|
|
263
|
+
);
|
|
264
|
+
expect(state.activeTabId).toBe(withTwo.tabs[0].id);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('switches split tab in secondary pane', () => {
|
|
268
|
+
const initial = makeState();
|
|
269
|
+
const withTwo = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
270
|
+
const state = explorerReducer(
|
|
271
|
+
{ ...withTwo, focusedPane: 'secondary', splitTabId: withTwo.tabs[0].id },
|
|
272
|
+
{ type: 'SWITCH_TAB', tabId: withTwo.tabs[1].id },
|
|
273
|
+
);
|
|
274
|
+
expect(state.splitTabId).toBe(withTwo.tabs[1].id);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('UPDATE_TAB_KQL', () => {
|
|
279
|
+
it('updates KQL for specified tab', () => {
|
|
280
|
+
const initial = makeState();
|
|
281
|
+
const tabId = initial.tabs[0].id;
|
|
282
|
+
const state = explorerReducer(initial, { type: 'UPDATE_TAB_KQL', tabId, kql: 'new query' });
|
|
283
|
+
expect(state.tabs[0].kql).toBe('new query');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('does not affect other tabs', () => {
|
|
287
|
+
const initial = makeState();
|
|
288
|
+
const withTwo = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
289
|
+
const state = explorerReducer(withTwo, {
|
|
290
|
+
type: 'UPDATE_TAB_KQL',
|
|
291
|
+
tabId: withTwo.tabs[0].id,
|
|
292
|
+
kql: 'updated',
|
|
293
|
+
});
|
|
294
|
+
expect(state.tabs[1].kql).toBe(withTwo.tabs[1].kql);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe('RENAME_TAB', () => {
|
|
299
|
+
it('renames specified tab', () => {
|
|
300
|
+
const initial = makeState();
|
|
301
|
+
const tabId = initial.tabs[0].id;
|
|
302
|
+
const state = explorerReducer(initial, { type: 'RENAME_TAB', tabId, title: 'My Query' });
|
|
303
|
+
expect(state.tabs[0].title).toBe('My Query');
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe('REORDER_TABS', () => {
|
|
308
|
+
it('moves a tab from one position to another', () => {
|
|
309
|
+
const initial = makeState();
|
|
310
|
+
const s1 = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
311
|
+
const s2 = explorerReducer(s1, { type: 'ADD_TAB' });
|
|
312
|
+
const firstId = s2.tabs[0].id;
|
|
313
|
+
const state = explorerReducer(s2, { type: 'REORDER_TABS', fromIdx: 0, toIdx: 2 });
|
|
314
|
+
expect(state.tabs[2].id).toBe(firstId);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// --- Split ---
|
|
319
|
+
|
|
320
|
+
describe('TOGGLE_SPLIT', () => {
|
|
321
|
+
it('enables split and creates new tab if needed', () => {
|
|
322
|
+
const initial = makeState();
|
|
323
|
+
const state = explorerReducer(initial, { type: 'TOGGLE_SPLIT', direction: 'vertical' });
|
|
324
|
+
expect(state.splitEnabled).toBe(true);
|
|
325
|
+
expect(state.splitDirection).toBe('vertical');
|
|
326
|
+
expect(state.splitTabId).not.toBeNull();
|
|
327
|
+
expect(state.tabs.length).toBeGreaterThan(initial.tabs.length);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('toggles off when same direction and already enabled', () => {
|
|
331
|
+
const initial = makeState();
|
|
332
|
+
const enabled = explorerReducer(initial, { type: 'TOGGLE_SPLIT', direction: 'vertical' });
|
|
333
|
+
const state = explorerReducer(enabled, { type: 'TOGGLE_SPLIT', direction: 'vertical' });
|
|
334
|
+
expect(state.splitEnabled).toBe(false);
|
|
335
|
+
expect(state.splitTabId).toBeNull();
|
|
336
|
+
expect(state.focusedPane).toBe('primary');
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('changes direction when different direction and already enabled', () => {
|
|
340
|
+
const initial = makeState();
|
|
341
|
+
const enabled = explorerReducer(initial, { type: 'TOGGLE_SPLIT', direction: 'vertical' });
|
|
342
|
+
const state = explorerReducer(enabled, { type: 'TOGGLE_SPLIT', direction: 'horizontal' });
|
|
343
|
+
expect(state.splitEnabled).toBe(true);
|
|
344
|
+
expect(state.splitDirection).toBe('horizontal');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('creates new tab when splitTabId equals activeTabId', () => {
|
|
348
|
+
const initial = makeState();
|
|
349
|
+
const withSplit: ExplorerState = {
|
|
350
|
+
...initial,
|
|
351
|
+
splitTabId: initial.activeTabId,
|
|
352
|
+
};
|
|
353
|
+
const state = explorerReducer(withSplit, { type: 'TOGGLE_SPLIT', direction: 'horizontal' });
|
|
354
|
+
expect(state.splitEnabled).toBe(true);
|
|
355
|
+
expect(state.splitTabId).not.toBe(initial.activeTabId);
|
|
356
|
+
expect(state.tabs.length).toBeGreaterThan(initial.tabs.length);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('keeps existing splitTabId when it differs from activeTabId', () => {
|
|
360
|
+
const initial = makeState();
|
|
361
|
+
const withTwo = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
362
|
+
const withSplit: ExplorerState = {
|
|
363
|
+
...withTwo,
|
|
364
|
+
splitEnabled: true,
|
|
365
|
+
splitDirection: 'vertical',
|
|
366
|
+
splitTabId: withTwo.tabs[1].id,
|
|
367
|
+
activeTabId: withTwo.tabs[0].id,
|
|
368
|
+
};
|
|
369
|
+
const state = explorerReducer(withSplit, { type: 'TOGGLE_SPLIT', direction: 'horizontal' });
|
|
370
|
+
expect(state.splitDirection).toBe('horizontal');
|
|
371
|
+
expect(state.tabs).toHaveLength(withTwo.tabs.length);
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('CLOSE_SPLIT', () => {
|
|
376
|
+
it('disables split', () => {
|
|
377
|
+
const initial = makeState();
|
|
378
|
+
const enabled = explorerReducer(initial, { type: 'TOGGLE_SPLIT', direction: 'vertical' });
|
|
379
|
+
const state = explorerReducer(enabled, { type: 'CLOSE_SPLIT' });
|
|
380
|
+
expect(state.splitEnabled).toBe(false);
|
|
381
|
+
expect(state.splitTabId).toBeNull();
|
|
382
|
+
expect(state.focusedPane).toBe('primary');
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe('SET_FOCUSED_PANE', () => {
|
|
387
|
+
it('sets focused pane to secondary', () => {
|
|
388
|
+
const state = explorerReducer(makeState(), { type: 'SET_FOCUSED_PANE', pane: 'secondary' });
|
|
389
|
+
expect(state.focusedPane).toBe('secondary');
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('sets focused pane to primary', () => {
|
|
393
|
+
const initial = makeState({ focusedPane: 'secondary' });
|
|
394
|
+
const state = explorerReducer(initial, { type: 'SET_FOCUSED_PANE', pane: 'primary' });
|
|
395
|
+
expect(state.focusedPane).toBe('primary');
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
describe('CLOSE_OTHER_TABS', () => {
|
|
400
|
+
it('keeps only the specified tab', () => {
|
|
401
|
+
const initial = makeState();
|
|
402
|
+
const s1 = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
403
|
+
const s2 = explorerReducer(s1, { type: 'ADD_TAB' });
|
|
404
|
+
const keptId = s2.tabs[1].id;
|
|
405
|
+
const state = explorerReducer(s2, { type: 'CLOSE_OTHER_TABS', tabId: keptId });
|
|
406
|
+
expect(state.tabs).toHaveLength(1);
|
|
407
|
+
expect(state.tabs[0].id).toBe(keptId);
|
|
408
|
+
expect(state.activeTabId).toBe(keptId);
|
|
409
|
+
expect(state.splitEnabled).toBe(false);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
describe('CLOSE_ALL_TABS', () => {
|
|
414
|
+
it('replaces all tabs with a fresh tab', () => {
|
|
415
|
+
const initial = makeState();
|
|
416
|
+
const s1 = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
417
|
+
const state = explorerReducer(s1, { type: 'CLOSE_ALL_TABS' });
|
|
418
|
+
expect(state.tabs).toHaveLength(1);
|
|
419
|
+
expect(state.tabs[0].title).toBe('Query 1');
|
|
420
|
+
expect(state.activeTabId).toBe(state.tabs[0].id);
|
|
421
|
+
expect(state.splitEnabled).toBe(false);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
describe('DUPLICATE_TAB', () => {
|
|
426
|
+
it('duplicates a tab with same KQL and connection', () => {
|
|
427
|
+
const initial = makeState();
|
|
428
|
+
const tabId = initial.tabs[0].id;
|
|
429
|
+
const updated = explorerReducer(initial, { type: 'UPDATE_TAB_KQL', tabId, kql: 'test query' });
|
|
430
|
+
const state = explorerReducer(updated, { type: 'DUPLICATE_TAB', tabId });
|
|
431
|
+
expect(state.tabs).toHaveLength(2);
|
|
432
|
+
expect(state.tabs[1].kql).toBe('test query');
|
|
433
|
+
expect(state.tabs[1].connectionId).toBe(initial.tabs[0].connectionId);
|
|
434
|
+
expect(state.tabs[1].id).not.toBe(tabId);
|
|
435
|
+
expect(state.activeTabId).toBe(state.tabs[1].id);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('inserts duplicate after the source tab', () => {
|
|
439
|
+
const initial = makeState();
|
|
440
|
+
const s1 = explorerReducer(initial, { type: 'ADD_TAB' });
|
|
441
|
+
const firstId = s1.tabs[0].id;
|
|
442
|
+
const state = explorerReducer(s1, { type: 'DUPLICATE_TAB', tabId: firstId });
|
|
443
|
+
expect(state.tabs).toHaveLength(3);
|
|
444
|
+
expect(state.tabs[0].id).toBe(firstId);
|
|
445
|
+
expect(state.tabs[1].kql).toBe(s1.tabs[0].kql);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// --- Query execution ---
|
|
450
|
+
|
|
451
|
+
describe('QUERY_START', () => {
|
|
452
|
+
it('sets loading state', () => {
|
|
453
|
+
const state = explorerReducer(makeState(), { type: 'QUERY_START', queryKey: 'q-1' });
|
|
454
|
+
expect(state.loading).toBe(true);
|
|
455
|
+
expect(state.error).toBeNull();
|
|
456
|
+
expect(state.queryStartTime).not.toBeNull();
|
|
457
|
+
expect(state.runningQueryKey).toBe('q-1');
|
|
458
|
+
expect(state.resultsTab).toBe('results');
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
describe('QUERY_SUCCESS', () => {
|
|
463
|
+
it('sets results and clears loading', () => {
|
|
464
|
+
const initial = makeState({ loading: true, queryStartTime: Date.now(), runningQueryKey: 'q-1' });
|
|
465
|
+
const state = explorerReducer(initial, {
|
|
466
|
+
type: 'QUERY_SUCCESS',
|
|
467
|
+
rows: [{ a: 1 }],
|
|
468
|
+
columns: ['a'],
|
|
469
|
+
columnTypes: { a: 'System.Int32' },
|
|
470
|
+
elapsed: 123,
|
|
471
|
+
stats: null,
|
|
472
|
+
resultSets: [],
|
|
473
|
+
});
|
|
474
|
+
expect(state.loading).toBe(false);
|
|
475
|
+
expect(state.rows).toEqual([{ a: 1 }]);
|
|
476
|
+
expect(state.columns).toEqual(['a']);
|
|
477
|
+
expect(state.columnTypes).toEqual({ a: 'System.Int32' });
|
|
478
|
+
expect(state.elapsed).toBe(123);
|
|
479
|
+
expect(state.resultTime).toBeInstanceOf(Date);
|
|
480
|
+
expect(state.activeResultSet).toBe(0);
|
|
481
|
+
expect(state.queryStartTime).toBeNull();
|
|
482
|
+
expect(state.runningQueryKey).toBeNull();
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
describe('QUERY_ERROR', () => {
|
|
487
|
+
it('sets error and clears loading', () => {
|
|
488
|
+
const initial = makeState({ loading: true });
|
|
489
|
+
const state = explorerReducer(initial, { type: 'QUERY_ERROR', error: 'timeout' });
|
|
490
|
+
expect(state.loading).toBe(false);
|
|
491
|
+
expect(state.error).toBe('timeout');
|
|
492
|
+
expect(state.queryStartTime).toBeNull();
|
|
493
|
+
expect(state.runningQueryKey).toBeNull();
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
describe('QUERY_CANCEL', () => {
|
|
498
|
+
it('clears loading without error', () => {
|
|
499
|
+
const initial = makeState({ loading: true, runningQueryKey: 'q-1' });
|
|
500
|
+
const state = explorerReducer(initial, { type: 'QUERY_CANCEL' });
|
|
501
|
+
expect(state.loading).toBe(false);
|
|
502
|
+
expect(state.queryStartTime).toBeNull();
|
|
503
|
+
expect(state.runningQueryKey).toBeNull();
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
// --- Results ---
|
|
508
|
+
|
|
509
|
+
describe('SET_RESULTS_TAB', () => {
|
|
510
|
+
it('sets results tab', () => {
|
|
511
|
+
const state = explorerReducer(makeState(), { type: 'SET_RESULTS_TAB', tab: 'chart' });
|
|
512
|
+
expect(state.resultsTab).toBe('chart');
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
describe('SET_ACTIVE_RESULT_SET', () => {
|
|
517
|
+
it('sets active result set index', () => {
|
|
518
|
+
const state = explorerReducer(makeState(), { type: 'SET_ACTIVE_RESULT_SET', index: 2 });
|
|
519
|
+
expect(state.activeResultSet).toBe(2);
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
describe('SET_HISTORY', () => {
|
|
524
|
+
it('sets history entries', () => {
|
|
525
|
+
const history = [{
|
|
526
|
+
key: 'k',
|
|
527
|
+
query: 'q',
|
|
528
|
+
timestamp: 1,
|
|
529
|
+
elapsed: 100,
|
|
530
|
+
rowCount: 5,
|
|
531
|
+
columnCount: 2,
|
|
532
|
+
status: 'success' as const,
|
|
533
|
+
}];
|
|
534
|
+
const state = explorerReducer(makeState(), { type: 'SET_HISTORY', history });
|
|
535
|
+
expect(state.history).toBe(history);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
describe('LOAD_HISTORY_ENTRY', () => {
|
|
540
|
+
it('loads history entry data', () => {
|
|
541
|
+
const state = explorerReducer(makeState(), {
|
|
542
|
+
type: 'LOAD_HISTORY_ENTRY',
|
|
543
|
+
rows: [{ x: 1 }],
|
|
544
|
+
columns: ['x'],
|
|
545
|
+
columnTypes: { x: 'System.Int32' },
|
|
546
|
+
kql: 'T | take 1',
|
|
547
|
+
});
|
|
548
|
+
expect(state.rows).toEqual([{ x: 1 }]);
|
|
549
|
+
expect(state.columns).toEqual(['x']);
|
|
550
|
+
expect(state.columnTypes).toEqual({ x: 'System.Int32' });
|
|
551
|
+
expect(state.resultsTab).toBe('results');
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
// --- UI ---
|
|
556
|
+
|
|
557
|
+
describe('SET_EDITOR_HEIGHT', () => {
|
|
558
|
+
it('sets editor height', () => {
|
|
559
|
+
const state = explorerReducer(makeState(), { type: 'SET_EDITOR_HEIGHT', height: 75 });
|
|
560
|
+
expect(state.editorHeight).toBe(75);
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
describe('SET_HAS_SELECTION', () => {
|
|
565
|
+
it('sets hasSelection', () => {
|
|
566
|
+
const state = explorerReducer(makeState(), { type: 'SET_HAS_SELECTION', hasSelection: true });
|
|
567
|
+
expect(state.hasSelection).toBe(true);
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
describe('SET_CAN_RECALL', () => {
|
|
572
|
+
it('sets canRecall', () => {
|
|
573
|
+
const state = explorerReducer(makeState(), { type: 'SET_CAN_RECALL', canRecall: true });
|
|
574
|
+
expect(state.canRecall).toBe(true);
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// --- Default ---
|
|
579
|
+
|
|
580
|
+
describe('default case', () => {
|
|
581
|
+
it('returns state unchanged for unknown action', () => {
|
|
582
|
+
const initial = makeState();
|
|
583
|
+
const state = explorerReducer(initial, { type: 'UNKNOWN_ACTION' } as unknown as ExplorerAction);
|
|
584
|
+
expect(state).toBe(initial);
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
// --- Connection actions ---
|
|
589
|
+
|
|
590
|
+
describe('SET_CONNECTIONS', () => {
|
|
591
|
+
it('replaces connections array', () => {
|
|
592
|
+
const initial = createInitialState({ initialQuery: '', defaultClusters: [] });
|
|
593
|
+
const newConns = [
|
|
594
|
+
{ id: 'a', name: 'A', clusterUrl: 'https://a.kusto.windows.net', database: 'db', color: '#f00' },
|
|
595
|
+
{ id: 'b', name: 'B', clusterUrl: 'https://b.kusto.windows.net', database: 'db2', color: '#0f0' },
|
|
596
|
+
];
|
|
597
|
+
const state = explorerReducer(initial, { type: 'SET_CONNECTIONS', connections: newConns });
|
|
598
|
+
expect(state.connections).toHaveLength(2);
|
|
599
|
+
expect(state.connections[0].id).toBe('a');
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
describe('SET_TAB_CONNECTION', () => {
|
|
604
|
+
it('updates a specific tab connectionId', () => {
|
|
605
|
+
const initial = createInitialState({ initialQuery: '', defaultClusters: [] });
|
|
606
|
+
const tabId = initial.tabs[0].id;
|
|
607
|
+
const state = explorerReducer(initial, { type: 'SET_TAB_CONNECTION', tabId, connectionId: 'new-conn' });
|
|
608
|
+
expect(state.tabs[0].connectionId).toBe('new-conn');
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it('does not affect other tabs', () => {
|
|
612
|
+
let state = createInitialState({ initialQuery: '', defaultClusters: [] });
|
|
613
|
+
state = explorerReducer(state, { type: 'ADD_TAB' });
|
|
614
|
+
expect(state.tabs).toHaveLength(2);
|
|
615
|
+
const secondTabId = state.tabs[1].id;
|
|
616
|
+
const result = explorerReducer(state, { type: 'SET_TAB_CONNECTION', tabId: secondTabId, connectionId: 'other' });
|
|
617
|
+
expect(result.tabs[0].connectionId).toBe(state.tabs[0].connectionId);
|
|
618
|
+
expect(result.tabs[1].connectionId).toBe('other');
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
describe('ADD_TAB inherits connection', () => {
|
|
623
|
+
it('new tab inherits active tab connection', () => {
|
|
624
|
+
let state = createInitialState({ initialQuery: '', defaultClusters: [] });
|
|
625
|
+
state = explorerReducer(state, { type: 'SET_TAB_CONNECTION', tabId: state.tabs[0].id, connectionId: 'custom-conn' });
|
|
626
|
+
state = explorerReducer(state, { type: 'ADD_TAB' });
|
|
627
|
+
const newTab = state.tabs[state.tabs.length - 1];
|
|
628
|
+
expect(newTab.connectionId).toBe('custom-conn');
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
describe('createInitialState with connections', () => {
|
|
633
|
+
it('loads connections', () => {
|
|
634
|
+
const state = createInitialState({ initialQuery: '', defaultClusters: [] });
|
|
635
|
+
expect(state.connections.length).toBeGreaterThanOrEqual(1);
|
|
636
|
+
expect(state.connections[0].id).toBeTruthy();
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it('first tab has a connectionId', () => {
|
|
640
|
+
const state = createInitialState({ initialQuery: '', defaultClusters: [] });
|
|
641
|
+
expect(state.tabs[0].connectionId).toBeTruthy();
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
});
|