Skip to content

Commit

Permalink
tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed Sep 2, 2021
1 parent b016f59 commit 647b868
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ describe('helpers', () => {
dataProviders: [],
dateRange: { start: '2020-07-07T08:20:18.966Z', end: '2020-07-08T08:20:18.966Z' },
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -328,7 +329,9 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
savedObjectId: 'savedObject-1',
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down Expand Up @@ -366,6 +369,7 @@ describe('helpers', () => {
dataProviders: [],
dateRange: { start: '2020-07-07T08:20:18.966Z', end: '2020-07-08T08:20:18.966Z' },
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -398,7 +402,9 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
savedObjectId: 'savedObject-1',
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down Expand Up @@ -436,6 +442,7 @@ describe('helpers', () => {
dataProviders: [],
dateRange: { start: '2020-07-07T08:20:18.966Z', end: '2020-07-08T08:20:18.966Z' },
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -468,7 +475,9 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
savedObjectId: 'savedObject-1',
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down Expand Up @@ -504,6 +513,7 @@ describe('helpers', () => {
dataProviders: [],
dateRange: { start: '2020-07-07T08:20:18.966Z', end: '2020-07-08T08:20:18.966Z' },
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -536,7 +546,9 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
savedObjectId: 'savedObject-1',
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down Expand Up @@ -577,6 +589,7 @@ describe('helpers', () => {
dataProviders: [],
dateRange: { start: '2020-07-07T08:20:18.966Z', end: '2020-07-08T08:20:18.966Z' },
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -612,6 +625,8 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down Expand Up @@ -680,6 +695,7 @@ describe('helpers', () => {
dateRange: { start: '2020-07-07T08:20:18.966Z', end: '2020-07-08T08:20:18.966Z' },
dataProviders: [],
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -758,6 +774,8 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down Expand Up @@ -791,6 +809,7 @@ describe('helpers', () => {
dataProviders: [],
dateRange: { end: '2020-10-28T11:37:31.655Z', start: '2020-10-27T11:37:31.655Z' },
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -823,7 +842,9 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
savedObjectId: 'savedObject-1',
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down Expand Up @@ -861,6 +882,7 @@ describe('helpers', () => {
dataProviders: [],
dateRange: { end: '2020-07-08T08:20:18.966Z', start: '2020-07-07T08:20:18.966Z' },
description: '',
documentType: '',
deletedEventIds: [],
eqlOptions: {
eventCategoryField: 'event.category',
Expand Down Expand Up @@ -893,7 +915,9 @@ describe('helpers', () => {
noteIds: [],
pinnedEventIds: {},
pinnedEventsSaveObject: {},
queryFields: [],
savedObjectId: 'savedObject-1',
selectAll: false,
selectedEventIds: {},
show: false,
showCheckboxes: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
const getExpectedColumns = (model: TimelineModel) =>
model.columns.map(migrateColumnWidthToInitialWidth).map(migrateColumnLabelToDisplayAsText);

const {
documentType,
filterManager,
isLoading,
loadingText,
queryFields,
selectAll,
unit,
...timelineToStore
} = mockTimelineModel;

describe('SiemLocalStorage', () => {
const { localStorage, storage } = createSecuritySolutionStorageMock();

Expand All @@ -41,7 +52,7 @@ describe('SiemLocalStorage', () => {
const timelineStorage = useTimelinesStorage();
timelineStorage.addTimeline(TimelineId.hostsPageEvents, mockTimelineModel);
expect(JSON.parse(localStorage.getItem(LOCAL_STORAGE_TIMELINE_KEY))).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
});
});

Expand All @@ -50,8 +61,8 @@ describe('SiemLocalStorage', () => {
timelineStorage.addTimeline(TimelineId.hostsPageEvents, mockTimelineModel);
timelineStorage.addTimeline(TimelineId.hostsPageExternalAlerts, mockTimelineModel);
expect(JSON.parse(localStorage.getItem(LOCAL_STORAGE_TIMELINE_KEY))).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageExternalAlerts]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
[TimelineId.hostsPageExternalAlerts]: timelineToStore,
});
});
});
Expand All @@ -63,8 +74,8 @@ describe('SiemLocalStorage', () => {
timelineStorage.addTimeline(TimelineId.hostsPageExternalAlerts, mockTimelineModel);
const timelines = timelineStorage.getAllTimelines();
expect(timelines).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageExternalAlerts]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
[TimelineId.hostsPageExternalAlerts]: timelineToStore,
});
});

Expand All @@ -80,7 +91,7 @@ describe('SiemLocalStorage', () => {
const timelineStorage = useTimelinesStorage();
timelineStorage.addTimeline(TimelineId.hostsPageEvents, mockTimelineModel);
const timeline = timelineStorage.getTimelineById(TimelineId.hostsPageEvents);
expect(timeline).toEqual(mockTimelineModel);
expect(timeline).toEqual(timelineToStore);
});
});

Expand All @@ -94,8 +105,8 @@ describe('SiemLocalStorage', () => {
TimelineId.hostsPageExternalAlerts,
]);
expect(timelines).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageExternalAlerts]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
[TimelineId.hostsPageExternalAlerts]: timelineToStore,
});
});

Expand Down Expand Up @@ -126,7 +137,7 @@ describe('SiemLocalStorage', () => {
TimelineId.hostsPageExternalAlerts,
]);
expect(timelines).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
});
});

