Skip to content

Commit

Permalink
cleanup and additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Jul 30, 2018
1 parent 46d1d22 commit 08d9096
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 221 deletions.
32 changes: 32 additions & 0 deletions src/core_plugins/kibana/public/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`SpaceSelector renders without crashing 1`] = `
onChange={[Function]}
options={Array []}
placeholder="choose space(s)"
renderOption={[Function]}
selectedOptions={Array []}
singleSelection={false}
>
Expand Down Expand Up @@ -58,123 +59,111 @@ exports[`SpaceSelector renders without crashing 1`] = `
className="euiFormControlLayout"
>
<div
className="euiComboBox__inputWrap"
data-test-subj="comboBoxInput"
onClick={[Function]}
className="euiFormControlLayout__childrenWrapper"
>
<p
className="euiComboBoxPlaceholder"
>
choose space(s)
</p>
<AutosizeInput
aria-hidden={true}
className="euiComboBox__input"
data-test-subj="comboBoxSearchInput"
injectStyles={true}
inputRef={[Function]}
minWidth={1}
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
style={
Object {
"fontSize": 14,
}
}
value=""
<div
className="euiComboBox__inputWrap"
data-test-subj="comboBoxInput"
onClick={[Function]}
>
<div
<p
className="euiComboBoxPlaceholder"
>
choose space(s)
</p>
<AutosizeInput
aria-hidden={true}
className="euiComboBox__input"
data-test-subj="comboBoxSearchInput"
injectStyles={true}
inputRef={[Function]}
minWidth={1}
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
style={
Object {
"display": "inline-block",
"fontSize": 14,
}
}
value=""
>
<input
aria-hidden={true}
data-test-subj="comboBoxSearchInput"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
style={
Object {
"boxSizing": "content-box",
"width": "2px",
}
}
value=""
/>
<div
className="euiComboBox__input"
style={
Object {
"height": 0,
"left": 0,
"overflow": "scroll",
"position": "absolute",
"top": 0,
"visibility": "hidden",
"whiteSpace": "pre",
"display": "inline-block",
"fontSize": 14,
}
}
/>
</div>
</AutosizeInput>
</div>
<EuiFormControlLayoutIcons
icon={
Object {
"aria-label": "Open list of options",
"data-test-subj": "comboBoxToggleListButton",
"disabled": undefined,
"onClick": [Function],
"ref": [Function],
"side": "right",
"type": "arrowDown",
>
<input
aria-hidden={true}
data-test-subj="comboBoxSearchInput"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
style={
Object {
"boxSizing": "content-box",
"width": "2px",
}
}
value=""
/>
<div
style={
Object {
"height": 0,
"left": 0,
"overflow": "scroll",
"position": "absolute",
"top": 0,
"visibility": "hidden",
"whiteSpace": "pre",
}
}
/>
</div>
</AutosizeInput>
</div>
<EuiFormControlLayoutIcons
icon={
Object {
"aria-label": "Open list of options",
"data-test-subj": "comboBoxToggleListButton",
"disabled": undefined,
"onClick": [Function],
"ref": [Function],
"side": "right",
"type": "arrowDown",
}
}
}
isLoading={false}
>
<div
className="euiFormControlLayoutIcons euiFormControlLayoutIcons--right"
isLoading={false}
>
<EuiFormControlLayoutCustomIcon
aria-label="Open list of options"
data-test-subj="comboBoxToggleListButton"
iconRef={[Function]}
onClick={[Function]}
type="arrowDown"
<div
className="euiFormControlLayoutIcons euiFormControlLayoutIcons--right"
>
<button
<EuiFormControlLayoutCustomIcon
aria-label="Open list of options"
className="euiFormControlLayoutCustomIcon euiFormControlLayoutCustomIcon--clickable"
data-test-subj="comboBoxToggleListButton"
iconRef={[Function]}
onClick={[Function]}
type="arrowDown"
>
<EuiIcon
aria-hidden="true"
className="euiFormControlLayoutCustomIcon__icon"
size="m"
type="arrowDown"
<button
aria-label="Open list of options"
className="euiFormControlLayoutCustomIcon euiFormControlLayoutCustomIcon--clickable"
data-test-subj="comboBoxToggleListButton"
onClick={[Function]}
>
<arrowDown
<EuiIcon
aria-hidden="true"
className="euiIcon euiIcon--medium euiFormControlLayoutCustomIcon__icon"
focusable="false"
height="16"
style={
Object {
"fill": undefined,
}
}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
className="euiFormControlLayoutCustomIcon__icon"
size="m"
type="arrowDown"
>
<svg
<arrowDown
aria-hidden="true"
className="euiIcon euiIcon--medium euiFormControlLayoutCustomIcon__icon"
focusable="false"
Expand All @@ -189,23 +178,39 @@ exports[`SpaceSelector renders without crashing 1`] = `
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
>
<defs>
<path
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z"
id="arrow_down-a"
<svg
aria-hidden="true"
className="euiIcon euiIcon--medium euiFormControlLayoutCustomIcon__icon"
focusable="false"
height="16"
style={
Object {
"fill": undefined,
}
}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
>
<defs>
<path
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z"
id="arrow_down-a"
/>
</defs>
<use
fillRule="nonzero"
xlinkHref="#arrow_down-a"
/>
</defs>
<use
fillRule="nonzero"
xlinkHref="#arrow_down-a"
/>
</svg>
</arrowDown>
</EuiIcon>
</button>
</EuiFormControlLayoutCustomIcon>
</div>
</EuiFormControlLayoutIcons>
</svg>
</arrowDown>
</EuiIcon>
</button>
</EuiFormControlLayoutCustomIcon>
</div>
</EuiFormControlLayoutIcons>
</div>
</div>
</EuiFormControlLayout>
</EuiComboBoxInput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@elastic/eui';
import { isReservedRole } from '../../../../../../lib/role';
import { copyRole } from '../../../lib/copy_role';
import { getAvailablePermissions } from '../../../lib/get_available_permissions';
import { getAvailablePrivileges } from '../../../lib/get_available_privileges';
import { PrivilegeSpaceTable } from './privilege_space_table';
import { ALL_RESOURCE } from '../../../../../../../common/constants';
import { getKibanaPrivilegesViewModel } from '../../../lib/get_application_privileges';
Expand Down Expand Up @@ -200,7 +200,7 @@ export class SpaceAwarePrivilegeForm extends Component {
key={index}
availableSpaces={availableSpaces}
selectedSpaceIds={selectedSpaceIds}
availablePrivileges={getAvailablePermissions(basePrivilege)}
availablePrivileges={getAvailablePrivileges(basePrivilege)}
selectedPrivilege={privilege}
onChange={this.onPrivilegeSpacePermissionChange(index)}
onDelete={this.onPrivilegeSpacePermissionDelete(index)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getAvailablePrivileges throws when given an unexpected minimum privilege 1`] = `"Unexpected minimumPrivilege value: idk"`;
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,3 @@ export function getKibanaPrivilegesViewModel(applicationPrivileges, roleKibanaPr

return viewModel;
}

