Skip to content

Commit

Permalink
feat(rxNotify): added check for empty messagesgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Lamping committed Feb 27, 2014
1 parent a60ab7c commit 5d2cfe4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/rxNotify/rxNotify.js
Expand Up @@ -68,7 +68,10 @@ angular.module('encore.ui.rxNotify', ['ngSanitize'])
dismissAfterTimeout(message);
}

stacks[message.stack].push(message);
// make sure there's actual text to add
if (message.text.length > 0) {
stacks[message.stack].push(message);
}
};

/*
Expand Down
23 changes: 18 additions & 5 deletions src/rxNotify/rxNotify.spec.js
Expand Up @@ -41,12 +41,27 @@ describe('rxNotify', function () {
expect(notifySvc.stacks[defaultStack][0].text).to.equal(messageText1);
});

it('should not add message if `text` is empty', function () {
// create message w/o text
notifySvc.add('');

// validate message not added
expect(notifySvc.stacks[defaultStack].length).to.equal(0);

// test that if someone really wants an empty message, they can get it
// create message w/ a single space
notifySvc.add(' ');

// validate message added
expect(notifySvc.stacks[defaultStack].length).to.equal(1);
});

it('should add unique id to message and return it on add', function () {
// create message
var msg = notifySvc.add(messageText1);

// expect message to be first in page stack
expect(notifySvc.stacks[defaultStack][0]).to.eql(msg);
expect(notifySvc.stacks[defaultStack][0].id).to.eql(msg.id);
});

it('should allow type specification', function () {
Expand Down Expand Up @@ -391,17 +406,15 @@ describe('rxNotify', function () {

it('should dismiss loading message after promise resolves', function () {
rpn.add(prom.promise, {
loading: loadingMsg,
success: successMsg
loading: loadingMsg
});

prom.resolve();

scope.$digest();

// expect loading message to no longer be in stack
expect(notifySvc.stacks[defaultStack].length).to.equal(1);
expect(notifySvc.stacks[defaultStack][0].text).to.not.contain(loadingMsg);
expect(notifySvc.stacks[defaultStack].length).to.equal(0);
});

it('should show success message after promise is resolved successfully', function () {
Expand Down

0 comments on commit 5d2cfe4

Please sign in to comment.