Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Bind messages to root scope and add testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateu Aguiló Bosch committed Oct 21, 2014
1 parent 3b19ba0 commit 6ab4894
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions message-center.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ MessageCenterModule.
restrict: 'EA',
template: templateString,
link: function(scope, element, attrs) {
// Bind the messages from the service to the root scope.
messageCenterService.flush();
var changeReaction = function (event, to, from) {
// Update 'unseen' messages to be marked as 'shown'.
messageCenterService.markShown();
Expand Down
51 changes: 51 additions & 0 deletions test/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,54 @@ describe('Message Center', function() {
});
});
});

describe('Message Center', function() {

beforeEach(module('MessageCenterModule'));

beforeEach(function() { browser().navigateTo('/index2.html'); });

it('renders an empty ordered list on its initial state', function() {
expect(element('div#mc-messages-wrapper').count()).toBe(1);
expect(element('div#mc-messages-wrapper .alert').count()).toBe(0);
});

describe('when on the same view without routing', function(){

it('renders a message with the default "success" level', function() {
element('#saveSuccess').click();
var messages = element('div#mc-messages-wrapper .alert');
expect(messages.count()).toBe(1);
expect(messages.prop('className')).toEqual('alert alert-success fade in');
expect(messages.text()).toMatch('Saved successfully!');
});

it('renders a message with the level and text provided', function() {
element('#saveFailure').click();
var messages = element('div#mc-messages-wrapper .alert');
expect(messages.count()).toBe(1);
expect(messages.prop('className')).toEqual('alert alert-danger fade in');
expect(messages.text()).toMatch('Something went wrong!');
});

it('renders multiple messages with the default "success" level and text', function() {
element('#saveMultipleSuccess').click();
var yay = element('div#mc-messages-wrapper .alert:first');
expect(yay.prop('className')).toEqual('alert alert-success fade in');
expect(yay.text()).toMatch('Yay!');
var saved = element('div#mc-messages-wrapper .alert:nth-of-type(2)');
expect(saved.prop('className')).toEqual('alert alert-success fade in');
expect(saved.text()).toMatch('Saved successfully!');
});

it('renders multiple messages with the level and text provided', function() {
element('#saveMultipleTypes').click();
var yay = element('div#mc-messages-wrapper .alert:first');
expect(yay.prop('className')).toEqual('alert alert-success fade in');
expect(yay.text()).toMatch('Yay!');
var somethingWrong = element('div#mc-messages-wrapper .alert:nth-of-type(2)');
expect(somethingWrong.prop('className')).toEqual('alert alert-danger fade in');
expect(somethingWrong.text()).toMatch('Something went wrong!');
});
});
});

0 comments on commit 6ab4894

Please sign in to comment.