From 6e96dd7c23edb11f63c074ef0e2ad25037964a4a Mon Sep 17 00:00:00 2001 From: Trevor Jones Date: Sat, 22 Nov 2014 12:34:58 -0700 Subject: [PATCH 1/2] Fixed 'next' status from never being removed after multiple transitions. Messages with next would be marked as processed while still marked as unseen. This change moves the 'processed' marking to be applied only when transitioning a messages state from 'unseen' to 'seen'. Also fixed an issue with test file in regard to the permanent test that was discovered while writing the test for this issue. --- message-center.js | 2 +- test/app/index.html | 25 ++++++++++++++++++++++++- test/scenarios.js | 17 ++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/message-center.js b/message-center.js index 4005306..46de391 100644 --- a/message-center.js +++ b/message-center.js @@ -65,11 +65,11 @@ MessageCenterModule. if (!this.mcMessages[index].processed) { if (this.mcMessages[index].status == this.status.unseen) { this.mcMessages[index].status = this.status.shown; + this.mcMessages[index].processed = true; } else if (this.mcMessages[index].status == this.status.next) { this.mcMessages[index].status = this.status.unseen; } - this.mcMessages[index].processed = true; } } }, diff --git a/test/app/index.html b/test/app/index.html index 01b66ec..32c636c 100644 --- a/test/app/index.html +++ b/test/app/index.html @@ -63,6 +63,13 @@ $scope.saveFailure = function() { messageCenterService.add('danger', 'Something went wrong!'); }; + $scope.saveSuccessGoHome = function() { + messageCenterService.add('success', 'Saved successfully and went home!', {status: messageCenterService.status.next}); + $scope.goIndex(); + }; + $scope.goIndex = function() { + $location.path('/'); + }; }) .controller('AllowHTMLController', function($scope, $location, messageCenterService) { @@ -72,7 +79,14 @@ $scope.plainText = function() { messageCenterService.add('warning', 'HTML is NOT allowed.'); }; - }); + }) + + .controller('PermanentController', function($scope, $location, messageCenterService) { + $scope.goIndex = function() { + $location.path('/'); + }; + }) + ; @@ -100,6 +114,8 @@

Edit

+ + @@ -111,6 +127,13 @@

HTML

+ +
diff --git a/test/scenarios.js b/test/scenarios.js index 1c7db14..cba9a88 100644 --- a/test/scenarios.js +++ b/test/scenarios.js @@ -88,7 +88,7 @@ describe('Message Center', function() { }); }); - describe('after navigating to multiple different views', function () { + describe('after navigating to multiple different views with permanent message', function () { beforeEach(function () { element('#goPermanent').click(); }); @@ -130,6 +130,21 @@ describe('Message Center', function() { }); }); + describe('after navigating to multiple different views with next message', function () { + it('clears the next message', function () { + element('#goEditSuccess').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('You have reached the edit page!'); + element('#saveSuccessGoHome').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 and went home!'); + }); + }); + describe('when going to the allowed HTML page', function(){ beforeEach(function() { element('#goHTML').click(); }); From 1c4721759dfa5aceca615877fb707c5ce122374c Mon Sep 17 00:00:00 2001 From: Trevor Jones Date: Sat, 22 Nov 2014 18:54:54 -0700 Subject: [PATCH 2/2] Handle multiple directives in multiple views. --- message-center.js | 6 +- test/app/index3.html | 144 +++++++++++++++++++++++++++++++++++++++++++ test/scenarios.js | 30 ++++++++- 3 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 test/app/index3.html diff --git a/message-center.js b/message-center.js index 46de391..afb41b3 100644 --- a/message-center.js +++ b/message-center.js @@ -10,6 +10,7 @@ MessageCenterModule. function ($rootScope, $sce, $timeout) { return { mcMessages: this.mcMessages || [], + offlistener: this.offlistener || undefined, status: { unseen: 'unseen', shown: 'shown', @@ -110,8 +111,9 @@ MessageCenterModule. $rootScope.mcMessages = messageCenterService.mcMessages; messageCenterService.flush(); }; - $rootScope.$on('$locationChangeStart', changeReaction); - + if (messageCenterService.offlistener === undefined) { + messageCenterService.offlistener = $rootScope.$on('$locationChangeSuccess', changeReaction); + } scope.animation = attrs.animation || 'fade in'; } }; diff --git a/test/app/index3.html b/test/app/index3.html new file mode 100644 index 0000000..bb6208a --- /dev/null +++ b/test/app/index3.html @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/test/scenarios.js b/test/scenarios.js index cba9a88..723142d 100644 --- a/test/scenarios.js +++ b/test/scenarios.js @@ -1,4 +1,4 @@ -describe('Message Center', function() { +describe('Message Center with single directive', function() { beforeEach(module('MessageCenterModule')); @@ -218,3 +218,31 @@ describe('Message Center', function() { }); }); }); + +describe('Message Center with multiple directives', function() { + + beforeEach(module('MessageCenterModule')); + + beforeEach(function() { browser().navigateTo('/index3.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 navigating through two views', function() { + + it('renders a message with the default "success" level', function() { + element('#goEditSuccess').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('You have reached the edit page!'); + element('#saveSuccessGoHome').click(); + 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 and went home!'); + }); + }); +});