-
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.
[SIEM] fix ipv6 bug and write tests for ip details page (#37528)
fix ipv6 bug and write tests for ip details page
- Loading branch information
1 parent
348f10e
commit 29e7d63
Showing
4 changed files
with
148 additions
and
7 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
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/siem/public/pages/network/__snapshots__/ip_details.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/siem/public/pages/network/ip_details.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,91 @@ | ||
/* | ||
* 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 { mount, shallow } from 'enzyme'; | ||
import toJson from 'enzyme-to-json'; | ||
import * as React from 'react'; | ||
import { Router } from 'react-router-dom'; | ||
|
||
import '../../mock/match_media'; | ||
import { apolloClientObservable, mockGlobalState, TestProviders } from '../../mock'; | ||
import { IPDetailsComponent, IPDetails } from './ip_details'; | ||
import { FlowTarget } from '../../graphql/types'; | ||
import { createStore, State } from '../../store'; | ||
|
||
type Action = 'PUSH' | 'POP' | 'REPLACE'; | ||
const pop: Action = 'POP'; | ||
|
||
const getMockHistory = (ip: string) => ({ | ||
length: 2, | ||
location: { | ||
pathname: `/network/ip/${ip}`, | ||
search: '', | ||
state: '', | ||
hash: '', | ||
}, | ||
action: pop, | ||
push: jest.fn(), | ||
replace: jest.fn(), | ||
go: jest.fn(), | ||
goBack: jest.fn(), | ||
goForward: jest.fn(), | ||
block: jest.fn(), | ||
createHref: jest.fn(), | ||
listen: jest.fn(), | ||
}); | ||
|
||
const getMockProps = (ip: string) => ({ | ||
filterQuery: 'coolQueryhuh?', | ||
flowTarget: FlowTarget.source, | ||
history: getMockHistory(ip), | ||
location: { | ||
pathname: `/network/ip/${ip}`, | ||
search: '', | ||
state: '', | ||
hash: '', | ||
}, | ||
match: { params: { ip }, isExact: true, path: '', url: '' }, | ||
}); | ||
|
||
describe('Ip Details', () => { | ||
const state: State = mockGlobalState; | ||
|
||
let store = createStore(state, apolloClientObservable); | ||
|
||
beforeEach(() => { | ||
store = createStore(state, apolloClientObservable); | ||
}); | ||
test('it renders', () => { | ||
const wrapper = shallow(<IPDetailsComponent {...getMockProps('123.456.78.90')} />); | ||
expect( | ||
wrapper | ||
.dive() | ||
.find('[data-test-subj="ip-details-page"]') | ||
.exists() | ||
).toBe(true); | ||
}); | ||
|
||
test('it matches the snapshot', () => { | ||
const wrapper = shallow(<IPDetailsComponent {...getMockProps('123.456.78.90')} />); | ||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
|
||
test('it renders ipv6 headline', () => { | ||
const ip = 'fe80--24ce-f7ff-fede-a571'; | ||
const wrapper = mount( | ||
<TestProviders store={store}> | ||
<Router history={getMockHistory(ip)}> | ||
<IPDetails {...getMockProps(ip)} /> | ||
</Router> | ||
</TestProviders> | ||
); | ||
expect( | ||
wrapper | ||
.find('[data-test-subj="ip-details-headline"] [data-test-subj="page_headline_title"]') | ||
.text() | ||
).toEqual('fe80::24ce:f7ff:fede:a571'); | ||
}); | ||
}); |
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