diff options
Diffstat (limited to 'js/build/tests/services/businesslayer/subsriptionsbusinesslayerSpec.js')
-rw-r--r-- | js/build/tests/services/businesslayer/subsriptionsbusinesslayerSpec.js | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/js/build/tests/services/businesslayer/subsriptionsbusinesslayerSpec.js b/js/build/tests/services/businesslayer/subsriptionsbusinesslayerSpec.js new file mode 100644 index 000000000..e2763903a --- /dev/null +++ b/js/build/tests/services/businesslayer/subsriptionsbusinesslayerSpec.js @@ -0,0 +1,130 @@ +// Generated by CoffeeScript 1.6.3 +/* + +ownCloud - News + +@author Bernhard Posselt +@copyright 2012 Bernhard Posselt dev@bernhard-posselt.com + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +License as published by the Free Software Foundation; either +version 3 of the License, or any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU AFFERO GENERAL PUBLIC LICENSE for more details. + +You should have received a copy of the GNU Affero General Public +License along with this library. If not, see <http://www.gnu.org/licenses/>. +*/ + + +(function() { + describe('SubscriptionsBusinessLayer', function() { + var _this = this; + beforeEach(module('News')); + beforeEach(module(function($provide) { + _this.persistence = { + setFeedRead: jasmine.createSpy('setFeedRead'), + test: 'subscriptionsbusinesslayer' + }; + $provide.value('Persistence', _this.persistence); + })); + beforeEach(inject(function(SubscriptionsBusinessLayer, ShowAll, FeedModel, ActiveFeed, FeedType, NewestItem) { + _this.SubscriptionsBusinessLayer = SubscriptionsBusinessLayer; + _this.ShowAll = ShowAll; + _this.FeedModel = FeedModel; + _this.ActiveFeed = ActiveFeed; + _this.FeedType = FeedType; + _this.NewestItem = NewestItem; + _this.ShowAll.setShowAll(false); + return _this.ActiveFeed.handle({ + type: _this.FeedType.Feed, + id: 0 + }); + })); + it('should be visible shows all items is set to true and there are feeds', function() { + _this.FeedModel.add({ + id: 3, + unreadCount: 5, + url: 'hi' + }); + expect(_this.SubscriptionsBusinessLayer.isVisible()).toBe(true); + _this.ShowAll.setShowAll(true); + return expect(_this.SubscriptionsBusinessLayer.isVisible()).toBe(true); + }); + it('should not be visible if there are no feeds', function() { + expect(_this.SubscriptionsBusinessLayer.isVisible()).toBe(false); + _this.ShowAll.setShowAll(true); + return expect(_this.SubscriptionsBusinessLayer.isVisible()).toBe(false); + }); + it('should not be visible if showall is false + there are no unread', function() { + _this.FeedModel.add({ + id: 3, + unreadCount: 0 + }); + return expect(_this.SubscriptionsBusinessLayer.isVisible()).toBe(false); + }); + it('should always be visible if its the active feed and there are feeds', function() { + _this.ActiveFeed.handle({ + type: _this.FeedType.Subscriptions, + id: 0 + }); + expect(_this.SubscriptionsBusinessLayer.isVisible()).toBe(false); + _this.FeedModel.add({ + id: 3, + unreadCount: 0, + url: 'hi' + }); + return expect(_this.SubscriptionsBusinessLayer.isVisible()).toBe(true); + }); + it('should mark all as read', function() { + _this.NewestItem.handle(25); + _this.persistence.setAllRead = jasmine.createSpy('setFeedRead'); + _this.FeedModel.add({ + id: 3, + unreadCount: 134, + folderId: 3, + url: 'a1' + }); + _this.FeedModel.add({ + id: 5, + unreadCount: 2, + folderId: 2, + url: 'a2' + }); + _this.FeedModel.add({ + id: 1, + unreadCount: 12, + folderId: 3, + url: 'a3' + }); + _this.SubscriptionsBusinessLayer.markRead(); + expect(_this.FeedModel.getById(3).unreadCount).toBe(0); + expect(_this.FeedModel.getById(1).unreadCount).toBe(0); + expect(_this.FeedModel.getById(5).unreadCount).toBe(0); + return expect(_this.persistence.setAllRead).toHaveBeenCalledWith(25); + }); + it('should not mark all read when no highest item id', function() { + _this.persistence.setAllRead = jasmine.createSpy('setAllRead'); + _this.SubscriptionsBusinessLayer.markRead(); + return expect(_this.persistence.setAllRead).not.toHaveBeenCalled(); + }); + return it('should get the correct unread count', function() { + _this.FeedModel.add({ + id: 3, + unreadCount: 132, + url: 'hoho' + }); + _this.FeedModel.add({ + id: 4, + unreadCount: 12, + url: 'hohod' + }); + return expect(_this.SubscriptionsBusinessLayer.getUnreadCount()).toBe(144); + }); + }); + +}).call(this); |