|
1 | 1 | import { enableMapSet } from 'immer'; |
| 2 | +import { buildSeverityClassExpressionV1 } from '@hyperdx/common-utils/dist/core/severity'; |
2 | 3 | import { filtersToQuery } from '@hyperdx/common-utils/dist/filters'; |
3 | 4 | import { act, renderHook } from '@testing-library/react'; |
4 | 5 |
|
@@ -1252,6 +1253,83 @@ describe('searchFilters', () => { |
1252 | 1253 | { type: 'sql', condition: `ServiceName IN ('app')` }, |
1253 | 1254 | ]); |
1254 | 1255 | }); |
| 1256 | + |
| 1257 | + describe('with a severity class key', () => { |
| 1258 | + const OLD = buildSeverityClassExpressionV1({ |
| 1259 | + numberExpr: 'OldSeverityNumber', |
| 1260 | + textExpr: 'SeverityText', |
| 1261 | + }); |
| 1262 | + const NEW = buildSeverityClassExpressionV1({ |
| 1263 | + numberExpr: 'SeverityNumber', |
| 1264 | + textExpr: 'SeverityText', |
| 1265 | + }); |
| 1266 | + const sql = (condition: string): ConditionFilter => ({ |
| 1267 | + type: 'sql', |
| 1268 | + condition, |
| 1269 | + }); |
| 1270 | + |
| 1271 | + it.each([ |
| 1272 | + [ |
| 1273 | + 'renames a stale key', |
| 1274 | + [sql(`${OLD} IN ('ERROR')`), sql(`ServiceName IN ('app')`)], |
| 1275 | + NEW, |
| 1276 | + [], |
| 1277 | + [sql(`${NEW} IN ('ERROR')`), sql(`ServiceName IN ('app')`)], |
| 1278 | + ], |
| 1279 | + [ |
| 1280 | + 'keeps the current key without a URL update', |
| 1281 | + [sql(`${NEW} IN ('ERROR')`)], |
| 1282 | + NEW, |
| 1283 | + [], |
| 1284 | + null, |
| 1285 | + ], |
| 1286 | + [ |
| 1287 | + 'drops class keys for a source without one', |
| 1288 | + [sql(`${OLD} IN ('ERROR')`), sql(`ServiceName IN ('app')`)], |
| 1289 | + null, |
| 1290 | + [OLD], |
| 1291 | + [sql(`ServiceName IN ('app')`)], |
| 1292 | + ], |
| 1293 | + [ |
| 1294 | + 'merges a stale key into the current one, the later key winning', |
| 1295 | + [ |
| 1296 | + sql(`${OLD} IN ('ERROR', 'WARN')`), |
| 1297 | + sql(`${NEW} IN ('FATAL')`), |
| 1298 | + sql(`${NEW} NOT IN ('ERROR')`), |
| 1299 | + ], |
| 1300 | + NEW, |
| 1301 | + [], |
| 1302 | + [ |
| 1303 | + sql(`${NEW} IN ('WARN', 'FATAL')`), |
| 1304 | + sql(`${NEW} NOT IN ('ERROR')`), |
| 1305 | + ], |
| 1306 | + ], |
| 1307 | + ])('%s', (_, searchQuery, classKey, expectedDropped, expectedUrl) => { |
| 1308 | + const onFilterChangeLocal = jest.fn(); |
| 1309 | + const { result } = renderHook(() => |
| 1310 | + useSearchPageFilterState({ |
| 1311 | + searchQuery, |
| 1312 | + onFilterChange: onFilterChangeLocal, |
| 1313 | + knownColumns: new Set(), |
| 1314 | + }), |
| 1315 | + ); |
| 1316 | + |
| 1317 | + let dropped: string[] = []; |
| 1318 | + act(() => { |
| 1319 | + dropped = result.current.retainFiltersByColumns( |
| 1320 | + new Set(['ServiceName']), |
| 1321 | + classKey, |
| 1322 | + ); |
| 1323 | + }); |
| 1324 | + |
| 1325 | + expect(dropped).toEqual(expectedDropped); |
| 1326 | + if (expectedUrl == null) { |
| 1327 | + expect(onFilterChangeLocal).not.toHaveBeenCalled(); |
| 1328 | + } else { |
| 1329 | + expect(onFilterChangeLocal).toHaveBeenLastCalledWith(expectedUrl); |
| 1330 | + } |
| 1331 | + }); |
| 1332 | + }); |
1255 | 1333 | }); |
1256 | 1334 | }); |
1257 | 1335 | }); |
0 commit comments