-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SecuritySolution] Remove usage of redux observables from the localst…
…orage and change epics (#175450) ## Summary As a first step in removing `redux-observable` (see #175427), this PR transforms all localstorage epics and the timeline change epic into regular redux middlewares. ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
1 parent
597cfeb
commit 0943f25
Showing
11 changed files
with
221 additions
and
271 deletions.
There are no files selected for viewing
185 changes: 0 additions & 185 deletions
185
x-pack/plugins/security_solution/public/common/store/data_table/epic_local_storage.test.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
.../plugins/security_solution/public/common/store/data_table/middlware_local_storage.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import '../../mock/match_media'; | ||
import { | ||
mockGlobalState, | ||
SUB_PLUGINS_REDUCER, | ||
defaultHeaders, | ||
createSecuritySolutionStorageMock, | ||
kibanaObservable, | ||
} from '../../mock'; | ||
|
||
import type { State } from '..'; | ||
import { createStore } from '..'; | ||
|
||
import { addTableInStorage } from '../../../timelines/containers/local_storage'; | ||
import { Direction } from '../../../../common/search_strategy'; | ||
import { TableId, dataTableActions } from '@kbn/securitysolution-data-table'; | ||
|
||
const { | ||
applyDeltaToColumnWidth, | ||
removeColumn, | ||
updateColumnOrder, | ||
updateColumns, | ||
updateColumnWidth, | ||
updateItemsPerPage, | ||
updateSort, | ||
upsertColumn, | ||
} = dataTableActions; | ||
|
||
jest.mock('../../../timelines/containers/local_storage'); | ||
|
||
const addTableInStorageMock = addTableInStorage as jest.Mock; | ||
|
||
describe('DataTable localStorage middleware', () => { | ||
const state: State = mockGlobalState; | ||
const { storage } = createSecuritySolutionStorageMock(); | ||
let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); | ||
|
||
beforeEach(() => { | ||
store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); | ||
}); | ||
|
||
it('should call the storage method with the most recent table state', () => { | ||
store.dispatch(updateItemsPerPage({ id: TableId.test, itemsPerPage: 42 })); | ||
expect(addTableInStorageMock).toHaveBeenCalledWith( | ||
storage, | ||
TableId.test, | ||
expect.objectContaining({ | ||
itemsPerPage: 42, | ||
}) | ||
); | ||
}); | ||
|
||
it('persist adding / reordering of a column correctly', () => { | ||
store.dispatch(upsertColumn({ id: TableId.test, index: 1, column: defaultHeaders[0] })); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('persist timeline when removing a column ', async () => { | ||
store.dispatch(removeColumn({ id: TableId.test, columnId: '@timestamp' })); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('persists resizing of a column', async () => { | ||
store.dispatch( | ||
applyDeltaToColumnWidth({ id: TableId.test, columnId: '@timestamp', delta: 80 }) | ||
); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('persist the resetting of the fields', async () => { | ||
store.dispatch(updateColumns({ id: TableId.test, columns: defaultHeaders })); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('persist items per page', async () => { | ||
store.dispatch(updateItemsPerPage({ id: TableId.test, itemsPerPage: 50 })); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('persist the sorting of a column', async () => { | ||
store.dispatch( | ||
updateSort({ | ||
id: TableId.test, | ||
sort: [ | ||
{ | ||
columnId: 'event.severity', | ||
columnType: 'number', | ||
esTypes: ['long'], | ||
sortDirection: Direction.desc, | ||
}, | ||
], | ||
}) | ||
); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('persists updates to the column order to local storage', async () => { | ||
store.dispatch( | ||
updateColumnOrder({ | ||
columnIds: ['event.severity', '@timestamp', 'event.category'], | ||
id: TableId.test, | ||
}) | ||
); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('persists updates to the column width to local storage', async () => { | ||
store.dispatch( | ||
updateColumnWidth({ | ||
columnId: 'event.severity', | ||
id: TableId.test, | ||
width: 123, | ||
}) | ||
); | ||
expect(addTableInStorageMock).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.