export function getKibanaPrivileges(kibanaPrivilegesViewModel) {
const kibanaPrivileges = {};

const resources = Object.keys(kibanaPrivilegesViewModel);
resources.forEach(resource => {
const selectedPrivileges = Object.keys(kibanaPrivilegesViewModel[resource]).filter(key => kibanaPrivilegesViewModel[resource][key]);
if (selectedPrivileges.length > 0) {
kibanaPrivileges[resource] = selectedPrivileges;
}
});

return kibanaPrivileges;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { NO_PRIVILEGE_VALUE } from './constants';

export function getAvailablePermissions(minimumPrivilege) {
export function getAvailablePrivileges(minimumPrivilege) {
switch (minimumPrivilege) {
case NO_PRIVILEGE_VALUE:
return ['read', 'all'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { getAvailablePrivileges } from './get_available_privileges';
import { NO_PRIVILEGE_VALUE } from './constants';

describe('getAvailablePrivileges', () => {
it('throws when given an unexpected minimum privilege', () => {
expect(() => getAvailablePrivileges('idk')).toThrowErrorMatchingSnapshot();
});

it(`returns all privileges when the minimum privilege is none`, () => {
expect(getAvailablePrivileges(NO_PRIVILEGE_VALUE)).toEqual(['read', 'all']);
});

it(`returns all privileges when the minimum privilege is read`, () => {
expect(getAvailablePrivileges('read')).toEqual(['read', 'all']);
});

it(`returns just the "all" privilege when the minimum privilege is all`, () => {
expect(getAvailablePrivileges('all')).toEqual(['all']);
});
});
Loading

0 comments on commit 08d9096

Please sign in to comment.