Skip to content

Commit

Permalink
punch up the tests
Browse files Browse the repository at this point in the history
check value types, more tests with less concerns, clean up notifications after each test
  • Loading branch information
w33ble authored and tsullivan committed Jul 27, 2016
1 parent 7055f6c commit 47edbfd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
47 changes: 37 additions & 10 deletions src/ui/public/notify/__tests__/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,50 @@ describe('Notifier', function () {
});

describe('#custom', function () {
let customNotif;

beforeEach(() => {
customNotif = notifier.custom(customText, customParams);
});

afterEach(() => {
customNotif.clear();
});

it('has a custom function to make notifications', function () {
expect(notifier.custom).to.be.defined;
});

it('properly merges options', function () {
const customNotif = notifier.custom(customText, customParams);
expect(customNotif.title).to.equal(customParams.title);
expect(customNotif.markdown).to.equal(customParams.markdown);
expect(customNotif.lifetime).to.equal(customParams.lifetime);
expect(customNotif).to.have.property('title', customParams.title);
expect(customNotif).to.have.property('lifetime', customParams.lifetime);

expect(customParams.title).to.be.a('string');
expect(customParams.lifetime).to.be.a('number');
});

it('sets the content', function () {
expect(customNotif).to.have.property('content', `${params.location}: ${customText}`);
expect(customNotif.content).to.be.a('string');
});

it('uses custom actions', function () {
expect(customNotif).to.have.property('customActions');
expect(customNotif.customActions).to.have.length(customParams.actions.length);
});

it('gives a default action if none are provided', function () {
const noActionParams = _.assign({}, customParams, { actions: []});
const customNotif = notifier.custom(customText, noActionParams);
expect(customNotif.actions.length).to.equal(1);
// destroy the default custom notification, avoid duplicate handling
customNotif.clear();

const noActionParams = _.defaults({ actions: [] }, customParams);
customNotif = notifier.custom(customText, noActionParams);
expect(customNotif).to.have.property('actions');
expect(customNotif.actions).to.have.length(1);
});

it('should wrap the callback functions in a close function', function () {
const customNotif = notifier.custom(customText, customParams);
customNotif.actions.forEach((action, idx) => {
customNotif.customActions.forEach((action, idx) => {
expect(action.callback).not.to.equal(customParams.actions[idx]);
action.callback();
});
Expand All @@ -232,7 +259,7 @@ describe('Notifier', function () {
});

it('prepends location to message for markdown', function () {
expect(notify('banner').markdown).to.equal(params.location + ': ' + message);
expect(notify('banner').content).to.equal(params.location + ': ' + message);
});

it('sets type to "banner"', function () {
Expand Down
1 change: 0 additions & 1 deletion src/ui/public/notify/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ function createGroupLogger(type, opts) {

if (consoleGroups) {
if (status) {
console.log(status);
console.groupEnd();
} else {
if (opts.open) {
Expand Down

0 comments on commit 47edbfd

Please sign in to comment.