Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion public/pages/DefineDetector/utils/__tests__/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
*/

import { INITIAL_DETECTOR_DEFINITION_VALUES } from '../../utils/constants';
import { DATA_TYPES } from '../../../../utils/constants';
import { getRandomDetector } from '../../../../redux/reducers/__tests__/utils';
import {
detectorDefinitionToFormik,
filtersToFormik,
} from '../../utils/helpers';
import { Detector } from '../../../../models/interfaces';
import { Detector, OPERATORS_MAP, FILTER_TYPES } from '../../../../models/interfaces';

describe('detectorDefinitionToFormik', () => {
test('should return initialValues if detector is null', () => {
Expand Down Expand Up @@ -53,4 +54,61 @@ describe('detectorDefinitionToFormik', () => {
windowDelay: randomDetector.windowDelay.period.interval,
});
});
test('upgrade old detector\'s filters to include filter type', () => {
const randomDetector = getRandomDetector();
randomDetector.uiMetadata = {
features: {},
filters : [
{
fieldInfo : [
{
label : 'service',
type : DATA_TYPES.KEYWORD
}
],
fieldValue : "app_3",
operator : OPERATORS_MAP.IS
},
{
fieldInfo : [
{
label : "host",
type : DATA_TYPES.KEYWORD
}
],
fieldValue : "server_2",
operator : OPERATORS_MAP.IS
}
],
filterType : FILTER_TYPES.SIMPLE
};
const adFormikValues = filtersToFormik(randomDetector);
expect(adFormikValues).toEqual(
[
{
fieldInfo : [
{
label : 'service',
type : DATA_TYPES.KEYWORD
}
],
fieldValue : "app_3",
operator : OPERATORS_MAP.IS,
filterType : FILTER_TYPES.SIMPLE
},
{
fieldInfo : [
{
label : "host",
type : DATA_TYPES.KEYWORD
}
],
fieldValue : "server_2",
operator : OPERATORS_MAP.IS,
filterType : FILTER_TYPES.SIMPLE
}
]
);
});

});
8 changes: 2 additions & 6 deletions public/pages/DefineDetector/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ export function filtersToFormik(detector: Detector): UIFilter[] {
},
];
} else {
curFilters.forEach((filter: UIFilter) => {
return {
...filter,
filterType: curFilterType,
};
});
curFilters.forEach((filter: UIFilter) =>
filter.filterType = curFilterType);
}
}
return curFilters;
Expand Down