-
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.
- Loading branch information
Showing
11 changed files
with
392 additions
and
41 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
110 changes: 110 additions & 0 deletions
110
x-pack/plugins/security/public/management/role_combo_box/role_combo_box.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,110 @@ | ||
/* | ||
* 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 { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; | ||
|
||
import { RoleComboBox } from '.'; | ||
import { EuiComboBox } from '@elastic/eui'; | ||
import { findTestSubject } from 'test_utils/find_test_subject'; | ||
|
||
describe('RoleComboBox', () => { | ||
it('renders the provided list of roles via EuiComboBox options', () => { | ||
const availableRoles = [ | ||
{ | ||
name: 'role-1', | ||
elasticsearch: { cluster: [], indices: [], run_as: [] }, | ||
kibana: [], | ||
metadata: {}, | ||
}, | ||
{ | ||
name: 'role-2', | ||
elasticsearch: { cluster: [], indices: [], run_as: [] }, | ||
kibana: [], | ||
metadata: {}, | ||
}, | ||
]; | ||
const wrapper = mountWithIntl( | ||
<RoleComboBox availableRoles={availableRoles} selectedRoleNames={[]} onChange={jest.fn()} /> | ||
); | ||
|
||
expect(wrapper.find(EuiComboBox).props().options).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"color": "default", | ||
"data-test-subj": "roleOption-role-1", | ||
"label": "role-1", | ||
"value": Object { | ||
"isDeprecated": false, | ||
}, | ||
}, | ||
Object { | ||
"color": "default", | ||
"data-test-subj": "roleOption-role-2", | ||
"label": "role-2", | ||
"value": Object { | ||
"isDeprecated": false, | ||
}, | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('renders deprecated roles as such', () => { | ||
const availableRoles = [ | ||
{ | ||
name: 'role-1', | ||
elasticsearch: { cluster: [], indices: [], run_as: [] }, | ||
kibana: [], | ||
metadata: { _deprecated: true }, | ||
}, | ||
]; | ||
const wrapper = mountWithIntl( | ||
<RoleComboBox availableRoles={availableRoles} selectedRoleNames={[]} onChange={jest.fn()} /> | ||
); | ||
|
||
expect(wrapper.find(EuiComboBox).props().options).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"color": "warning", | ||
"data-test-subj": "roleOption-role-1", | ||
"label": "role-1", | ||
"value": Object { | ||
"isDeprecated": true, | ||
}, | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('renders the selected role names in the expanded list, coded according to deprecated status', () => { | ||
const availableRoles = [ | ||
{ | ||
name: 'role-1', | ||
elasticsearch: { cluster: [], indices: [], run_as: [] }, | ||
kibana: [], | ||
metadata: {}, | ||
}, | ||
{ | ||
name: 'role-2', | ||
elasticsearch: { cluster: [], indices: [], run_as: [] }, | ||
kibana: [], | ||
metadata: {}, | ||
}, | ||
]; | ||
const wrapper = mountWithIntl( | ||
<div> | ||
<RoleComboBox availableRoles={availableRoles} selectedRoleNames={[]} onChange={jest.fn()} /> | ||
</div> | ||
); | ||
|
||
findTestSubject(wrapper, 'comboBoxToggleListButton').simulate('click'); | ||
|
||
wrapper.find(EuiComboBox).setState({ isListOpen: true }); | ||
|
||
expect(findTestSubject(wrapper, 'rolesDropdown-renderOption')).toMatchInlineSnapshot(`null`); | ||
}); | ||
}); |
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
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/security/public/management/role_combo_box/role_combo_box_option.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,57 @@ | ||
/* | ||
* 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 { shallowWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { RoleComboBoxOption } from './role_combo_box_option'; | ||
|
||
describe('RoleComboBoxOption', () => { | ||
it('renders a regular role correctly', () => { | ||
const wrapper = shallowWithIntl( | ||
<RoleComboBoxOption | ||
option={{ | ||
color: 'default', | ||
label: 'role-1', | ||
}} | ||
/> | ||
); | ||
|
||
expect(wrapper).toMatchInlineSnapshot(` | ||
<EuiText | ||
color="default" | ||
data-test-subj="rolesDropdown-renderOption" | ||
> | ||
role-1 | ||
</EuiText> | ||
`); | ||
}); | ||
|
||
it('renders a deprecated role correctly', () => { | ||
const wrapper = shallowWithIntl( | ||
<RoleComboBoxOption | ||
option={{ | ||
color: 'warning', | ||
label: 'role-1', | ||
value: { | ||
isDeprecated: true, | ||
}, | ||
}} | ||
/> | ||
); | ||
|
||
expect(wrapper).toMatchInlineSnapshot(` | ||
<EuiText | ||
color="warning" | ||
data-test-subj="rolesDropdown-renderOption" | ||
> | ||
role-1 | ||
(deprecated) | ||
</EuiText> | ||
`); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/security/public/management/role_combo_box/role_combo_box_option.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,31 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
import { EuiComboBoxOptionProps, EuiText } from '@elastic/eui'; | ||
|
||
interface Props { | ||
option: EuiComboBoxOptionProps<{ isDeprecated: boolean }>; | ||
} | ||
|
||
export const RoleComboBoxOption = ({ option }: Props) => { | ||
const isDeprecated = option.value?.isDeprecated ?? false; | ||
const deprecatedLabel = i18n.translate( | ||
'xpack.security.management.users.editUser.deprecatedRoleText', | ||
{ | ||
defaultMessage: '(deprecated)', | ||
} | ||
); | ||
|
||
return ( | ||
<EuiText color={option.color as any} data-test-subj="rolesDropdown-renderOption"> | ||
{option.label} {isDeprecated ? deprecatedLabel : ''} | ||
</EuiText> | ||
); | ||
}; |
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.