Skip to content

Commit

Permalink
Merge pull request #8096 from ycombinator/disable-button-for-real
Browse files Browse the repository at this point in the history
Adding defaults and fixing unit tests
  • Loading branch information
ycombinator authored Aug 25, 2016
2 parents a95554f + 5ca6ad1 commit 78cc0d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
32 changes: 25 additions & 7 deletions src/ui/public/kbn_top_nav/__tests__/kbn_top_nav_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,62 @@ describe('KbnTopNavController', function () {
});

describe('hideButton:', function () {
it('defaults to false', function () {
it('defaults to a function that returns false', function () {
const controller = new KbnTopNavController([
{ key: 'foo' },
{ key: '1234' },
]);

expect(pluck(controller.opts, 'hideButton')).to.eql([false, false]);
pluck(controller.opts, 'hideButton').forEach(prop => {
expect(prop).to.be.a(Function);
expect(prop()).to.eql(false);
});
});

it('excludes opts from opts when true', function () {
it('excludes opts from opts when set to true', function () {
const controller = new KbnTopNavController([
{ key: 'foo' },
{ key: '1234', hideButton: true },
]);

expect(controller.menuItems).to.have.length(1);
});

it('excludes opts from opts when set to a function that returns true', function () {
const controller = new KbnTopNavController([
{ key: 'foo' },
{ key: '1234', hideButton: () => true },
]);

expect(controller.menuItems).to.have.length(1);
});
});

describe('disableButton:', function () {
it('defaults to false', function () {
it('defaults to a function that returns false', function () {
const controller = new KbnTopNavController([
{ key: 'foo' },
{ key: '1234' },
]);

expect(pluck(controller.opts, 'disableButton')).to.eql([false, false]);
pluck(controller.opts, 'disableButton').forEach(prop => {
expect(prop).to.be.a(Function);
expect(prop()).to.eql(false);
});
});
});

describe('tooltip:', function () {
it('defaults to empty string', function () {
it('defaults to a function that returns undefined', function () {
const controller = new KbnTopNavController([
{ key: 'foo' },
{ key: '1234' },
]);

expect(pluck(controller.opts, 'tooltip')).to.eql(['', '']);
pluck(controller.opts, 'tooltip').forEach(prop => {
expect(prop).to.be.a(Function);
expect(prop()).to.eql(undefined);
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/kbn_top_nav/kbn_top_nav_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export default function ($compile) {
run: (item) => this.toggle(item.key)
}, opt);

defaultedOpt.hideButton = isFunction(opt.hideButton) ? opt.hideButton : () => opt.hideButton;
defaultedOpt.disableButton = isFunction(opt.disableButton) ? opt.disableButton : () => opt.disableButton;
defaultedOpt.hideButton = isFunction(opt.hideButton) ? opt.hideButton : () => !!opt.hideButton;
defaultedOpt.disableButton = isFunction(opt.disableButton) ? opt.disableButton : () => !!opt.disableButton;
defaultedOpt.tooltip = isFunction(opt.tooltip) ? opt.tooltip : () => opt.tooltip;

return defaultedOpt;
Expand Down

0 comments on commit 78cc0d9

Please sign in to comment.