From 82f0a877a001ead0bd0cdd76d96fe46a071535d8 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 31 May 2014 01:12:20 +0200 Subject: add active and unread stuff --- .../unit/controller/NavigationControllerSpec.js | 156 ++++++++++++++++++++- js/tests/unit/filter/UnreadCountFormatterSpec.js | 27 ++++ js/tests/unit/service/FeedResourceSpec.js | 2 +- 3 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 js/tests/unit/filter/UnreadCountFormatterSpec.js (limited to 'js/tests') diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js index adefd157f..6837160bf 100644 --- a/js/tests/unit/controller/NavigationControllerSpec.js +++ b/js/tests/unit/controller/NavigationControllerSpec.js @@ -14,11 +14,24 @@ describe('NavigationController', () => { beforeEach(module('News', ($provide) => { $provide.value('BASE_URL', 'base'); + $provide.value('FEED_TYPE', { + FEED: 0, + FOLDER: 1, + STARRED: 2, + SUBSCRIPTIONS: 3, + SHARED: 4 + }); $provide.constant('ITEM_BATCH_SIZE', 5); })); - beforeEach(inject(($controller) => { + beforeEach(inject(($controller, FeedResource) => { controller = $controller('NavigationController'); + FeedResource.receive([ + {id: 1, folderId: 3, url: 'ye', unreadCount: 45}, + {id: 2, folderId: 4, url: 'sye', unreadCount: 25}, + {id: 3, folderId: 3, title: 'hore', url: '1sye', unreadCount: 1} + ]); + })); @@ -126,4 +139,143 @@ describe('NavigationController', () => { })); -}); \ No newline at end of file + it('should get the unreadcount', inject((FeedResource, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + }); + + + expect(ctrl.getUnreadCount()).toBe(71); + expect(ctrl.getFeedUnreadCount(1)).toBe(45); + expect(ctrl.getFolderUnreadCount(3)).toBe(46); + })); + + + it('should get the starred count', inject((ItemResource, $controller) => { + let ctrl = $controller('NavigationController', { + ItemResource: ItemResource, + }); + + ItemResource.receive(99, 'starred'); + + expect(ctrl.getStarredCount()).toBe(99); + })); + + + it('should toggle a folder', inject((FolderResource, $controller) => { + let ctrl = $controller('NavigationController', { + FolderResource: FolderResource, + }); + + FolderResource.toggleOpen = jasmine.createSpy('open'); + + ctrl.toggleFolder(3); + + expect(FolderResource.toggleOpen).toHaveBeenCalledWith(3); + })); + + + it('should check if a folder has feeds', inject((FeedResource, + $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + }); + + expect(ctrl.hasFeeds(3)).toBe(true); + expect(ctrl.hasFeeds(1)).toBe(false); + })); + + + it('should check if a subfeed is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + params: { + id: 3 + }, + $$route: { + type: FEED_TYPE.FEED + } + } + } + }); + + expect(ctrl.subFeedActive(3)).toBe(true); + })); + + it('should check if a subscriptions is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + $$route: { + type: FEED_TYPE.SUBSCRIPTIONS + } + } + } + }); + + expect(ctrl.isSubscriptionsActive()).toBe(true); + })); + + + it('should check if a starred is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + $$route: { + type: FEED_TYPE.STARRED + } + } + } + }); + + expect(ctrl.isStarredActive()).toBe(true); + })); + + + + it('should check if a feed is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + params: { + id: 3 + }, + $$route: { + type: FEED_TYPE.FEED + } + } + } + }); + + expect(ctrl.isFeedActive(3)).toBe(true); + })); + + + it('should check if a folder is active', inject((FeedResource, + FEED_TYPE, $controller) => { + let ctrl = $controller('NavigationController', { + FeedResource: FeedResource, + $route: { + current: { + params: { + id: 3 + }, + $$route: { + type: FEED_TYPE.FOLDER + } + } + } + }); + + expect(ctrl.isFolderActive(3)).toBe(true); + })); +}); diff --git a/js/tests/unit/filter/UnreadCountFormatterSpec.js b/js/tests/unit/filter/UnreadCountFormatterSpec.js new file mode 100644 index 000000000..14152f047 --- /dev/null +++ b/js/tests/unit/filter/UnreadCountFormatterSpec.js @@ -0,0 +1,27 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ +describe('unreadCountFormatter', () => { + 'use strict'; + + let filter; + + beforeEach(module('News')); + + beforeEach(inject(($filter) => { + filter = $filter('unreadCountFormatter'); + })); + + it('should format the unread count', () => { + expect(filter(999)).toBe(999); + expect(filter(1000)).toBe('999+'); + }); + + +}); \ No newline at end of file diff --git a/js/tests/unit/service/FeedResourceSpec.js b/js/tests/unit/service/FeedResourceSpec.js index a37ff42f3..d7473cb70 100644 --- a/js/tests/unit/service/FeedResourceSpec.js +++ b/js/tests/unit/service/FeedResourceSpec.js @@ -97,7 +97,7 @@ describe('FeedResource', () => { expect(FeedResource.getFolderUnreadCount(3)).toBe(0); FeedResource.markRead(); - expect(FeedResource.getFolderUnreadCount(4)).toBe(0); + expect(FeedResource.getFolderUnreadCount(4)).toBe(undefined); })); -- cgit v1.2.3