-
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.
Browse files
Browse the repository at this point in the history
* allow users importing data if they are authorized * rename props * rename types * hide import timeline btn if unauthorized * unit test for TimelinesPageComponent * update schemas * update schema Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
6e05272
commit 7372833
Showing
3 changed files
with
117 additions
and
31 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
x-pack/legacy/plugins/siem/public/pages/timelines/timelines_page.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,89 @@ | ||
/* | ||
* 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 { TimelinesPageComponent } from './timelines_page'; | ||
import { useKibana } from '../../lib/kibana'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import React from 'react'; | ||
import ApolloClient from 'apollo-client'; | ||
|
||
jest.mock('../../lib/kibana', () => { | ||
return { | ||
useKibana: jest.fn(), | ||
}; | ||
}); | ||
describe('TimelinesPageComponent', () => { | ||
const mockAppollloClient = {} as ApolloClient<object>; | ||
let wrapper: ShallowWrapper; | ||
|
||
describe('If the user is authorised', () => { | ||
beforeAll(() => { | ||
((useKibana as unknown) as jest.Mock).mockReturnValue({ | ||
services: { | ||
application: { | ||
capabilities: { | ||
siem: { | ||
crud: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
wrapper = shallow(<TimelinesPageComponent apolloClient={mockAppollloClient} />); | ||
}); | ||
|
||
afterAll(() => { | ||
((useKibana as unknown) as jest.Mock).mockReset(); | ||
}); | ||
|
||
test('should not show the import timeline modal by default', () => { | ||
expect( | ||
wrapper.find('[data-test-subj="stateful-open-timeline"]').prop('importDataModalToggle') | ||
).toEqual(false); | ||
}); | ||
|
||
test('should show the import timeline button', () => { | ||
expect(wrapper.find('[data-test-subj="open-import-data-modal-btn"]').exists()).toEqual(true); | ||
}); | ||
|
||
test('should show the import timeline modal after user clicking on the button', () => { | ||
wrapper.find('[data-test-subj="open-import-data-modal-btn"]').simulate('click'); | ||
expect( | ||
wrapper.find('[data-test-subj="stateful-open-timeline"]').prop('importDataModalToggle') | ||
).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('If the user is not authorised', () => { | ||
beforeAll(() => { | ||
((useKibana as unknown) as jest.Mock).mockReturnValue({ | ||
services: { | ||
application: { | ||
capabilities: { | ||
siem: { | ||
crud: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
wrapper = shallow(<TimelinesPageComponent apolloClient={mockAppollloClient} />); | ||
}); | ||
|
||
afterAll(() => { | ||
((useKibana as unknown) as jest.Mock).mockReset(); | ||
}); | ||
test('should not show the import timeline modal by default', () => { | ||
expect( | ||
wrapper.find('[data-test-subj="stateful-open-timeline"]').prop('importDataModalToggle') | ||
).toEqual(false); | ||
}); | ||
|
||
test('should not show the import timeline button', () => { | ||
expect(wrapper.find('[data-test-subj="open-import-data-modal-btn"]').exists()).toEqual(false); | ||
}); | ||
}); | ||
}); |
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