Expand All @@ -152,16 +163,16 @@ describe('SiemLocalStorage', () => {
// all legacy `width` values are migrated to `initialWidth`:
expect(timelines).toStrictEqual({
[TimelineId.hostsPageEvents]: {
...mockTimelineModel,
columns: mockTimelineModel.columns.map((c) => ({
...timelineToStore,
columns: timelineToStore.columns.map((c) => ({
...c,
displayAsText: undefined,
initialWidth: 98765,
width: 98765,
})),
},
[TimelineId.hostsPageExternalAlerts]: {
...mockTimelineModel,
...timelineToStore,
columns: getExpectedColumns(mockTimelineModel),
},
});
Expand All @@ -187,16 +198,16 @@ describe('SiemLocalStorage', () => {

expect(timelines).toStrictEqual({
[TimelineId.hostsPageEvents]: {
...mockTimelineModel,
columns: mockTimelineModel.columns.map((c) => ({
...timelineToStore,
columns: timelineToStore.columns.map((c) => ({
...c,
displayAsText: undefined,
initialWidth: c.initialWidth, // initialWidth is unchanged
width: 98765,
})),
},
[TimelineId.hostsPageExternalAlerts]: {
...mockTimelineModel,
...timelineToStore,
columns: getExpectedColumns(mockTimelineModel),
},
});
Expand All @@ -223,15 +234,15 @@ describe('SiemLocalStorage', () => {
// all legacy `label` values are migrated to `displayAsText`:
expect(timelines).toStrictEqual({
[TimelineId.hostsPageEvents]: {
...mockTimelineModel,
columns: mockTimelineModel.columns.map((c, i) => ({
...timelineToStore,
columns: timelineToStore.columns.map((c, i) => ({
...c,
displayAsText: `A legacy label ${i}`,
label: `A legacy label ${i}`,
})),
},
[TimelineId.hostsPageExternalAlerts]: {
...mockTimelineModel,
...timelineToStore,
columns: getExpectedColumns(mockTimelineModel),
},
});
Expand Down Expand Up @@ -259,16 +270,16 @@ describe('SiemLocalStorage', () => {

expect(timelines).toStrictEqual({
[TimelineId.hostsPageEvents]: {
...mockTimelineModel,
columns: mockTimelineModel.columns.map((c, i) => ({
...timelineToStore,
columns: timelineToStore.columns.map((c, i) => ({
...c,
displayAsText:
'Label will NOT be migrated to displayAsText, because displayAsText already has a value',
label: `A legacy label ${i}`,
})),
},
[TimelineId.hostsPageExternalAlerts]: {
...mockTimelineModel,
...timelineToStore,
columns: getExpectedColumns(mockTimelineModel),
},
});
Expand All @@ -293,11 +304,11 @@ describe('SiemLocalStorage', () => {

expect(timelines).toStrictEqual({
[TimelineId.hostsPageEvents]: {
...mockTimelineModel,
...timelineToStore,
columns: 'this is NOT an array',
},
[TimelineId.hostsPageExternalAlerts]: {
...mockTimelineModel,
...timelineToStore,
columns: getExpectedColumns(mockTimelineModel),
},
});
Expand All @@ -311,8 +322,8 @@ describe('SiemLocalStorage', () => {
timelineStorage.addTimeline(TimelineId.hostsPageExternalAlerts, mockTimelineModel);
const timelines = getAllTimelinesInStorage(storage);
expect(timelines).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageExternalAlerts]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
[TimelineId.hostsPageExternalAlerts]: timelineToStore,
});
});

Expand All @@ -326,16 +337,16 @@ describe('SiemLocalStorage', () => {
it('adds a timeline when storage is empty', () => {
addTimelineInStorage(storage, TimelineId.hostsPageEvents, mockTimelineModel);
expect(JSON.parse(localStorage.getItem(LOCAL_STORAGE_TIMELINE_KEY))).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
});
});

it('adds a timeline when storage contains another timelines', () => {
addTimelineInStorage(storage, TimelineId.hostsPageEvents, mockTimelineModel);
addTimelineInStorage(storage, TimelineId.hostsPageExternalAlerts, mockTimelineModel);
expect(JSON.parse(localStorage.getItem(LOCAL_STORAGE_TIMELINE_KEY))).toEqual({
[TimelineId.hostsPageEvents]: mockTimelineModel,
[TimelineId.hostsPageExternalAlerts]: mockTimelineModel,
[TimelineId.hostsPageEvents]: timelineToStore,
[TimelineId.hostsPageExternalAlerts]: timelineToStore,
});
});
});
Expand Down

0 comments on commit 647b868

Please sign in to comment.