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.
[App Search] Credentials: implement working flyout form (elastic#81541)
* Add key name field * Add key type field * Add key read/write fields * Add key engine access / selection * Add key update warning callout * Update flyout body with form components * [PR feedback] i18n - change appSearch.tokens to appSearch.credentials * [PR feedback] Remove unnecessary conditional
- Loading branch information
Showing
15 changed files
with
855 additions
and
4 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
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
11 changes: 11 additions & 0 deletions
11
...pplications/app_search/components/credentials/credentials_flyout/form_components/index.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,11 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { FormKeyName } from './key_name'; | ||
export { FormKeyType } from './key_type'; | ||
export { FormKeyReadWriteAccess } from './key_read_write_access'; | ||
export { FormKeyEngineAccess } from './key_engine_access'; | ||
export { FormKeyUpdateWarning } from './key_update_warning'; |
135 changes: 135 additions & 0 deletions
135
...arch/components/credentials/credentials_flyout/form_components/key_engine_access.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,135 @@ | ||
/* | ||
* 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 { setMockValues, setMockActions } from '../../../../../__mocks__/kea.mock'; | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { EuiRadio, EuiCheckbox } from '@elastic/eui'; | ||
|
||
import { FormKeyEngineAccess, EngineSelection } from './key_engine_access'; | ||
|
||
describe('FormKeyEngineAccess', () => { | ||
const values = { | ||
myRole: { canAccessAllEngines: true }, | ||
fullEngineAccessChecked: true, | ||
}; | ||
const actions = { | ||
setAccessAllEngines: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find(EuiRadio)).toHaveLength(2); | ||
expect(wrapper.find(EngineSelection)).toHaveLength(0); | ||
}); | ||
|
||
it('hides the full access radio option if the user does not have access to all engines', () => { | ||
setMockValues({ | ||
...values, | ||
myRole: { canAccessAllEngines: false }, | ||
}); | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find('#all_engines').prop('hidden')).toEqual(true); | ||
}); | ||
|
||
it('controls the checked values for access radios', () => { | ||
setMockValues({ | ||
...values, | ||
fullEngineAccessChecked: true, | ||
}); | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find('#all_engines').prop('checked')).toEqual(true); | ||
expect(wrapper.find('#all_engines').prop('value')).toEqual('true'); | ||
expect(wrapper.find('#specific_engines').prop('checked')).toEqual(false); | ||
expect(wrapper.find('#specific_engines').prop('value')).toEqual('false'); | ||
|
||
setMockValues({ | ||
...values, | ||
fullEngineAccessChecked: false, | ||
}); | ||
wrapper.setProps({}); // Re-render | ||
|
||
expect(wrapper.find('#all_engines').prop('checked')).toEqual(false); | ||
expect(wrapper.find('#all_engines').prop('value')).toEqual('false'); | ||
expect(wrapper.find('#specific_engines').prop('checked')).toEqual(true); | ||
expect(wrapper.find('#specific_engines').prop('value')).toEqual('true'); | ||
}); | ||
|
||
it('calls setAccessAllEngines when the radios are changed', () => { | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
wrapper.find('#all_engines').simulate('change'); | ||
expect(actions.setAccessAllEngines).toHaveBeenCalledWith(true); | ||
|
||
wrapper.find('#specific_engines').simulate('change'); | ||
expect(actions.setAccessAllEngines).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('displays the engine selection panel if the limited access radio is selected', () => { | ||
setMockValues({ | ||
...values, | ||
fullEngineAccessChecked: false, | ||
}); | ||
const wrapper = shallow(<FormKeyEngineAccess />); | ||
|
||
expect(wrapper.find(EngineSelection)).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe('EngineSelection', () => { | ||
const values = { | ||
activeApiToken: { engines: [] }, | ||
engines: [{ name: 'engine1' }, { name: 'engine2' }, { name: 'engine3' }], | ||
}; | ||
const actions = { | ||
onEngineSelect: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<EngineSelection />); | ||
|
||
expect(wrapper.find('h4').text()).toEqual('Select Engines'); | ||
expect(wrapper.find(EuiCheckbox)).toHaveLength(3); | ||
expect(wrapper.find(EuiCheckbox).first().prop('label')).toEqual('engine1'); | ||
}); | ||
|
||
it('controls the engines checked state', () => { | ||
setMockValues({ | ||
...values, | ||
activeApiToken: { engines: ['engine3'] }, | ||
}); | ||
const wrapper = shallow(<EngineSelection />); | ||
|
||
expect(wrapper.find(EuiCheckbox).first().prop('checked')).toEqual(false); | ||
expect(wrapper.find(EuiCheckbox).last().prop('checked')).toEqual(true); | ||
}); | ||
|
||
it('calls onEngineSelect when the checkboxes are changed', () => { | ||
const wrapper = shallow(<EngineSelection />); | ||
|
||
wrapper.find(EuiCheckbox).first().simulate('change'); | ||
expect(actions.onEngineSelect).toHaveBeenCalledWith('engine1'); | ||
|
||
wrapper.find(EuiCheckbox).last().simulate('change'); | ||
expect(actions.onEngineSelect).toHaveBeenCalledWith('engine3'); | ||
}); | ||
}); |
Oops, something went wrong.