@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,615 @@
|
|
|
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 { Explorer } from './Explorer';
|
|
6
|
+
|
|
7
|
+
vi.mock('@monaco-editor/react', () => ({
|
|
8
|
+
Editor: () => React.createElement('div', { 'data-testid': 'monaco-editor' }),
|
|
9
|
+
}));
|
|
10
|
+
vi.mock('../../services/kusto', () => ({
|
|
11
|
+
queryKusto: vi.fn().mockResolvedValue({ columns: [], rows: [] }),
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('../../services/queryHistory', () => ({
|
|
14
|
+
normalizeQuery: vi.fn((q: string) => q),
|
|
15
|
+
getHistory: vi.fn(() => Promise.resolve([])),
|
|
16
|
+
saveHistoryEntry: vi.fn(),
|
|
17
|
+
recallResult: vi.fn(() => null),
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('../../services/schema', () => ({
|
|
20
|
+
getSchema: vi.fn(() => []),
|
|
21
|
+
loadSchema: vi.fn().mockResolvedValue([]),
|
|
22
|
+
}));
|
|
23
|
+
vi.mock('../../context/ExplorerColorContext', () => ({
|
|
24
|
+
useExplorerColors: () => ({
|
|
25
|
+
semantic: { backdrop: 'rgba(0,0,0,0.5)', shadowMedium: 'rgba(0,0,0,0.2)', shadowLight: 'rgba(0,0,0,0.15)', scrollThumb: '#ccc', scrollThumbHover: '#aaa', functionBadge: '#0f0', materializedViewBadge: '#90f', lookupBadge: '#f90', selectionBg: '#00f', selectionSubtle: '#eef', highlightHoverBg: '#ffa' },
|
|
26
|
+
chart: { palette: [] },
|
|
27
|
+
}),
|
|
28
|
+
ExplorerColorProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
29
|
+
}));
|
|
30
|
+
vi.mock('../EditorToolbar/EditorToolbar', () => ({
|
|
31
|
+
EditorToolbar: () => React.createElement('div', { 'data-testid': 'editor-toolbar' }),
|
|
32
|
+
}));
|
|
33
|
+
vi.mock('../ResultsPanel/ResultsPanel', () => ({
|
|
34
|
+
ResultsPanel: () => React.createElement('div', { 'data-testid': 'results-panel' }),
|
|
35
|
+
}));
|
|
36
|
+
vi.mock('../SchemaSidebar/SchemaSidebar', () => ({
|
|
37
|
+
SchemaSidebar: () => React.createElement('div', { 'data-testid': 'schema-sidebar' }),
|
|
38
|
+
}));
|
|
39
|
+
vi.mock('../TabBar/TabBar', () => ({
|
|
40
|
+
TabBar: () => React.createElement('div', { 'data-testid': 'tab-bar' }),
|
|
41
|
+
}));
|
|
42
|
+
vi.mock('../../context/ExplorerStateContext', () => ({
|
|
43
|
+
ExplorerStateContext: { Provider: ({ children }: { children: React.ReactNode }) => children },
|
|
44
|
+
ExplorerDispatchContext: { Provider: ({ children }: { children: React.ReactNode }) => children },
|
|
45
|
+
useExplorerState: (...args: unknown[]) => (mockExplorerState as (...a: unknown[]) => unknown)(...args),
|
|
46
|
+
useExplorerDispatch: () => mockDispatch,
|
|
47
|
+
useActiveTabs: (...args: unknown[]) => (mockActiveTabs as (...a: unknown[]) => unknown)(...args),
|
|
48
|
+
useFocusedConnection: () => mockConnection,
|
|
49
|
+
}));
|
|
50
|
+
vi.mock('../../context/KustoClientContext', () => ({
|
|
51
|
+
KustoClientContext: { Provider: ({ children }: { children: React.ReactNode }) => children },
|
|
52
|
+
useKustoClient: () => ({}),
|
|
53
|
+
}));
|
|
54
|
+
vi.mock('../ExplorerWorkspace/ExplorerWorkspace.styles', () => ({
|
|
55
|
+
useExplorerStyles: () => new Proxy({}, { get: (_, p) => String(p) }),
|
|
56
|
+
}));
|
|
57
|
+
vi.mock('../ExplorerWorkspace/ExplorerWorkspace.logic', () => ({
|
|
58
|
+
DEFAULT_QUERY: '',
|
|
59
|
+
buildWellKnownClusters: vi.fn((clusters: unknown[]) => clusters),
|
|
60
|
+
formatKql: vi.fn((q: string) => q),
|
|
61
|
+
getQueryToRunFromEditor: vi.fn(() => ''),
|
|
62
|
+
KEYBOARD_SHORTCUTS: [],
|
|
63
|
+
createTab: vi.fn((q: string, title: string) => ({ id: '1', query: q, title, kql: '', connectionId: 'test-conn' })),
|
|
64
|
+
loadConnections: vi.fn(() => [{ id: 'test-conn', name: 'Test Cluster', clusterUrl: 'https://help.kusto.windows.net', database: 'Telemetry', color: '#909d63' }]),
|
|
65
|
+
loadActiveConnectionId: vi.fn(() => 'test-conn'),
|
|
66
|
+
saveConnections: vi.fn(),
|
|
67
|
+
saveActiveConnectionId: vi.fn(),
|
|
68
|
+
formatBytes: vi.fn(() => '0 B'),
|
|
69
|
+
exportCsv: vi.fn(),
|
|
70
|
+
exportJson: vi.fn(),
|
|
71
|
+
parseResultColumns: vi.fn(() => ({ columns: [], columnTypes: {} })),
|
|
72
|
+
buildSuccessEntry: vi.fn(() => ({})),
|
|
73
|
+
buildErrorEntry: vi.fn(() => ({})),
|
|
74
|
+
DEFAULT_CONNECTION: { id: 'test-conn', name: 'Test Cluster', clusterUrl: 'https://help.kusto.windows.net', database: 'Telemetry', color: '#909d63' },
|
|
75
|
+
CONNECTION_COLORS: ['#909d63', '#6a8799', '#ebc17a', '#bc5653', '#b06698'],
|
|
76
|
+
}));
|
|
77
|
+
vi.mock('../ExplorerWorkspace/kqlLanguage', () => ({
|
|
78
|
+
registerKqlLanguage: vi.fn(),
|
|
79
|
+
setKqlSchemaResolver: vi.fn(),
|
|
80
|
+
}));
|
|
81
|
+
vi.mock('@fluentui/react-components', () => ({
|
|
82
|
+
Button: (p: Record<string, unknown>) => React.createElement('button', p, p['children'] as React.ReactNode),
|
|
83
|
+
Tooltip: (p: Record<string, unknown>) => React.createElement('div', null, p['children'] as React.ReactNode),
|
|
84
|
+
tokens: {},
|
|
85
|
+
}));
|
|
86
|
+
vi.mock('@fluentui/react-icons', () => ({
|
|
87
|
+
AddRegular: () => React.createElement('span', null, 'icon'),
|
|
88
|
+
DismissRegular: () => React.createElement('span', null, 'icon'),
|
|
89
|
+
SplitVerticalRegular: () => React.createElement('span', null, 'icon'),
|
|
90
|
+
SplitHorizontalRegular: () => React.createElement('span', null, 'icon'),
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
const defaultExplorerState = {
|
|
94
|
+
tabs: [{ id: '1', query: '', title: 'Tab 1', kql: '', connectionId: 'test-conn' }],
|
|
95
|
+
activeTabId: '1',
|
|
96
|
+
splitEnabled: false,
|
|
97
|
+
splitDirection: 'vertical' as 'vertical' | 'horizontal',
|
|
98
|
+
splitTabId: null as string | null,
|
|
99
|
+
focusedPane: 'primary' as 'primary' | 'secondary',
|
|
100
|
+
loading: false,
|
|
101
|
+
error: null as string | null,
|
|
102
|
+
queryStartTime: null as number | null,
|
|
103
|
+
runningQueryKey: null as string | null,
|
|
104
|
+
rows: null as Record<string, unknown>[] | null,
|
|
105
|
+
columns: [] as string[],
|
|
106
|
+
columnTypes: {} as Record<string, string>,
|
|
107
|
+
elapsed: null as number | null,
|
|
108
|
+
resultTime: null as Date | null,
|
|
109
|
+
queryStats: null as Record<string, unknown> | null,
|
|
110
|
+
resultSets: [] as unknown[],
|
|
111
|
+
activeResultSet: 0,
|
|
112
|
+
resultsTab: 'results' as 'results' | 'chart' | 'stats' | 'history',
|
|
113
|
+
history: [] as unknown[],
|
|
114
|
+
editorHeight: 50,
|
|
115
|
+
hasSelection: false,
|
|
116
|
+
canRecall: false,
|
|
117
|
+
schema: [] as unknown[],
|
|
118
|
+
schemaSearch: '',
|
|
119
|
+
expandedFolders: new Set<string>(),
|
|
120
|
+
expandedTables: new Set<string>(),
|
|
121
|
+
schemaContextMenu: null as { x: number; y: number; item: Record<string, unknown> } | null,
|
|
122
|
+
connections: [{ id: 'test-conn', name: 'Test Cluster', clusterUrl: 'https://help.kusto.windows.net', database: 'Telemetry', color: '#909d63' }],
|
|
123
|
+
};
|
|
124
|
+
const mockConnection = { id: 'test-conn', name: 'Test Cluster', clusterUrl: 'https://help.kusto.windows.net', database: 'Telemetry', color: '#909d63' };
|
|
125
|
+
const mockExplorerState = vi.fn(() => defaultExplorerState);
|
|
126
|
+
const mockDispatch = vi.fn();
|
|
127
|
+
const mockActiveTab = { id: '1', query: '', title: 'Tab 1', kql: '', connectionId: 'test-conn' };
|
|
128
|
+
const mockActiveTabs = vi.fn(() => ({
|
|
129
|
+
activeTab: mockActiveTab,
|
|
130
|
+
splitTab: null as { id: string; query: string; title: string; kql: string; connectionId: string } | null,
|
|
131
|
+
}));
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
describe('Explorer', () => {
|
|
135
|
+
let container: HTMLDivElement;
|
|
136
|
+
let root: ReturnType<typeof createRoot>;
|
|
137
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
138
|
+
let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
|
|
139
|
+
|
|
140
|
+
beforeEach(() => {
|
|
141
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
142
|
+
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
143
|
+
container = document.createElement('div');
|
|
144
|
+
document.body.appendChild(container);
|
|
145
|
+
root = createRoot(container);
|
|
146
|
+
mockExplorerState.mockReturnValue(defaultExplorerState);
|
|
147
|
+
mockActiveTabs.mockReturnValue({ activeTab: mockActiveTab, splitTab: null });
|
|
148
|
+
mockDispatch.mockClear();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
afterEach(() => {
|
|
152
|
+
act(() => {
|
|
153
|
+
root.unmount();
|
|
154
|
+
});
|
|
155
|
+
container.remove();
|
|
156
|
+
consoleErrorSpy.mockRestore();
|
|
157
|
+
consoleWarnSpy.mockRestore();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('renders without crashing', () => {
|
|
161
|
+
act(() => {
|
|
162
|
+
root.render(React.createElement(Explorer));
|
|
163
|
+
});
|
|
164
|
+
expect(container.innerHTML).not.toBe('');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('renders with split mode enabled', () => {
|
|
168
|
+
mockExplorerState.mockReturnValue({
|
|
169
|
+
...defaultExplorerState,
|
|
170
|
+
splitEnabled: true,
|
|
171
|
+
splitTabId: '2',
|
|
172
|
+
tabs: [
|
|
173
|
+
{ id: '1', query: '', title: 'Tab 1', kql: 'table1', connectionId: 'test-conn' },
|
|
174
|
+
{ id: '2', query: '', title: 'Tab 2', kql: 'table2', connectionId: 'test-conn' },
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
mockActiveTabs.mockReturnValue({
|
|
178
|
+
activeTab: { id: '1', query: '', title: 'Tab 1', kql: 'table1', connectionId: 'test-conn' },
|
|
179
|
+
splitTab: { id: '2', query: '', title: 'Tab 2', kql: 'table2', connectionId: 'test-conn' },
|
|
180
|
+
});
|
|
181
|
+
act(() => {
|
|
182
|
+
root.render(React.createElement(Explorer));
|
|
183
|
+
});
|
|
184
|
+
expect(container.innerHTML).toContain('monaco-editor');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('renders loading state with cancel button visible', () => {
|
|
188
|
+
mockExplorerState.mockReturnValue({
|
|
189
|
+
...defaultExplorerState,
|
|
190
|
+
loading: true,
|
|
191
|
+
runningQueryKey: 'test-key',
|
|
192
|
+
});
|
|
193
|
+
act(() => {
|
|
194
|
+
root.render(React.createElement(Explorer));
|
|
195
|
+
});
|
|
196
|
+
expect(container.innerHTML).not.toBe('');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('renders with result data', () => {
|
|
200
|
+
mockExplorerState.mockReturnValue({
|
|
201
|
+
...defaultExplorerState,
|
|
202
|
+
rows: [{ Name: 'a', Value: 1 }],
|
|
203
|
+
columns: ['Name', 'Value'],
|
|
204
|
+
columnTypes: { Name: 'string', Value: 'long' },
|
|
205
|
+
elapsed: 42,
|
|
206
|
+
resultTime: new Date(),
|
|
207
|
+
});
|
|
208
|
+
act(() => {
|
|
209
|
+
root.render(React.createElement(Explorer));
|
|
210
|
+
});
|
|
211
|
+
expect(container.innerHTML).toContain('results-panel');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('renders in VSCode webview mode', () => {
|
|
215
|
+
act(() => {
|
|
216
|
+
root.render(React.createElement(Explorer));
|
|
217
|
+
});
|
|
218
|
+
expect(container.innerHTML).not.toBe('');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('renders with multiple result sets', () => {
|
|
222
|
+
mockExplorerState.mockReturnValue({
|
|
223
|
+
...defaultExplorerState,
|
|
224
|
+
rows: [{ A: 1 }],
|
|
225
|
+
columns: ['A'],
|
|
226
|
+
resultSets: [
|
|
227
|
+
{ columns: [{ ColumnName: 'A', ColumnType: 'int' }], rows: [{ A: 1 }] },
|
|
228
|
+
{ columns: [{ ColumnName: 'B', ColumnType: 'string' }], rows: [{ B: 'x' }] },
|
|
229
|
+
],
|
|
230
|
+
activeResultSet: 0,
|
|
231
|
+
});
|
|
232
|
+
act(() => {
|
|
233
|
+
root.render(React.createElement(Explorer));
|
|
234
|
+
});
|
|
235
|
+
expect(container.innerHTML).not.toBe('');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('renders with secondary pane focused', () => {
|
|
239
|
+
mockExplorerState.mockReturnValue({
|
|
240
|
+
...defaultExplorerState,
|
|
241
|
+
splitEnabled: true,
|
|
242
|
+
splitTabId: '2',
|
|
243
|
+
focusedPane: 'secondary',
|
|
244
|
+
tabs: [
|
|
245
|
+
{ id: '1', query: '', title: 'Tab 1', kql: '', connectionId: 'test-conn' },
|
|
246
|
+
{ id: '2', query: '', title: 'Tab 2', kql: '', connectionId: 'test-conn' },
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
mockActiveTabs.mockReturnValue({
|
|
250
|
+
activeTab: { id: '1', query: '', title: 'Tab 1', kql: '', connectionId: 'test-conn' },
|
|
251
|
+
splitTab: { id: '2', query: '', title: 'Tab 2', kql: '', connectionId: 'test-conn' },
|
|
252
|
+
});
|
|
253
|
+
act(() => {
|
|
254
|
+
root.render(React.createElement(Explorer));
|
|
255
|
+
});
|
|
256
|
+
expect(container.innerHTML).not.toBe('');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('renders with error state', () => {
|
|
260
|
+
mockExplorerState.mockReturnValue({
|
|
261
|
+
...defaultExplorerState,
|
|
262
|
+
error: 'Query failed',
|
|
263
|
+
rows: null,
|
|
264
|
+
});
|
|
265
|
+
act(() => {
|
|
266
|
+
root.render(React.createElement(Explorer));
|
|
267
|
+
});
|
|
268
|
+
expect(container.innerHTML).not.toBe('');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('renders with schema data', () => {
|
|
272
|
+
mockExplorerState.mockReturnValue({
|
|
273
|
+
...defaultExplorerState,
|
|
274
|
+
schema: [
|
|
275
|
+
{ name: 'Events', folder: 'Tables', kind: 'table', columns: [{ name: 'Id', type: 'int' }] },
|
|
276
|
+
],
|
|
277
|
+
});
|
|
278
|
+
act(() => {
|
|
279
|
+
root.render(React.createElement(Explorer));
|
|
280
|
+
});
|
|
281
|
+
expect(container.innerHTML).toContain('schema-sidebar');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('renders with history entries', () => {
|
|
285
|
+
mockExplorerState.mockReturnValue({
|
|
286
|
+
...defaultExplorerState,
|
|
287
|
+
history: [
|
|
288
|
+
{ key: 'k1', query: 'Events | take 10', timestamp: Date.now(), elapsed: 100, rowCount: 10, columnCount: 2, status: 'success' },
|
|
289
|
+
],
|
|
290
|
+
});
|
|
291
|
+
act(() => {
|
|
292
|
+
root.render(React.createElement(Explorer));
|
|
293
|
+
});
|
|
294
|
+
expect(container.innerHTML).not.toBe('');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('renders with horizontal split direction', () => {
|
|
298
|
+
mockExplorerState.mockReturnValue({
|
|
299
|
+
...defaultExplorerState,
|
|
300
|
+
splitEnabled: true,
|
|
301
|
+
splitDirection: 'horizontal',
|
|
302
|
+
splitTabId: '2',
|
|
303
|
+
tabs: [
|
|
304
|
+
{ id: '1', query: '', title: 'Tab 1', kql: '', connectionId: 'test-conn' },
|
|
305
|
+
{ id: '2', query: '', title: 'Tab 2', kql: '', connectionId: 'test-conn' },
|
|
306
|
+
],
|
|
307
|
+
});
|
|
308
|
+
mockActiveTabs.mockReturnValue({
|
|
309
|
+
activeTab: { id: '1', query: '', title: 'Tab 1', kql: '', connectionId: 'test-conn' },
|
|
310
|
+
splitTab: { id: '2', query: '', title: 'Tab 2', kql: '', connectionId: 'test-conn' },
|
|
311
|
+
});
|
|
312
|
+
act(() => {
|
|
313
|
+
root.render(React.createElement(Explorer));
|
|
314
|
+
});
|
|
315
|
+
expect(container.innerHTML).not.toBe('');
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('renders with multiple tabs', () => {
|
|
319
|
+
mockExplorerState.mockReturnValue({
|
|
320
|
+
...defaultExplorerState,
|
|
321
|
+
tabs: [
|
|
322
|
+
{ id: '1', query: 'query1', title: 'Tab 1', kql: '', connectionId: 'test-conn' },
|
|
323
|
+
{ id: '2', query: 'query2', title: 'Tab 2', kql: '', connectionId: 'test-conn' },
|
|
324
|
+
{ id: '3', query: 'query3', title: 'Tab 3', kql: '', connectionId: 'test-conn' },
|
|
325
|
+
],
|
|
326
|
+
activeTabId: '2',
|
|
327
|
+
});
|
|
328
|
+
act(() => {
|
|
329
|
+
root.render(React.createElement(Explorer));
|
|
330
|
+
});
|
|
331
|
+
expect(container.innerHTML).not.toBe('');
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('renders with running query cancelled', () => {
|
|
335
|
+
mockExplorerState.mockReturnValue({
|
|
336
|
+
...defaultExplorerState,
|
|
337
|
+
loading: false,
|
|
338
|
+
runningQueryKey: null,
|
|
339
|
+
rows: [],
|
|
340
|
+
columns: [],
|
|
341
|
+
});
|
|
342
|
+
act(() => {
|
|
343
|
+
root.render(React.createElement(Explorer));
|
|
344
|
+
});
|
|
345
|
+
expect(container.innerHTML).not.toBe('');
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('parses query from URL search params', () => {
|
|
349
|
+
const originalLocation = window.location;
|
|
350
|
+
delete (window as { location?: unknown }).location;
|
|
351
|
+
window.location = Object.assign(Object.create(Object.getPrototypeOf(originalLocation)), originalLocation, { search: '?query=Events%20%7C%20take%2010' });
|
|
352
|
+
act(() => {
|
|
353
|
+
root.render(React.createElement(Explorer));
|
|
354
|
+
});
|
|
355
|
+
expect(container.innerHTML).not.toBe('');
|
|
356
|
+
(window as unknown as { location: Location }).location = originalLocation;
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('handles URL parsing error gracefully', () => {
|
|
360
|
+
const originalLocation = window.location;
|
|
361
|
+
delete (window as { location?: unknown }).location;
|
|
362
|
+
(window as unknown as { location: Location }).location = { search: '' } as Location;
|
|
363
|
+
Object.defineProperty(window.location, 'search', {
|
|
364
|
+
get: () => { throw new Error('URL error'); },
|
|
365
|
+
});
|
|
366
|
+
act(() => {
|
|
367
|
+
root.render(React.createElement(Explorer));
|
|
368
|
+
});
|
|
369
|
+
expect(container.innerHTML).not.toBe('');
|
|
370
|
+
(window as unknown as { location: Location }).location = originalLocation;
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('renders with canRecall enabled', () => {
|
|
374
|
+
mockExplorerState.mockReturnValue({
|
|
375
|
+
...defaultExplorerState,
|
|
376
|
+
canRecall: true,
|
|
377
|
+
});
|
|
378
|
+
act(() => {
|
|
379
|
+
root.render(React.createElement(Explorer));
|
|
380
|
+
});
|
|
381
|
+
expect(container.innerHTML).not.toBe('');
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('renders with hasSelection enabled', () => {
|
|
385
|
+
mockExplorerState.mockReturnValue({
|
|
386
|
+
...defaultExplorerState,
|
|
387
|
+
hasSelection: true,
|
|
388
|
+
});
|
|
389
|
+
act(() => {
|
|
390
|
+
root.render(React.createElement(Explorer));
|
|
391
|
+
});
|
|
392
|
+
expect(container.innerHTML).not.toBe('');
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('renders with different editor heights', () => {
|
|
396
|
+
mockExplorerState.mockReturnValue({
|
|
397
|
+
...defaultExplorerState,
|
|
398
|
+
editorHeight: 70,
|
|
399
|
+
});
|
|
400
|
+
act(() => {
|
|
401
|
+
root.render(React.createElement(Explorer));
|
|
402
|
+
});
|
|
403
|
+
expect(container.innerHTML).not.toBe('');
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('renders with query stats', () => {
|
|
407
|
+
mockExplorerState.mockReturnValue({
|
|
408
|
+
...defaultExplorerState,
|
|
409
|
+
rows: [{ A: 1 }],
|
|
410
|
+
columns: ['A'],
|
|
411
|
+
queryStats: { totalRows: 100, executionTime: 500 },
|
|
412
|
+
});
|
|
413
|
+
act(() => {
|
|
414
|
+
root.render(React.createElement(Explorer));
|
|
415
|
+
});
|
|
416
|
+
expect(container.innerHTML).not.toBe('');
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('renders with expanded schema folders', () => {
|
|
420
|
+
mockExplorerState.mockReturnValue({
|
|
421
|
+
...defaultExplorerState,
|
|
422
|
+
expandedFolders: new Set(['Tables']),
|
|
423
|
+
expandedTables: new Set(['Events']),
|
|
424
|
+
schema: [{ name: 'Events', folder: 'Tables', kind: 'table' }],
|
|
425
|
+
});
|
|
426
|
+
act(() => {
|
|
427
|
+
root.render(React.createElement(Explorer));
|
|
428
|
+
});
|
|
429
|
+
expect(container.innerHTML).not.toBe('');
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it('renders with schema search active', () => {
|
|
433
|
+
mockExplorerState.mockReturnValue({
|
|
434
|
+
...defaultExplorerState,
|
|
435
|
+
schemaSearch: 'Events',
|
|
436
|
+
schema: [{ name: 'Events', folder: 'Tables', kind: 'table' }],
|
|
437
|
+
});
|
|
438
|
+
act(() => {
|
|
439
|
+
root.render(React.createElement(Explorer));
|
|
440
|
+
});
|
|
441
|
+
expect(container.innerHTML).not.toBe('');
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it('renders with schema context menu', () => {
|
|
445
|
+
mockExplorerState.mockReturnValue({
|
|
446
|
+
...defaultExplorerState,
|
|
447
|
+
schemaContextMenu: { x: 100, y: 200, item: { name: 'Events' } },
|
|
448
|
+
});
|
|
449
|
+
act(() => {
|
|
450
|
+
root.render(React.createElement(Explorer));
|
|
451
|
+
});
|
|
452
|
+
expect(container.innerHTML).not.toBe('');
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('renders with empty rows array', () => {
|
|
456
|
+
mockExplorerState.mockReturnValue({
|
|
457
|
+
...defaultExplorerState,
|
|
458
|
+
rows: [],
|
|
459
|
+
columns: ['A', 'B'],
|
|
460
|
+
});
|
|
461
|
+
act(() => {
|
|
462
|
+
root.render(React.createElement(Explorer));
|
|
463
|
+
});
|
|
464
|
+
expect(container.innerHTML).not.toBe('');
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it('renders with different results tabs', () => {
|
|
468
|
+
mockExplorerState.mockReturnValue({
|
|
469
|
+
...defaultExplorerState,
|
|
470
|
+
resultsTab: 'history',
|
|
471
|
+
rows: [{ A: 1 }],
|
|
472
|
+
columns: ['A'],
|
|
473
|
+
});
|
|
474
|
+
act(() => {
|
|
475
|
+
root.render(React.createElement(Explorer));
|
|
476
|
+
});
|
|
477
|
+
expect(container.innerHTML).not.toBe('');
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it('renders split view with both panes having different queries', () => {
|
|
481
|
+
mockExplorerState.mockReturnValue({
|
|
482
|
+
...defaultExplorerState,
|
|
483
|
+
splitEnabled: true,
|
|
484
|
+
splitTabId: '2',
|
|
485
|
+
tabs: [
|
|
486
|
+
{ id: '1', query: 'Events | take 10', title: 'Query 1', kql: 'Events | take 10', connectionId: 'test-conn' },
|
|
487
|
+
{ id: '2', query: 'Traces | take 20', title: 'Query 2', kql: 'Traces | take 20', connectionId: 'test-conn' },
|
|
488
|
+
],
|
|
489
|
+
});
|
|
490
|
+
mockActiveTabs.mockReturnValue({
|
|
491
|
+
activeTab: { id: '1', query: 'Events | take 10', title: 'Query 1', kql: 'Events | take 10', connectionId: 'test-conn' },
|
|
492
|
+
splitTab: { id: '2', query: 'Traces | take 20', title: 'Query 2', kql: 'Traces | take 20', connectionId: 'test-conn' },
|
|
493
|
+
});
|
|
494
|
+
act(() => {
|
|
495
|
+
root.render(React.createElement(Explorer));
|
|
496
|
+
});
|
|
497
|
+
expect(container.innerHTML).toContain('monaco-editor');
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it('renders with loading and no runningQueryKey', () => {
|
|
501
|
+
mockExplorerState.mockReturnValue({
|
|
502
|
+
...defaultExplorerState,
|
|
503
|
+
loading: true,
|
|
504
|
+
runningQueryKey: null,
|
|
505
|
+
});
|
|
506
|
+
act(() => {
|
|
507
|
+
root.render(React.createElement(Explorer));
|
|
508
|
+
});
|
|
509
|
+
expect(container.innerHTML).not.toBe('');
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('renders with queryStartTime but no results yet', () => {
|
|
513
|
+
mockExplorerState.mockReturnValue({
|
|
514
|
+
...defaultExplorerState,
|
|
515
|
+
queryStartTime: Date.now(),
|
|
516
|
+
loading: true,
|
|
517
|
+
});
|
|
518
|
+
act(() => {
|
|
519
|
+
root.render(React.createElement(Explorer));
|
|
520
|
+
});
|
|
521
|
+
expect(container.innerHTML).not.toBe('');
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('renders with multiple history entries with different statuses', () => {
|
|
525
|
+
mockExplorerState.mockReturnValue({
|
|
526
|
+
...defaultExplorerState,
|
|
527
|
+
history: [
|
|
528
|
+
{ key: 'k1', query: 'Events', timestamp: Date.now(), elapsed: 100, rowCount: 10, columnCount: 2, status: 'success' },
|
|
529
|
+
{ key: 'k2', query: 'Traces', timestamp: Date.now(), elapsed: null, rowCount: null, columnCount: 0, status: 'error', error: 'Query failed' },
|
|
530
|
+
],
|
|
531
|
+
});
|
|
532
|
+
act(() => {
|
|
533
|
+
root.render(React.createElement(Explorer));
|
|
534
|
+
});
|
|
535
|
+
expect(container.innerHTML).not.toBe('');
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it('renders with result sets and non-zero activeResultSet', () => {
|
|
539
|
+
mockExplorerState.mockReturnValue({
|
|
540
|
+
...defaultExplorerState,
|
|
541
|
+
rows: [{ B: 'x' }],
|
|
542
|
+
columns: ['B'],
|
|
543
|
+
resultSets: [
|
|
544
|
+
{ columns: [{ ColumnName: 'A', ColumnType: 'int' }], rows: [{ A: 1 }] },
|
|
545
|
+
{ columns: [{ ColumnName: 'B', ColumnType: 'string' }], rows: [{ B: 'x' }] },
|
|
546
|
+
],
|
|
547
|
+
activeResultSet: 1,
|
|
548
|
+
});
|
|
549
|
+
act(() => {
|
|
550
|
+
root.render(React.createElement(Explorer));
|
|
551
|
+
});
|
|
552
|
+
expect(container.innerHTML).not.toBe('');
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it('renders with null resultTime', () => {
|
|
556
|
+
mockExplorerState.mockReturnValue({
|
|
557
|
+
...defaultExplorerState,
|
|
558
|
+
rows: [{ A: 1 }],
|
|
559
|
+
columns: ['A'],
|
|
560
|
+
resultTime: null,
|
|
561
|
+
});
|
|
562
|
+
act(() => {
|
|
563
|
+
root.render(React.createElement(Explorer));
|
|
564
|
+
});
|
|
565
|
+
expect(container.innerHTML).not.toBe('');
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it('renders with null elapsed time', () => {
|
|
569
|
+
mockExplorerState.mockReturnValue({
|
|
570
|
+
...defaultExplorerState,
|
|
571
|
+
rows: [{ A: 1 }],
|
|
572
|
+
columns: ['A'],
|
|
573
|
+
elapsed: null,
|
|
574
|
+
});
|
|
575
|
+
act(() => {
|
|
576
|
+
root.render(React.createElement(Explorer));
|
|
577
|
+
});
|
|
578
|
+
expect(container.innerHTML).not.toBe('');
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
it('renders with empty schema', () => {
|
|
582
|
+
mockExplorerState.mockReturnValue({
|
|
583
|
+
...defaultExplorerState,
|
|
584
|
+
schema: [],
|
|
585
|
+
});
|
|
586
|
+
act(() => {
|
|
587
|
+
root.render(React.createElement(Explorer));
|
|
588
|
+
});
|
|
589
|
+
expect(container.innerHTML).toContain('schema-sidebar');
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it('renders with empty history', () => {
|
|
593
|
+
mockExplorerState.mockReturnValue({
|
|
594
|
+
...defaultExplorerState,
|
|
595
|
+
history: [],
|
|
596
|
+
});
|
|
597
|
+
act(() => {
|
|
598
|
+
root.render(React.createElement(Explorer));
|
|
599
|
+
});
|
|
600
|
+
expect(container.innerHTML).not.toBe('');
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it('renders with error and null rows', () => {
|
|
604
|
+
mockExplorerState.mockReturnValue({
|
|
605
|
+
...defaultExplorerState,
|
|
606
|
+
error: 'Connection timeout',
|
|
607
|
+
rows: null,
|
|
608
|
+
columns: [],
|
|
609
|
+
});
|
|
610
|
+
act(() => {
|
|
611
|
+
root.render(React.createElement(Explorer));
|
|
612
|
+
});
|
|
613
|
+
expect(container.innerHTML).not.toBe('');
|
|
614
|
+
});
|
|
615
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useMemo, useReducer } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { ExplorerColorConfig } from '../../colors';
|
|
4
|
+
import type { KustoClient } from '../../services/kusto';
|
|
5
|
+
import { KustoClientContext } from '../../context/KustoClientContext';
|
|
6
|
+
import { ExplorerColorProvider } from '../../context/ExplorerColorContext';
|
|
7
|
+
import { ExplorerStateContext, ExplorerDispatchContext } from '../../context/ExplorerStateContext';
|
|
8
|
+
import { explorerReducer, createInitialState } from '../../state';
|
|
9
|
+
import { DEFAULT_QUERY, buildWellKnownClusters } from '../ExplorerWorkspace/ExplorerWorkspace.logic';
|
|
10
|
+
import type { WellKnownCluster } from '../ExplorerWorkspace/ExplorerWorkspace.logic';
|
|
11
|
+
import { ExplorerWorkspace } from '../ExplorerWorkspace/ExplorerWorkspace';
|
|
12
|
+
|
|
13
|
+
export interface ExplorerProps {
|
|
14
|
+
className?: string;
|
|
15
|
+
isDark?: boolean;
|
|
16
|
+
kustoClient: KustoClient;
|
|
17
|
+
colors: ExplorerColorConfig;
|
|
18
|
+
clusters?: readonly WellKnownCluster[];
|
|
19
|
+
enableTabShortcuts?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Explorer(props: ExplorerProps) {
|
|
23
|
+
const initialQuery = useMemo(() => {
|
|
24
|
+
try {
|
|
25
|
+
const params = new URLSearchParams(window.location.search);
|
|
26
|
+
const q = params.get('query');
|
|
27
|
+
if (q) {
|
|
28
|
+
return q;
|
|
29
|
+
}
|
|
30
|
+
} catch { /* ignore */ }
|
|
31
|
+
return DEFAULT_QUERY;
|
|
32
|
+
}, []);
|
|
33
|
+
|
|
34
|
+
const defaultClusters = useMemo(() => buildWellKnownClusters(props.clusters ?? []), [props.clusters]);
|
|
35
|
+
const initArgs = useMemo(() => ({ initialQuery, defaultClusters }), [initialQuery, defaultClusters]);
|
|
36
|
+
const [state, dispatch] = useReducer(explorerReducer, initArgs, createInitialState);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<KustoClientContext.Provider value={props.kustoClient}>
|
|
40
|
+
<ExplorerColorProvider value={props.colors}>
|
|
41
|
+
<ExplorerStateContext.Provider value={state}>
|
|
42
|
+
<ExplorerDispatchContext.Provider value={dispatch}>
|
|
43
|
+
<ExplorerWorkspace {...props} />
|
|
44
|
+
</ExplorerDispatchContext.Provider>
|
|
45
|
+
</ExplorerStateContext.Provider>
|
|
46
|
+
</ExplorerColorProvider>
|
|
47
|
+
</KustoClientContext.Provider>
|
|
48
|
+
);
|
|
49
|
+
}
|