diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-09-11 14:32:59 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-09-11 14:32:59 +0200 |
commit | 793bd2177367c32d205c19950be33a8afc3c76e1 (patch) | |
tree | 7a36495ecb43e998e95dd21ec60ce943338ad80c /js/tests | |
parent | ea9ebd4826fe9807af5bc17e786b3dc58f163970 (diff) |
port to ES5, fix unread count going into minus
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/unit/controller/AppControllerSpec.js | 19 | ||||
-rw-r--r-- | js/tests/unit/controller/ContentControllerSpec.js | 156 | ||||
-rw-r--r-- | js/tests/unit/controller/NavigationControllerSpec.js | 93 | ||||
-rw-r--r-- | js/tests/unit/controller/SettingsControllerSpec.js | 28 | ||||
-rw-r--r-- | js/tests/unit/filter/UnreadCountFormatterSpec.js | 8 | ||||
-rw-r--r-- | js/tests/unit/service/FeedResourceSpec.js | 52 | ||||
-rw-r--r-- | js/tests/unit/service/FolderResourceSpec.js | 35 | ||||
-rw-r--r-- | js/tests/unit/service/ItemResourceSpec.js | 37 | ||||
-rw-r--r-- | js/tests/unit/service/LoadingSpec.js | 6 | ||||
-rw-r--r-- | js/tests/unit/service/PublisherSpec.js | 17 | ||||
-rw-r--r-- | js/tests/unit/service/ResourceSpec.js | 48 | ||||
-rw-r--r-- | js/tests/unit/service/SettingsResourceSpec.js | 48 | ||||
-rw-r--r-- | js/tests/unit/stubs/OC.js | 2 |
13 files changed, 285 insertions, 264 deletions
diff --git a/js/tests/unit/controller/AppControllerSpec.js b/js/tests/unit/controller/AppControllerSpec.js index 772fdc565..90dd0aab8 100644 --- a/js/tests/unit/controller/AppControllerSpec.js +++ b/js/tests/unit/controller/AppControllerSpec.js @@ -7,38 +7,39 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('AppController', () => { +describe('AppController', function () { 'use strict'; - let controller; + var controller; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.value('BASE_URL', 'base'); })); - beforeEach(inject(($controller) => { + beforeEach(inject(function ($controller) { controller = $controller('AppController'); })); - it('should expose Loading', inject((Loading) => { + it('should expose Loading', inject(function (Loading) { expect(controller.loading).toBe(Loading); })); - it('should expose set firstrun if no feeds and folders', inject(() => { + it('should expose set firstrun if no feeds and folders', function () { expect(controller.isFirstRun()).toBe(true); - })); + }); - it('should expose set firstrun if feeds', inject((FeedResource) => { + it('should expose set firstrun if feeds', inject(function (FeedResource) { FeedResource.add({url: 'test'}); expect(controller.isFirstRun()).toBe(false); })); - it('should expose set firstrun if folders', inject((FolderResource) => { + it('should expose set firstrun if folders', inject( + function (FolderResource) { FolderResource.add({name: 'test'}); expect(controller.isFirstRun()).toBe(false); diff --git a/js/tests/unit/controller/ContentControllerSpec.js b/js/tests/unit/controller/ContentControllerSpec.js index e649219d6..bdea6e16a 100644 --- a/js/tests/unit/controller/ContentControllerSpec.js +++ b/js/tests/unit/controller/ContentControllerSpec.js @@ -7,37 +7,37 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('ContentController', () => { +describe('ContentController', function () { 'use strict'; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.constant('BASE_URL', 'base'); $provide.constant('ITEM_BATCH_SIZE', 5); })); - it('should publish data to models', inject(($controller, Publisher, - FeedResource, ItemResource) => { + it('should publish data to models', inject(function ($controller, Publisher, + FeedResource, ItemResource) { - Publisher.subscribe(ItemResource).toChannels('items'); - Publisher.subscribe(FeedResource).toChannels('feeds'); + Publisher.subscribe(ItemResource).toChannels(['items']); + Publisher.subscribe(FeedResource).toChannels(['feeds']); - let controller = $controller('ContentController', { + var controller = $controller('ContentController', { data: { 'items': [ {id: 3}, {id: 4} ] - }, + } }); expect(controller.getItems().length).toBe(2); })); - it('should clear data on url change', inject(($controller, - ItemResource) => { + it('should clear data on url change', inject(function ($controller, + ItemResource) { ItemResource.clear = jasmine.createSpy('clear'); @@ -49,10 +49,10 @@ describe('ContentController', () => { })); - it('should return order by', inject(($controller, - SettingsResource) => { + it('should return order by', inject(function ($controller, + SettingsResource) { - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { SettingsResource: SettingsResource, data: {}, }); @@ -65,31 +65,38 @@ describe('ContentController', () => { })); - it('should mark read', inject(($controller, - ItemResource, FeedResource, Publisher) => { + it('should mark read', inject(function ($controller, ItemResource, + FeedResource, Publisher) { - Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(ItemResource).toChannels(['items']); ItemResource.markItemRead = jasmine.createSpy('markRead'); FeedResource.markItemOfFeedRead = jasmine.createSpy('markRead'); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { ItemResource: ItemResource, FeedResource: FeedResource, data: { 'items': [{ id: 3, - feedId: 4 + feedId: 4, + unread: true }, { id: 5, feedId: 4, keepUnread: true + }, + { + id: 9, + feedId: 5, + unread: false }] }, }); ctrl.markRead(3); ctrl.markRead(5); + ctrl.markRead(9); expect(ItemResource.markItemRead).toHaveBeenCalledWith(3); expect(FeedResource.markItemOfFeedRead).toHaveBeenCalledWith(4); @@ -98,12 +105,12 @@ describe('ContentController', () => { })); - it('should toggle keep unread when unread', inject(($controller, - ItemResource, FeedResource, Publisher) => { + it('should toggle keep unread when unread', inject(function ($controller, + ItemResource, FeedResource, Publisher) { - Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(ItemResource).toChannels(['items']); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { ItemResource: ItemResource, FeedResource: FeedResource, data: { @@ -121,14 +128,14 @@ describe('ContentController', () => { })); - it('should toggle keep unread when read', inject(($controller, - ItemResource, FeedResource, Publisher) => { + it('should toggle keep unread when read', inject(function ($controller, + ItemResource, FeedResource, Publisher) { - Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(ItemResource).toChannels(['items']); ItemResource.markItemRead = jasmine.createSpy('markRead'); FeedResource.markItemOfFeedUnread = jasmine.createSpy('markRead'); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { ItemResource: ItemResource, FeedResource: FeedResource, data: { @@ -149,11 +156,12 @@ describe('ContentController', () => { })); - it('should get a feed', inject(($controller, FeedResource, Publisher) => { + it('should get a feed', inject(function ($controller, FeedResource, + Publisher) { - Publisher.subscribe(FeedResource).toChannels('feeds'); + Publisher.subscribe(FeedResource).toChannels(['feeds']); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { FeedResource: FeedResource, data: { 'feeds': [{ @@ -167,11 +175,11 @@ describe('ContentController', () => { })); - it('should toggle starred', inject(($controller, ItemResource) => { + it('should toggle starred', inject(function ($controller, ItemResource) { ItemResource.toggleStar = jasmine.createSpy('star'); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { ItemResource: ItemResource, data: {}, }); @@ -183,11 +191,12 @@ describe('ContentController', () => { - it('should publish compactview', inject(($controller, SettingsResource) => { + it('should publish compactview', inject(function ($controller, + SettingsResource) { SettingsResource.set('compact', true); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { SettingsResource: SettingsResource, data: {}, }); @@ -196,11 +205,12 @@ describe('ContentController', () => { })); - it('should publish markread', inject(($controller, SettingsResource) => { + it('should publish markread', inject(function ($controller, + SettingsResource) { SettingsResource.set('preventReadOnScroll', true); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { SettingsResource: SettingsResource, data: {}, }); @@ -209,8 +219,8 @@ describe('ContentController', () => { })); - it('should publish autopaging', inject(($controller) => { - let ctrl = $controller('ContentController', { + it('should publish autopaging', inject(function ($controller) { + var ctrl = $controller('ContentController', { data: {}, }); @@ -218,14 +228,14 @@ describe('ContentController', () => { })); - it('should mark multiple items read', inject(($controller, - ItemResource, FeedResource, Publisher) => { + it('should mark multiple items read', inject(function ($controller, + ItemResource, FeedResource, Publisher) { - Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(ItemResource).toChannels(['items']); ItemResource.markItemsRead = jasmine.createSpy('markRead'); FeedResource.markItemsOfFeedsRead = jasmine.createSpy('markRead'); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { ItemResource: ItemResource, FeedResource: FeedResource, data: { @@ -252,10 +262,10 @@ describe('ContentController', () => { })); - it('should not autopage if less than 0 elements', inject(( - $controller, ItemResource, Publisher) => { + it('should not autopage if less than 0 elements', inject(function ( + $controller, ItemResource, Publisher) { - let $route = { + var $route = { current: { $$route: { type: 3 @@ -263,27 +273,27 @@ describe('ContentController', () => { } }; - let $routeParams = { + var $routeParams = { id: 2 }; - Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(ItemResource).toChannels(['items']); ItemResource.autoPage = jasmine.createSpy('autoPage') - .andCallFake(() => { + .andCallFake(function () { return { - success: (callback) => { + success: function (callback) { callback({ 'items': [] }); return { - error: () => {} + error: function () {} }; } }; }); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { $routeParams: $routeParams, $route: $route, Publisher: Publisher, @@ -302,10 +312,10 @@ describe('ContentController', () => { })); - it('should autopage if more than 0 elements', inject(( - $controller, ItemResource, Publisher) => { + it('should autopage if more than 0 elements', inject(function ( + $controller, ItemResource, Publisher) { - let $route = { + var $route = { current: { $$route: { type: 3 @@ -313,27 +323,27 @@ describe('ContentController', () => { } }; - let $routeParams = { + var $routeParams = { id: 2 }; - Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(ItemResource).toChannels(['items']); ItemResource.autoPage = jasmine.createSpy('autoPage') - .andCallFake(() => { + .andCallFake(function () { return { - success: (callback) => { + success: function (callback) { callback({ 'items': [{items: [{id: 3}]}] }); return { - error: () => {} + error: function () {} }; } }; }); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { $routeParams: $routeParams, $route: $route, Publisher: Publisher, @@ -350,10 +360,10 @@ describe('ContentController', () => { })); - it('should autopage if error', inject(( - $controller, ItemResource, Publisher) => { + it('should autopage if error', inject(function ( + $controller, ItemResource, Publisher) { - let $route = { + var $route = { current: { $$route: { type: 3 @@ -361,21 +371,21 @@ describe('ContentController', () => { } }; - let $routeParams = { + var $routeParams = { id: 2 }; - Publisher.subscribe(ItemResource).toChannels('items'); + Publisher.subscribe(ItemResource).toChannels(['items']); ItemResource.autoPage = jasmine.createSpy('autoPage') - .andCallFake(() => { + .andCallFake(function () { return { - success: (callback) => { + success: function (callback) { callback({ 'items': [] }); return { - error: (callback) => { + error: function (callback) { callback(); } }; @@ -383,7 +393,7 @@ describe('ContentController', () => { }; }); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { $routeParams: $routeParams, $route: $route, Publisher: Publisher, @@ -399,11 +409,11 @@ describe('ContentController', () => { })); - it('should return relative date', inject(($controller, - SettingsResource) => { + it('should return relative date', inject(function ($controller, + SettingsResource) { SettingsResource.receive({language: 'en'}); - let ctrl = $controller('ContentController', { + var ctrl = $controller('ContentController', { data: {}, }); @@ -411,8 +421,8 @@ describe('ContentController', () => { })); - it('should return relative date empty', inject(($controller) => { - let ctrl = $controller('ContentController', { + it('should return relative date empty', inject(function ($controller) { + var ctrl = $controller('ContentController', { data: {}, }); diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js index 8c646640f..e871a2174 100644 --- a/js/tests/unit/controller/NavigationControllerSpec.js +++ b/js/tests/unit/controller/NavigationControllerSpec.js @@ -7,12 +7,12 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('NavigationController', () => { +describe('NavigationController', function () { 'use strict'; - let controller; + var controller; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.value('BASE_URL', 'base'); $provide.value('FEED_TYPE', { FEED: 0, @@ -24,7 +24,7 @@ describe('NavigationController', () => { $provide.constant('ITEM_BATCH_SIZE', 5); })); - beforeEach(inject(($controller, FeedResource) => { + beforeEach(inject(function ($controller, FeedResource) { controller = $controller('NavigationController'); FeedResource.receive([ {id: 1, folderId: 3, url: 'ye', unreadCount: 45}, @@ -35,22 +35,22 @@ describe('NavigationController', () => { })); - it('should expose Feeds', inject((FeedResource) => { + it('should expose Feeds', inject(function (FeedResource) { FeedResource.add({url: 1}); expect(controller.getFeeds()).toBe(FeedResource.getAll()); })); - it('should expose Folders', inject((FolderResource) => { + it('should expose Folders', inject(function (FolderResource) { FolderResource.add({name: 1}); expect(controller.getFolders()).toBe(FolderResource.getAll()); })); - it('should mark Folders read', inject(($controller) => { - let FeedResource = { + it('should mark Folders read', inject(function ($controller) { + var FeedResource = { markFolderRead: jasmine.createSpy('folder'), - getByFolderId: () => { + getByFolderId: function () { return [ {id: 3}, {id: 4} @@ -58,7 +58,7 @@ describe('NavigationController', () => { } }; - let ItemResource = { + var ItemResource = { markFeedRead: jasmine.createSpy('feedfolder') }; @@ -74,12 +74,12 @@ describe('NavigationController', () => { })); - it('should mark a feed read', inject(($controller) => { - let FeedResource = { + it('should mark a feed read', inject(function ($controller) { + var FeedResource = { markFeedRead: jasmine.createSpy('folder'), }; - let ItemResource = { + var ItemResource = { markFeedRead: jasmine.createSpy('feedfolder') }; @@ -95,12 +95,12 @@ describe('NavigationController', () => { })); - it('should mark all read', inject(($controller) => { - let FeedResource = { + it('should mark all read', inject(function ($controller) { + var FeedResource = { markRead: jasmine.createSpy('folder'), }; - let ItemResource = { + var ItemResource = { markRead: jasmine.createSpy('feedfolder') }; @@ -116,8 +116,8 @@ describe('NavigationController', () => { })); - it('should mark all read', inject((SettingsResource, $controller) => { - let ctrl = $controller('NavigationController', { + it('should mark all read', inject(function (SettingsResource, $controller) { + var ctrl = $controller('NavigationController', { SettingsResource: SettingsResource, }); @@ -127,8 +127,8 @@ describe('NavigationController', () => { })); - it('should get all of folder', inject((FeedResource, $controller) => { - let ctrl = $controller('NavigationController', { + it('should get all of folder', inject(function (FeedResource, $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, }); @@ -139,8 +139,9 @@ describe('NavigationController', () => { })); - it('should get the unreadcount', inject((FeedResource, $controller) => { - let ctrl = $controller('NavigationController', { + it('should get the unreadcount', inject(function (FeedResource, + $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, }); @@ -151,8 +152,9 @@ describe('NavigationController', () => { })); - it('should get the starred count', inject((ItemResource, $controller) => { - let ctrl = $controller('NavigationController', { + it('should get the starred count', inject(function (ItemResource, + $controller) { + var ctrl = $controller('NavigationController', { ItemResource: ItemResource, }); @@ -162,8 +164,8 @@ describe('NavigationController', () => { })); - it('should toggle a folder', inject((FolderResource, $controller) => { - let ctrl = $controller('NavigationController', { + it('should toggle a folder', inject(function (FolderResource, $controller) { + var ctrl = $controller('NavigationController', { FolderResource: FolderResource, }); @@ -175,9 +177,9 @@ describe('NavigationController', () => { })); - it('should check if a folder has feeds', inject((FeedResource, - $controller) => { - let ctrl = $controller('NavigationController', { + it('should check if a folder has feeds', inject(function (FeedResource, + $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, }); @@ -186,9 +188,9 @@ describe('NavigationController', () => { })); - it('should check if a subfeed is active', inject((FeedResource, - FEED_TYPE, $controller) => { - let ctrl = $controller('NavigationController', { + it('should check if a subfeed is active', inject(function (FeedResource, + FEED_TYPE, $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, $route: { current: { @@ -205,9 +207,9 @@ describe('NavigationController', () => { expect(ctrl.subFeedActive(3)).toBe(true); })); - it('should check if a subscriptions is active', inject((FeedResource, - FEED_TYPE, $controller) => { - let ctrl = $controller('NavigationController', { + it('should check if a subscriptions is active', inject(function ( + FeedResource, FEED_TYPE, $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, $route: { current: { @@ -222,9 +224,9 @@ describe('NavigationController', () => { })); - it('should check if a starred is active', inject((FeedResource, - FEED_TYPE, $controller) => { - let ctrl = $controller('NavigationController', { + it('should check if a starred is active', inject(function (FeedResource, + FEED_TYPE, $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, $route: { current: { @@ -240,9 +242,9 @@ describe('NavigationController', () => { - it('should check if a feed is active', inject((FeedResource, - FEED_TYPE, $controller) => { - let ctrl = $controller('NavigationController', { + it('should check if a feed is active', inject(function (FeedResource, + FEED_TYPE, $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, $route: { current: { @@ -260,9 +262,9 @@ describe('NavigationController', () => { })); - it('should check if a folder is active', inject((FeedResource, - FEED_TYPE, $controller) => { - let ctrl = $controller('NavigationController', { + it('should check if a folder is active', inject(function (FeedResource, + FEED_TYPE, $controller) { + var ctrl = $controller('NavigationController', { FeedResource: FeedResource, $route: { current: { @@ -280,7 +282,8 @@ describe('NavigationController', () => { })); - it('should expose check if folder exists', inject((FolderResource) => { + it('should expose check if folder exists', inject(function ( + FolderResource) { expect(controller.folderNameExists('hi')).toBe(false); FolderResource.add({name: 'hi'}); expect(controller.folderNameExists('hi')).toBe(true); diff --git a/js/tests/unit/controller/SettingsControllerSpec.js b/js/tests/unit/controller/SettingsControllerSpec.js index fbe8b3438..ac6d2c9b6 100644 --- a/js/tests/unit/controller/SettingsControllerSpec.js +++ b/js/tests/unit/controller/SettingsControllerSpec.js @@ -7,28 +7,28 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('SettingsController', () => { +describe('SettingsController', function () { 'use strict'; - let route; + var route; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.value('BASE_URL', 'base'); })); - beforeEach(() => { + beforeEach(function () { route = { reload: jasmine.createSpy('Route') }; }); - it('should set values', inject(($controller) => { - let SettingsResource = { + it('should set values', inject(function ($controller) { + var SettingsResource = { set: jasmine.createSpy('SettingsResource'), - get: key => key + get: function (key) { return key; } }; - let ctrl = $controller('SettingsController', { + var ctrl = $controller('SettingsController', { SettingsResource: SettingsResource, $route: route }); @@ -39,13 +39,13 @@ describe('SettingsController', () => { })); - it('should reload page if set needed', inject(($controller) => { - let SettingsResource = { + it('should reload page if set needed', inject(function ($controller) { + var SettingsResource = { set: jasmine.createSpy('SettingsResource'), - get: key => key + get: function (key) { return key; } }; - let ctrl = $controller('SettingsController', { + var ctrl = $controller('SettingsController', { SettingsResource: SettingsResource, $route: route }); @@ -59,10 +59,10 @@ describe('SettingsController', () => { })); - it('should return feed size', inject(($controller, FeedResource) => { + it('should return feed size', inject(function ($controller, FeedResource) { FeedResource.add({url: 'hi'}); - let ctrl = $controller('SettingsController', { + var ctrl = $controller('SettingsController', { FeedResource: FeedResource, $route: route }); diff --git a/js/tests/unit/filter/UnreadCountFormatterSpec.js b/js/tests/unit/filter/UnreadCountFormatterSpec.js index 14152f047..83a96ebfe 100644 --- a/js/tests/unit/filter/UnreadCountFormatterSpec.js +++ b/js/tests/unit/filter/UnreadCountFormatterSpec.js @@ -7,18 +7,18 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('unreadCountFormatter', () => { +describe('unreadCountFormatter', function () { 'use strict'; - let filter; + var filter; beforeEach(module('News')); - beforeEach(inject(($filter) => { + beforeEach(inject(function ($filter) { filter = $filter('unreadCountFormatter'); })); - it('should format the unread count', () => { + it('should format the unread count', function () { expect(filter(999)).toBe(999); expect(filter(1000)).toBe('99 |