forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Endpoint] add new policy fields (elastic#67323)
- Loading branch information
Showing
4 changed files
with
265 additions
and
50 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
40 changes: 40 additions & 0 deletions
40
.../plugins/siem/public/management/pages/policy/store/policy_list/mock_policy_result_list.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,40 @@ | ||
/* | ||
* 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 { GetPolicyListResponse } from '../../types'; | ||
import { EndpointDocGenerator } from '../../../../../../common/endpoint/generate_data'; | ||
|
||
export const mockPolicyResultList: (options?: { | ||
total?: number; | ||
request_page_size?: number; | ||
request_page_index?: number; | ||
}) => GetPolicyListResponse = (options = {}) => { | ||
const { | ||
total = 1, | ||
request_page_size: requestPageSize = 10, | ||
request_page_index: requestPageIndex = 0, | ||
} = options; | ||
|
||
// Skip any that are before the page we're on | ||
const numberToSkip = requestPageSize * requestPageIndex; | ||
|
||
// total - numberToSkip is the count of non-skipped ones, but return no more than a pageSize, and no less than 0 | ||
const actualCountToReturn = Math.max(Math.min(total - numberToSkip, requestPageSize), 0); | ||
|
||
const policies = []; | ||
for (let index = 0; index < actualCountToReturn; index++) { | ||
const generator = new EndpointDocGenerator('seed'); | ||
policies.push(generator.generatePolicyDatasource()); | ||
} | ||
const mock: GetPolicyListResponse = { | ||
items: policies, | ||
total, | ||
page: requestPageIndex, | ||
perPage: requestPageSize, | ||
success: true, | ||
}; | ||
return mock; | ||
}; |
65 changes: 65 additions & 0 deletions
65
x-pack/plugins/siem/public/management/pages/policy/view/policy_list.test.tsx
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,65 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import * as reactTestingLibrary from '@testing-library/react'; | ||
|
||
import { PolicyList } from './index'; | ||
import { mockPolicyResultList } from '../store/policy_list/mock_policy_result_list'; | ||
import { AppContextTestRender, createAppRootMockRenderer } from '../../../../common/mock/endpoint'; | ||
import { AppAction } from '../../../../common/store/actions'; | ||
|
||
describe('when on the policies page', () => { | ||
let render: () => ReturnType<AppContextTestRender['render']>; | ||
let history: AppContextTestRender['history']; | ||
let store: AppContextTestRender['store']; | ||
|
||
beforeEach(() => { | ||
const mockedContext = createAppRootMockRenderer(); | ||
({ history, store } = mockedContext); | ||
render = () => mockedContext.render(<PolicyList />); | ||
}); | ||
|
||
it('should show a table', async () => { | ||
const renderResult = render(); | ||
const table = await renderResult.findByTestId('policyTable'); | ||
expect(table).not.toBeNull(); | ||
}); | ||
|
||
describe('when list data loads', () => { | ||
let firstPolicyID: string; | ||
beforeEach(() => { | ||
reactTestingLibrary.act(() => { | ||
history.push('/management/policy'); | ||
reactTestingLibrary.act(() => { | ||
const policyListData = mockPolicyResultList({ total: 3 }); | ||
firstPolicyID = policyListData.items[0].id; | ||
const action: AppAction = { | ||
type: 'serverReturnedPolicyListData', | ||
payload: { | ||
policyItems: policyListData.items, | ||
total: policyListData.total, | ||
pageSize: policyListData.perPage, | ||
pageIndex: policyListData.page, | ||
}, | ||
}; | ||
store.dispatch(action); | ||
}); | ||
}); | ||
}); | ||
it('should display rows in the table', async () => { | ||
const renderResult = render(); | ||
const rows = await renderResult.findAllByRole('row'); | ||
expect(rows).toHaveLength(4); | ||
}); | ||
it('should display policy name value as a link', async () => { | ||
const renderResult = render(); | ||
const policyNameLink = (await renderResult.findAllByTestId('policyNameLink'))[0]; | ||
expect(policyNameLink).not.toBeNull(); | ||
expect(policyNameLink.getAttribute('href')).toContain(`policy/${firstPolicyID}`); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.