-
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.
Alert list frontend pagination (#57142)
- Loading branch information
Showing
15 changed files
with
469 additions
and
105 deletions.
There are no files selected for viewing
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
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
85 changes: 85 additions & 0 deletions
85
x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/alert_list.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,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Store, createStore, applyMiddleware } from 'redux'; | ||
import { History } from 'history'; | ||
import { alertListReducer } from './reducer'; | ||
import { AlertListState } from '../../types'; | ||
import { alertMiddlewareFactory } from './middleware'; | ||
import { AppAction } from '../action'; | ||
import { coreMock } from 'src/core/public/mocks'; | ||
import { AlertResultList } from '../../../../../common/types'; | ||
import { isOnAlertPage } from './selectors'; | ||
import { createBrowserHistory } from 'history'; | ||
|
||
describe('alert list tests', () => { | ||
let store: Store<AlertListState, AppAction>; | ||
let coreStart: ReturnType<typeof coreMock.createStart>; | ||
let history: History<never>; | ||
beforeEach(() => { | ||
coreStart = coreMock.createStart(); | ||
history = createBrowserHistory(); | ||
const middleware = alertMiddlewareFactory(coreStart); | ||
store = createStore(alertListReducer, applyMiddleware(middleware)); | ||
}); | ||
describe('when the user navigates to the alert list page', () => { | ||
beforeEach(() => { | ||
coreStart.http.get.mockImplementation(async () => { | ||
const response: AlertResultList = { | ||
alerts: [ | ||
{ | ||
'@timestamp': new Date(1542341895000), | ||
agent: { | ||
id: 'ced9c68e-b94a-4d66-bb4c-6106514f0a2f', | ||
version: '3.0.0', | ||
}, | ||
event: { | ||
action: 'open', | ||
}, | ||
file_classification: { | ||
malware_classification: { | ||
score: 3, | ||
}, | ||
}, | ||
host: { | ||
hostname: 'HD-c15-bc09190a', | ||
ip: '10.179.244.14', | ||
os: { | ||
name: 'Windows', | ||
}, | ||
}, | ||
thread: {}, | ||
}, | ||
], | ||
total: 1, | ||
request_page_size: 10, | ||
request_page_index: 0, | ||
result_from_index: 0, | ||
}; | ||
return response; | ||
}); | ||
|
||
// Simulates user navigating to the /alerts page | ||
store.dispatch({ | ||
type: 'userChangedUrl', | ||
payload: { | ||
...history.location, | ||
pathname: '/alerts', | ||
}, | ||
}); | ||
}); | ||
|
||
it("should recognize it's on the alert list page", () => { | ||
const actual = isOnAlertPage(store.getState()); | ||
expect(actual).toBe(true); | ||
}); | ||
|
||
it('should return alertListData', () => { | ||
const actualResponseLength = store.getState().alerts.length; | ||
expect(actualResponseLength).toEqual(1); | ||
}); | ||
}); | ||
}); |
98 changes: 98 additions & 0 deletions
98
.../plugins/endpoint/public/applications/endpoint/store/alerts/alert_list_pagination.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,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Store, createStore, applyMiddleware } from 'redux'; | ||
import { History } from 'history'; | ||
import { alertListReducer } from './reducer'; | ||
import { AlertListState } from '../../types'; | ||
import { alertMiddlewareFactory } from './middleware'; | ||
import { AppAction } from '../action'; | ||
import { coreMock } from 'src/core/public/mocks'; | ||
import { createBrowserHistory } from 'history'; | ||
import { | ||
urlFromNewPageSizeParam, | ||
paginationDataFromUrl, | ||
urlFromNewPageIndexParam, | ||
} from './selectors'; | ||
|
||
describe('alert list pagination', () => { | ||
let store: Store<AlertListState, AppAction>; | ||
let coreStart: ReturnType<typeof coreMock.createStart>; | ||
let history: History<never>; | ||
beforeEach(() => { | ||
coreStart = coreMock.createStart(); | ||
history = createBrowserHistory(); | ||
const middleware = alertMiddlewareFactory(coreStart); | ||
store = createStore(alertListReducer, applyMiddleware(middleware)); | ||
}); | ||
describe('when the user navigates to the alert list page', () => { | ||
describe('when a new page size is passed', () => { | ||
beforeEach(() => { | ||
const urlPageSizeSelector = urlFromNewPageSizeParam(store.getState()); | ||
history.push(urlPageSizeSelector(1)); | ||
store.dispatch({ type: 'userChangedUrl', payload: history.location }); | ||
}); | ||
it('should modify the url correctly', () => { | ||
const actualPaginationQuery = paginationDataFromUrl(store.getState()); | ||
expect(actualPaginationQuery).toMatchInlineSnapshot(` | ||
Object { | ||
"page_size": "1", | ||
} | ||
`); | ||
}); | ||
|
||
describe('and then a new page index is passed', () => { | ||
beforeEach(() => { | ||
const urlPageIndexSelector = urlFromNewPageIndexParam(store.getState()); | ||
history.push(urlPageIndexSelector(1)); | ||
store.dispatch({ type: 'userChangedUrl', payload: history.location }); | ||
}); | ||
it('should modify the url in the correct order', () => { | ||
const actualPaginationQuery = paginationDataFromUrl(store.getState()); | ||
expect(actualPaginationQuery).toMatchInlineSnapshot(` | ||
Object { | ||
"page_index": "1", | ||
"page_size": "1", | ||
} | ||
`); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when a new page index is passed', () => { | ||
beforeEach(() => { | ||
const urlPageIndexSelector = urlFromNewPageIndexParam(store.getState()); | ||
history.push(urlPageIndexSelector(1)); | ||
store.dispatch({ type: 'userChangedUrl', payload: history.location }); | ||
}); | ||
it('should modify the url correctly', () => { | ||
const actualPaginationQuery = paginationDataFromUrl(store.getState()); | ||
expect(actualPaginationQuery).toMatchInlineSnapshot(` | ||
Object { | ||
"page_index": "1", | ||
} | ||
`); | ||
}); | ||
|
||
describe('and then a new page size is passed', () => { | ||
beforeEach(() => { | ||
const urlPageSizeSelector = urlFromNewPageSizeParam(store.getState()); | ||
history.push(urlPageSizeSelector(1)); | ||
store.dispatch({ type: 'userChangedUrl', payload: history.location }); | ||
}); | ||
it('should modify the url correctly and reset index to `0`', () => { | ||
const actualPaginationQuery = paginationDataFromUrl(store.getState()); | ||
expect(actualPaginationQuery).toMatchInlineSnapshot(` | ||
Object { | ||
"page_index": "0", | ||
"page_size": "1", | ||
} | ||
`); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.