@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,655 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
isCellInRange,
|
|
4
|
+
serializeCellValue,
|
|
5
|
+
formatCellDisplayValue,
|
|
6
|
+
buildSelectionTsv,
|
|
7
|
+
parseHighlightExpr,
|
|
8
|
+
matchesHighlight,
|
|
9
|
+
computeAggregates,
|
|
10
|
+
computeDateDelta,
|
|
11
|
+
shortType,
|
|
12
|
+
computeColumnWidths,
|
|
13
|
+
sortRows,
|
|
14
|
+
filterRows,
|
|
15
|
+
findEmptyColumns,
|
|
16
|
+
} from './ResultsTable.logic';
|
|
17
|
+
import type { CellRange, HighlightExpr } from './ResultsTable.logic';
|
|
18
|
+
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// isCellInRange
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
describe('serializeCellValue', () => {
|
|
24
|
+
it('serializes dynamic objects as JSON', () => {
|
|
25
|
+
expect(serializeCellValue({ foo: 'bar', count: 2 })).toBe('{"foo":"bar","count":2}');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('serializes numbers without locale formatting', () => {
|
|
29
|
+
expect(serializeCellValue(1234)).toBe('1234');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('formatCellDisplayValue', () => {
|
|
34
|
+
it('formats numbers for display', () => {
|
|
35
|
+
expect(formatCellDisplayValue(1234)).toBe('1,234');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('formats dynamic arrays for display', () => {
|
|
39
|
+
expect(formatCellDisplayValue(['a', 'b'])).toBe('["a","b"]');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('isCellInRange', () => {
|
|
44
|
+
const range: CellRange = { startRow: 2, startCol: 3, endRow: 5, endCol: 6 };
|
|
45
|
+
|
|
46
|
+
it('returns true for cell inside range', () => {
|
|
47
|
+
expect(isCellInRange(3, 4, range)).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('returns true for cell on boundary', () => {
|
|
51
|
+
expect(isCellInRange(2, 3, range)).toBe(true);
|
|
52
|
+
expect(isCellInRange(5, 6, range)).toBe(true);
|
|
53
|
+
expect(isCellInRange(2, 6, range)).toBe(true);
|
|
54
|
+
expect(isCellInRange(5, 3, range)).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns false for cell outside range', () => {
|
|
58
|
+
expect(isCellInRange(1, 3, range)).toBe(false);
|
|
59
|
+
expect(isCellInRange(6, 3, range)).toBe(false);
|
|
60
|
+
expect(isCellInRange(3, 2, range)).toBe(false);
|
|
61
|
+
expect(isCellInRange(3, 7, range)).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('handles inverted range (start > end)', () => {
|
|
65
|
+
const inverted: CellRange = { startRow: 5, startCol: 6, endRow: 2, endCol: 3 };
|
|
66
|
+
expect(isCellInRange(3, 4, inverted)).toBe(true);
|
|
67
|
+
expect(isCellInRange(1, 1, inverted)).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('buildSelectionTsv', () => {
|
|
72
|
+
it('builds a TSV payload for a rectangular selection', () => {
|
|
73
|
+
const rows = [
|
|
74
|
+
{ Name: 'Alice', Meta: { team: 'A' } },
|
|
75
|
+
{ Name: 'Bob', Meta: { team: 'B' } },
|
|
76
|
+
];
|
|
77
|
+
const result = buildSelectionTsv(rows, ['Name', 'Meta'], { startRow: 0, startCol: 0, endRow: 1, endCol: 1 });
|
|
78
|
+
expect(result).toBe('Alice\t{"team":"A"}\nBob\t{"team":"B"}');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('returns empty text for an empty selection source', () => {
|
|
82
|
+
expect(buildSelectionTsv([], ['Name'], { startRow: 0, startCol: 0, endRow: 0, endCol: 0 })).toBe('');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// parseHighlightExpr
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
describe('parseHighlightExpr', () => {
|
|
91
|
+
it('parses == expression', () => {
|
|
92
|
+
const result = parseHighlightExpr('Name == Alice');
|
|
93
|
+
expect(result).toEqual({ column: 'Name', op: '==', value: 'Alice' });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('parses != expression', () => {
|
|
97
|
+
const result = parseHighlightExpr('Status != active');
|
|
98
|
+
expect(result).toEqual({ column: 'Status', op: '!=', value: 'active' });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('parses > expression', () => {
|
|
102
|
+
const result = parseHighlightExpr('Age > 30');
|
|
103
|
+
expect(result).toEqual({ column: 'Age', op: '>', value: '30' });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('parses < expression', () => {
|
|
107
|
+
const result = parseHighlightExpr('Age < 30');
|
|
108
|
+
expect(result).toEqual({ column: 'Age', op: '<', value: '30' });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('parses >= expression', () => {
|
|
112
|
+
const result = parseHighlightExpr('Score >= 90');
|
|
113
|
+
expect(result).toEqual({ column: 'Score', op: '>=', value: '90' });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('parses <= expression', () => {
|
|
117
|
+
const result = parseHighlightExpr('Score <= 10');
|
|
118
|
+
expect(result).toEqual({ column: 'Score', op: '<=', value: '10' });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('parses contains expression', () => {
|
|
122
|
+
const result = parseHighlightExpr('Name contains ali');
|
|
123
|
+
expect(result).toEqual({ column: 'Name', op: 'contains', value: 'ali' });
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('parses !contains expression', () => {
|
|
127
|
+
const result = parseHighlightExpr('Name !contains bob');
|
|
128
|
+
expect(result).toEqual({ column: 'Name', op: '!contains', value: 'bob' });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('strips quotes from value', () => {
|
|
132
|
+
const result = parseHighlightExpr("Name == 'Alice'");
|
|
133
|
+
expect(result?.value).toBe('Alice');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('strips double quotes from value', () => {
|
|
137
|
+
const result = parseHighlightExpr('Name == "Alice"');
|
|
138
|
+
expect(result?.value).toBe('Alice');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('returns null for invalid expression', () => {
|
|
142
|
+
expect(parseHighlightExpr('invalid')).toBeNull();
|
|
143
|
+
expect(parseHighlightExpr('')).toBeNull();
|
|
144
|
+
expect(parseHighlightExpr('Name =~ value')).toBeNull();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('handles whitespace', () => {
|
|
148
|
+
const result = parseHighlightExpr(' Name == Alice ');
|
|
149
|
+
expect(result).toEqual({ column: 'Name', op: '==', value: 'Alice' });
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('is case-insensitive for operators', () => {
|
|
153
|
+
const result = parseHighlightExpr('Name CONTAINS alice');
|
|
154
|
+
expect(result?.op).toBe('contains');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
// matchesHighlight
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
|
|
162
|
+
describe('matchesHighlight', () => {
|
|
163
|
+
it('matches == for exact string', () => {
|
|
164
|
+
const expr: HighlightExpr = { column: 'Name', op: '==', value: 'Alice' };
|
|
165
|
+
expect(matchesHighlight({ Name: 'Alice' }, expr)).toBe(true);
|
|
166
|
+
expect(matchesHighlight({ Name: 'Bob' }, expr)).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('matches == for numeric comparison', () => {
|
|
170
|
+
const expr: HighlightExpr = { column: 'Age', op: '==', value: '30' };
|
|
171
|
+
expect(matchesHighlight({ Age: 30 }, expr)).toBe(true);
|
|
172
|
+
expect(matchesHighlight({ Age: 25 }, expr)).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('matches != operator', () => {
|
|
176
|
+
const expr: HighlightExpr = { column: 'Name', op: '!=', value: 'Alice' };
|
|
177
|
+
expect(matchesHighlight({ Name: 'Bob' }, expr)).toBe(true);
|
|
178
|
+
expect(matchesHighlight({ Name: 'Alice' }, expr)).toBe(false);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('matches > operator', () => {
|
|
182
|
+
const expr: HighlightExpr = { column: 'Age', op: '>', value: '30' };
|
|
183
|
+
expect(matchesHighlight({ Age: 31 }, expr)).toBe(true);
|
|
184
|
+
expect(matchesHighlight({ Age: 30 }, expr)).toBe(false);
|
|
185
|
+
expect(matchesHighlight({ Age: 29 }, expr)).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('matches < operator', () => {
|
|
189
|
+
const expr: HighlightExpr = { column: 'Age', op: '<', value: '30' };
|
|
190
|
+
expect(matchesHighlight({ Age: 29 }, expr)).toBe(true);
|
|
191
|
+
expect(matchesHighlight({ Age: 30 }, expr)).toBe(false);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('matches >= operator', () => {
|
|
195
|
+
const expr: HighlightExpr = { column: 'Age', op: '>=', value: '30' };
|
|
196
|
+
expect(matchesHighlight({ Age: 30 }, expr)).toBe(true);
|
|
197
|
+
expect(matchesHighlight({ Age: 31 }, expr)).toBe(true);
|
|
198
|
+
expect(matchesHighlight({ Age: 29 }, expr)).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('matches <= operator', () => {
|
|
202
|
+
const expr: HighlightExpr = { column: 'Age', op: '<=', value: '30' };
|
|
203
|
+
expect(matchesHighlight({ Age: 30 }, expr)).toBe(true);
|
|
204
|
+
expect(matchesHighlight({ Age: 29 }, expr)).toBe(true);
|
|
205
|
+
expect(matchesHighlight({ Age: 31 }, expr)).toBe(false);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('matches contains operator (case-insensitive)', () => {
|
|
209
|
+
const expr: HighlightExpr = { column: 'Name', op: 'contains', value: 'ali' };
|
|
210
|
+
expect(matchesHighlight({ Name: 'Alice' }, expr)).toBe(true);
|
|
211
|
+
expect(matchesHighlight({ Name: 'BOB' }, expr)).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('matches !contains operator', () => {
|
|
215
|
+
const expr: HighlightExpr = { column: 'Name', op: '!contains', value: 'ali' };
|
|
216
|
+
expect(matchesHighlight({ Name: 'Bob' }, expr)).toBe(true);
|
|
217
|
+
expect(matchesHighlight({ Name: 'Alice' }, expr)).toBe(false);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('handles null/undefined values', () => {
|
|
221
|
+
const expr: HighlightExpr = { column: 'Name', op: '==', value: '' };
|
|
222
|
+
expect(matchesHighlight({ Name: null }, expr)).toBe(true);
|
|
223
|
+
expect(matchesHighlight({ Name: undefined }, expr)).toBe(true);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('handles missing column in row', () => {
|
|
227
|
+
const expr: HighlightExpr = { column: 'Missing', op: '==', value: '' };
|
|
228
|
+
expect(matchesHighlight({}, expr)).toBe(true);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('returns false for numeric comparison with non-numeric value', () => {
|
|
232
|
+
const expr: HighlightExpr = { column: 'Name', op: '>', value: '30' };
|
|
233
|
+
expect(matchesHighlight({ Name: 'Alice' }, expr)).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('returns false for unknown operator', () => {
|
|
237
|
+
const expr: HighlightExpr = { column: 'Name', op: 'like', value: 'A' };
|
|
238
|
+
expect(matchesHighlight({ Name: 'Alice' }, expr)).toBe(false);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('matches serialized dynamic values', () => {
|
|
242
|
+
const expr: HighlightExpr = { column: 'Meta', op: 'contains', value: '"team":"A"' };
|
|
243
|
+
expect(matchesHighlight({ Meta: { team: 'A' } }, expr)).toBe(true);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
// computeAggregates
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
|
|
251
|
+
describe('computeAggregates', () => {
|
|
252
|
+
it('returns empty object for empty array', () => {
|
|
253
|
+
expect(computeAggregates([])).toEqual({});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('computes aggregates for a single value', () => {
|
|
257
|
+
const result = computeAggregates([42]);
|
|
258
|
+
expect(result['Count']).toBe('1');
|
|
259
|
+
expect(result['Sum']).toBeDefined();
|
|
260
|
+
expect(result['Avg']).toBeDefined();
|
|
261
|
+
expect(result['Min']).toBeDefined();
|
|
262
|
+
expect(result['Max']).toBeDefined();
|
|
263
|
+
expect(result['P50']).toBeDefined();
|
|
264
|
+
expect(result['P75']).toBeDefined();
|
|
265
|
+
expect(result['P90']).toBeDefined();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('computes correct aggregates for multiple values', () => {
|
|
269
|
+
const values = [10, 20, 30, 40, 50];
|
|
270
|
+
const result = computeAggregates(values);
|
|
271
|
+
expect(result['Count']).toBe('5');
|
|
272
|
+
// Sum = 150
|
|
273
|
+
expect(result['Sum']).toContain('150');
|
|
274
|
+
// Min/Max
|
|
275
|
+
expect(result['Min']).toContain('10');
|
|
276
|
+
expect(result['Max']).toContain('50');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('computes percentiles correctly', () => {
|
|
280
|
+
const values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
281
|
+
const result = computeAggregates(values);
|
|
282
|
+
expect(result['P50']).toBeDefined();
|
|
283
|
+
expect(result['P75']).toBeDefined();
|
|
284
|
+
expect(result['P90']).toBeDefined();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('handles non-integer values in formatting', () => {
|
|
288
|
+
const values = [1.5, 2.5];
|
|
289
|
+
const result = computeAggregates(values);
|
|
290
|
+
expect(result['Avg']).toBeDefined();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// ---------------------------------------------------------------------------
|
|
295
|
+
// computeDateDelta
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
|
|
298
|
+
describe('computeDateDelta', () => {
|
|
299
|
+
it('returns null for less than 2 values', () => {
|
|
300
|
+
expect(computeDateDelta([])).toBeNull();
|
|
301
|
+
expect(computeDateDelta(['2024-01-01'])).toBeNull();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('returns ms for very small deltas', () => {
|
|
305
|
+
const result = computeDateDelta([
|
|
306
|
+
'2024-01-01T00:00:00.000Z',
|
|
307
|
+
'2024-01-01T00:00:00.500Z',
|
|
308
|
+
]);
|
|
309
|
+
expect(result).toBe('500ms');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('returns seconds for delta < 60s', () => {
|
|
313
|
+
const result = computeDateDelta([
|
|
314
|
+
'2024-01-01T00:00:00Z',
|
|
315
|
+
'2024-01-01T00:00:30Z',
|
|
316
|
+
]);
|
|
317
|
+
expect(result).toBe('30.0s');
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('returns minutes for delta < 1h', () => {
|
|
321
|
+
const result = computeDateDelta([
|
|
322
|
+
'2024-01-01T00:00:00Z',
|
|
323
|
+
'2024-01-01T00:05:00Z',
|
|
324
|
+
]);
|
|
325
|
+
expect(result).toBe('5.0m');
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('returns hours for delta < 1d', () => {
|
|
329
|
+
const result = computeDateDelta([
|
|
330
|
+
'2024-01-01T00:00:00Z',
|
|
331
|
+
'2024-01-01T03:00:00Z',
|
|
332
|
+
]);
|
|
333
|
+
expect(result).toBe('3.0h');
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('returns days for delta >= 1d', () => {
|
|
337
|
+
const result = computeDateDelta([
|
|
338
|
+
'2024-01-01T00:00:00Z',
|
|
339
|
+
'2024-01-03T00:00:00Z',
|
|
340
|
+
]);
|
|
341
|
+
expect(result).toBe('2.0d');
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('returns null for invalid dates', () => {
|
|
345
|
+
expect(computeDateDelta(['not-a-date', 'also-not'])).toBeNull();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('handles mixed valid and invalid dates', () => {
|
|
349
|
+
const result = computeDateDelta([
|
|
350
|
+
'2024-01-01T00:00:00Z',
|
|
351
|
+
'invalid',
|
|
352
|
+
'2024-01-01T00:00:01Z',
|
|
353
|
+
]);
|
|
354
|
+
expect(result).toBe('1.0s');
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// ---------------------------------------------------------------------------
|
|
359
|
+
// shortType
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
|
|
362
|
+
describe('shortType', () => {
|
|
363
|
+
it('maps System.String to string', () => {
|
|
364
|
+
expect(shortType('System.String')).toBe('string');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('maps System.Int64 to long', () => {
|
|
368
|
+
expect(shortType('System.Int64')).toBe('long');
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('maps System.Int32 to int', () => {
|
|
372
|
+
expect(shortType('System.Int32')).toBe('int');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('maps System.Double to real', () => {
|
|
376
|
+
expect(shortType('System.Double')).toBe('real');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('maps System.Single to real', () => {
|
|
380
|
+
expect(shortType('System.Single')).toBe('real');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('maps System.Boolean to bool', () => {
|
|
384
|
+
expect(shortType('System.Boolean')).toBe('bool');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('maps System.DateTime to datetime', () => {
|
|
388
|
+
expect(shortType('System.DateTime')).toBe('datetime');
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('maps System.TimeSpan to timespan', () => {
|
|
392
|
+
expect(shortType('System.TimeSpan')).toBe('timespan');
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('maps System.Guid to guid', () => {
|
|
396
|
+
expect(shortType('System.Guid')).toBe('guid');
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('maps System.Object to dynamic', () => {
|
|
400
|
+
expect(shortType('System.Object')).toBe('dynamic');
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('maps System.SByte to bool', () => {
|
|
404
|
+
expect(shortType('System.SByte')).toBe('bool');
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('returns lowercase last segment for unknown System.* types', () => {
|
|
408
|
+
expect(shortType('System.Decimal')).toBe('decimal');
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('returns non-System types unchanged', () => {
|
|
412
|
+
expect(shortType('customtype')).toBe('customtype');
|
|
413
|
+
expect(shortType('MyType')).toBe('MyType');
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// ---------------------------------------------------------------------------
|
|
418
|
+
// computeColumnWidths
|
|
419
|
+
// ---------------------------------------------------------------------------
|
|
420
|
+
|
|
421
|
+
describe('computeColumnWidths', () => {
|
|
422
|
+
it('returns widths for basic columns', () => {
|
|
423
|
+
const widths = computeColumnWidths(['Name', 'Age'], [{ Name: 'Alice', Age: 30 }]);
|
|
424
|
+
expect(widths).toHaveLength(2);
|
|
425
|
+
widths.forEach((w) => {
|
|
426
|
+
expect(w).toBeGreaterThanOrEqual(60);
|
|
427
|
+
expect(w).toBeLessThanOrEqual(500);
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it('accounts for column types in header length', () => {
|
|
432
|
+
const withTypes = computeColumnWidths(
|
|
433
|
+
['Name'],
|
|
434
|
+
[{ Name: 'A' }],
|
|
435
|
+
{ Name: 'System.String' },
|
|
436
|
+
);
|
|
437
|
+
const withoutTypes = computeColumnWidths(['Name'], [{ Name: 'A' }]);
|
|
438
|
+
expect(withTypes[0]).toBeGreaterThanOrEqual(withoutTypes[0]);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('handles empty rows', () => {
|
|
442
|
+
const widths = computeColumnWidths(['Col'], []);
|
|
443
|
+
expect(widths).toHaveLength(1);
|
|
444
|
+
expect(widths[0]).toBeGreaterThanOrEqual(60);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('caps wide values at 500', () => {
|
|
448
|
+
const longValue = 'x'.repeat(200);
|
|
449
|
+
const widths = computeColumnWidths(['Col'], [{ Col: longValue }]);
|
|
450
|
+
expect(widths[0]).toBeLessThanOrEqual(500);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it('ensures minimum width of 60', () => {
|
|
454
|
+
const widths = computeColumnWidths(['A'], [{ A: '' }]);
|
|
455
|
+
expect(widths[0]).toBeGreaterThanOrEqual(60);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it('handles null/undefined values in rows', () => {
|
|
459
|
+
const widths = computeColumnWidths(['Col'], [{ Col: null }, { Col: undefined }]);
|
|
460
|
+
expect(widths).toHaveLength(1);
|
|
461
|
+
expect(widths[0]).toBeGreaterThanOrEqual(60);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it('samples only first 100 rows', () => {
|
|
465
|
+
const rows = Array.from({ length: 200 }, (_, i) => ({ Col: String(i) }));
|
|
466
|
+
const widths = computeColumnWidths(['Col'], rows);
|
|
467
|
+
expect(widths).toHaveLength(1);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('accounts for serialized dynamic values', () => {
|
|
471
|
+
const widths = computeColumnWidths(['Meta'], [{ Meta: { team: 'alpha', enabled: true } }]);
|
|
472
|
+
expect(widths[0]).toBeGreaterThan(60);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// ---------------------------------------------------------------------------
|
|
477
|
+
// sortRows
|
|
478
|
+
// ---------------------------------------------------------------------------
|
|
479
|
+
|
|
480
|
+
describe('sortRows', () => {
|
|
481
|
+
const rows = [
|
|
482
|
+
{ Name: 'Charlie', Age: 30 },
|
|
483
|
+
{ Name: 'Alice', Age: 25 },
|
|
484
|
+
{ Name: 'Bob', Age: 35 },
|
|
485
|
+
];
|
|
486
|
+
|
|
487
|
+
it('sorts ascending by numeric column', () => {
|
|
488
|
+
const sorted = sortRows(rows, 'Age', 'asc');
|
|
489
|
+
expect(sorted.map((r) => r['Age'])).toEqual([25, 30, 35]);
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
it('sorts descending by numeric column', () => {
|
|
493
|
+
const sorted = sortRows(rows, 'Age', 'desc');
|
|
494
|
+
expect(sorted.map((r) => r['Age'])).toEqual([35, 30, 25]);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('sorts ascending by string column', () => {
|
|
498
|
+
const sorted = sortRows(rows, 'Name', 'asc');
|
|
499
|
+
expect(sorted.map((r) => r['Name'])).toEqual(['Alice', 'Bob', 'Charlie']);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('sorts descending by string column', () => {
|
|
503
|
+
const sorted = sortRows(rows, 'Name', 'desc');
|
|
504
|
+
expect(sorted.map((r) => r['Name'])).toEqual(['Charlie', 'Bob', 'Alice']);
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it('handles null values in ascending sort', () => {
|
|
508
|
+
const withNull = [{ Val: null }, { Val: 10 }, { Val: 5 }];
|
|
509
|
+
const sorted = sortRows(withNull, 'Val', 'asc');
|
|
510
|
+
expect(sorted[0]['Val']).toBeNull();
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it('handles null values in descending sort', () => {
|
|
514
|
+
const withNull = [{ Val: null }, { Val: 10 }, { Val: 5 }];
|
|
515
|
+
const sorted = sortRows(withNull, 'Val', 'desc');
|
|
516
|
+
expect(sorted[sorted.length - 1]['Val']).toBeNull();
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it('handles undefined values', () => {
|
|
520
|
+
const withUndef = [{ Val: undefined }, { Val: 10 }];
|
|
521
|
+
const sorted = sortRows(withUndef, 'Val', 'asc');
|
|
522
|
+
expect(sorted[0]['Val']).toBeUndefined();
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('returns rows unchanged when sortColumn is null', () => {
|
|
526
|
+
const sorted = sortRows(rows, null, 'asc');
|
|
527
|
+
expect(sorted).toBe(rows);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it('returns rows unchanged when sortDir is null', () => {
|
|
531
|
+
const sorted = sortRows(rows, 'Name', null);
|
|
532
|
+
expect(sorted).toBe(rows);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it('does not mutate original array', () => {
|
|
536
|
+
const original = [...rows];
|
|
537
|
+
sortRows(rows, 'Age', 'asc');
|
|
538
|
+
expect(rows).toEqual(original);
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// ---------------------------------------------------------------------------
|
|
543
|
+
// filterRows
|
|
544
|
+
// ---------------------------------------------------------------------------
|
|
545
|
+
|
|
546
|
+
describe('filterRows', () => {
|
|
547
|
+
const columns = ['Name', 'City'];
|
|
548
|
+
const rows = [
|
|
549
|
+
{ Name: 'Alice', City: 'Seattle' },
|
|
550
|
+
{ Name: 'Bob', City: 'Portland' },
|
|
551
|
+
{ Name: 'Charlie', City: 'Seattle' },
|
|
552
|
+
];
|
|
553
|
+
|
|
554
|
+
it('returns all rows when no filters', () => {
|
|
555
|
+
const result = filterRows(rows, columns, '', {});
|
|
556
|
+
expect(result).toEqual(rows);
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
it('filters by global search (case-insensitive)', () => {
|
|
560
|
+
const result = filterRows(rows, columns, 'alice', {});
|
|
561
|
+
expect(result).toHaveLength(1);
|
|
562
|
+
expect(result[0]['Name']).toBe('Alice');
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('filters by column filter', () => {
|
|
566
|
+
const result = filterRows(rows, columns, '', { City: 'seattle' });
|
|
567
|
+
expect(result).toHaveLength(2);
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it('combines global and column filters', () => {
|
|
571
|
+
const result = filterRows(rows, columns, 'seattle', { Name: 'alice' });
|
|
572
|
+
expect(result).toHaveLength(1);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
it('skips empty column filter values', () => {
|
|
576
|
+
const result = filterRows(rows, columns, '', { City: '' });
|
|
577
|
+
expect(result).toEqual(rows);
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it('handles null/undefined values in rows', () => {
|
|
581
|
+
const withNull = [{ Name: null, City: 'Seattle' }, { Name: 'Bob', City: undefined }];
|
|
582
|
+
const result = filterRows(withNull, columns, 'seattle', {});
|
|
583
|
+
expect(result).toHaveLength(1);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
it('is case-insensitive for column filters', () => {
|
|
587
|
+
const result = filterRows(rows, columns, '', { Name: 'ALICE' });
|
|
588
|
+
expect(result).toHaveLength(1);
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('global search matches any column', () => {
|
|
592
|
+
const result = filterRows(rows, columns, 'port', {});
|
|
593
|
+
expect(result).toHaveLength(1);
|
|
594
|
+
expect(result[0]['Name']).toBe('Bob');
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it('filters serialized dynamic values', () => {
|
|
598
|
+
const result = filterRows(
|
|
599
|
+
[{ Meta: { team: 'Alpha' } }, { Meta: { team: 'Beta' } }],
|
|
600
|
+
['Meta'],
|
|
601
|
+
'alpha',
|
|
602
|
+
{},
|
|
603
|
+
);
|
|
604
|
+
expect(result).toHaveLength(1);
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// ---------------------------------------------------------------------------
|
|
609
|
+
// findEmptyColumns
|
|
610
|
+
// ---------------------------------------------------------------------------
|
|
611
|
+
|
|
612
|
+
describe('findEmptyColumns', () => {
|
|
613
|
+
it('detects columns with all null values', () => {
|
|
614
|
+
const rows = [{ A: null, B: 1 }, { A: null, B: 2 }];
|
|
615
|
+
const result = findEmptyColumns(['A', 'B'], rows);
|
|
616
|
+
expect(result.has('A')).toBe(true);
|
|
617
|
+
expect(result.has('B')).toBe(false);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it('detects columns with all undefined values', () => {
|
|
621
|
+
const rows = [{ A: undefined, B: 'x' }];
|
|
622
|
+
const result = findEmptyColumns(['A', 'B'], rows);
|
|
623
|
+
expect(result.has('A')).toBe(true);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('detects columns with all empty string values', () => {
|
|
627
|
+
const rows = [{ A: '', B: 'x' }, { A: '', B: 'y' }];
|
|
628
|
+
const result = findEmptyColumns(['A', 'B'], rows);
|
|
629
|
+
expect(result.has('A')).toBe(true);
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('detects mixed null/undefined/empty as empty', () => {
|
|
633
|
+
const rows = [{ A: null }, { A: undefined }, { A: '' }];
|
|
634
|
+
const result = findEmptyColumns(['A'], rows);
|
|
635
|
+
expect(result.has('A')).toBe(true);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it('returns empty set when no columns are empty', () => {
|
|
639
|
+
const rows = [{ A: 1, B: 'x' }];
|
|
640
|
+
const result = findEmptyColumns(['A', 'B'], rows);
|
|
641
|
+
expect(result.size).toBe(0);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it('treats 0 and false as non-empty', () => {
|
|
645
|
+
const rows = [{ A: 0 }, { A: false }];
|
|
646
|
+
const result = findEmptyColumns(['A'], rows as Record<string, unknown>[]);
|
|
647
|
+
expect(result.has('A')).toBe(false);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it('handles empty rows array', () => {
|
|
651
|
+
const result = findEmptyColumns(['A', 'B'], []);
|
|
652
|
+
expect(result.has('A')).toBe(true);
|
|
653
|
+
expect(result.has('B')).toBe(true);
|
|
654
|
+
});
|
|
655
|
+
});
|