Skip to content

Commit

Permalink
Adds getAriaName function and applies it to advanced settings (#13448)
Browse files Browse the repository at this point in the history
  • Loading branch information
BigFunger committed Aug 16, 2017
1 parent a5fc742 commit 030e5e2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
ng-click="edit(conf)"
class="kuiMenuButton kuiMenuButton--basic kuiMenuButton--iconText"
ng-disabled="conf.tooComplex"
aria-label="Edit {{conf.ariaName}}"
data-test-subj="advancedSetting-{{conf.name}}-editButton"
>
<span
Expand All @@ -146,6 +147,7 @@
ng-click="save(conf)"
class="kuiMenuButton kuiMenuButton--primary kuiMenuButton--iconText"
ng-disabled="conf.loading || conf.tooComplex || forms.configEdit.$invalid"
aria-label="Save edit"
data-test-subj="advancedSetting-{{conf.name}}-saveButton"
>
<span
Expand All @@ -166,6 +168,7 @@
ng-if="!conf.editing"
ng-click="clear(conf)"
ng-hide="isDefaultValue(conf)"
aria-label="Clear {{conf.ariaName}}"
class="kuiMenuButton kuiMenuButton--danger kuiMenuButton--iconText"
>
<span
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import { getAriaName } from '../get_aria_name';
import expect from 'expect.js';

describe('Settings', function () {
describe('Advanced', function () {
describe('getAriaName(name)', function () {
it('should be a function', function () {
expect(getAriaName).to.be.a(Function);
});

it('should return a space delimited lower-case string with no special characters', function () {
expect(getAriaName('xPack:defaultAdminEmail')).to.be('x pack default admin email');
expect(getAriaName('search:queryLanguage:switcher:enable')).to.be('search query language switcher enable');
expect(getAriaName('doc_table:highlight')).to.be('doc table highlight');
expect(getAriaName('foo')).to.be('foo');
});

it('should return an empty string if passed undefined or null', function () {
expect(getAriaName()).to.be('');
expect(getAriaName(undefined)).to.be('');
expect(getAriaName(null)).to.be('');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import { words } from 'lodash';

/**
* @name {string} the name of the configuration object
* @returns {string} a space demimited, lowercase string with
* special characters removed.
*
* Example: 'xPack:fooBar:foo_bar_baz' -> 'x pack foo bar foo bar baz'
*/
export function getAriaName(name) {
return words(name).map(word => word.toLowerCase()).join(' ');
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getValType } from './get_val_type';
import { getEditorType } from './get_editor_type';
import { getAriaName } from './get_aria_name';

/**
* @param {object} advanced setting definition object
Expand All @@ -13,6 +14,7 @@ export function toEditableConfig({ def, name, value, isCustom }) {
}
const conf = {
name,
ariaName: getAriaName(name),
value,
isCustom,
readonly: !!def.readonly,
Expand All @@ -33,3 +35,4 @@ export function toEditableConfig({ def, name, value, isCustom }) {

return conf;
}

0 comments on commit 030e5e2

Please sign in to comment.