Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding defaults and fixing unit tests #8096

Merged
merged 3 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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