diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-30 00:06:49 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-30 00:06:49 +0200 |
commit | 79032a17fb1f458aae723098ddc1a96c28daad05 (patch) | |
tree | b7e7a7f99e6e334d9058de7445280da6624ec3e3 /js/tests/unit/controller | |
parent | 320304c909dc12c14b53335a7f32550809c06178 (diff) |
add autopaging
Diffstat (limited to 'js/tests/unit/controller')
-rw-r--r-- | js/tests/unit/controller/ContentControllerSpec.js | 191 | ||||
-rw-r--r-- | js/tests/unit/controller/NavigationControllerSpec.js | 1 |
2 files changed, 191 insertions, 1 deletions
diff --git a/js/tests/unit/controller/ContentControllerSpec.js b/js/tests/unit/controller/ContentControllerSpec.js index 8757cb5c5..d814a56de 100644 --- a/js/tests/unit/controller/ContentControllerSpec.js +++ b/js/tests/unit/controller/ContentControllerSpec.js @@ -12,7 +12,8 @@ describe('ContentController', () => { beforeEach(module('News', ($provide) => { - $provide.value('BASE_URL', 'base'); + $provide.constant('BASE_URL', 'base'); + $provide.constant('ITEM_BATCH_SIZE', 5); })); @@ -78,14 +79,22 @@ describe('ContentController', () => { 'items': [{ id: 3, feedId: 4 + }, + { + id: 5, + feedId: 4, + keepUnread: true }] }, }); ctrl.markRead(3); + ctrl.markRead(5); expect(ItemResource.markItemRead).toHaveBeenCalledWith(3); expect(FeedResource.markItemOfFeedRead).toHaveBeenCalledWith(4); + expect(ItemResource.markItemRead.callCount).toBe(1); + expect(FeedResource.markItemOfFeedRead.callCount).toBe(1); })); @@ -209,4 +218,184 @@ describe('ContentController', () => { })); + it('should mark multiple items read', inject(($controller, + ItemResource, FeedResource, Publisher) => { + + Publisher.subscribe(ItemResource).toChannels('items'); + ItemResource.markItemsRead = jasmine.createSpy('markRead'); + FeedResource.markItemOfFeedRead = jasmine.createSpy('markRead'); + + let ctrl = $controller('ContentController', { + ItemResource: ItemResource, + FeedResource: FeedResource, + data: { + 'items': [{ + id: 3, + feedId: 4 + }, + { + id: 2, + feedId: 4, + keepUnread: true + }, + { + id: 1, + feedId: 4 + },] + }, + }); + + ctrl.scrollRead([3, 2, 1]); + + expect(ItemResource.markItemsRead).toHaveBeenCalledWith([3, 1]); + expect(FeedResource.markItemOfFeedRead.callCount).toBe(2); + })); + + + it('should not autopage if less than 0 elements', inject(( + $controller, ItemResource, Publisher) => { + + let $route = { + current: { + $$route: { + type: 3 + } + } + }; + + let $routeParams = { + id: 2 + }; + + Publisher.subscribe(ItemResource).toChannels('items'); + ItemResource.autoPage = jasmine.createSpy('autoPage') + .andCallFake(() => { + return { + success: (callback) => { + callback({ + 'items': [] + }); + + return { + error: () => {} + }; + } + } + }); + + let ctrl = $controller('ContentController', { + $routeParams: $routeParams, + $route: $route, + Publisher: Publisher, + ItemResource: ItemResource, + data: {}, + }); + + expect(ctrl.autoPagingEnabled()).toBe(true); + + ctrl.autoPage(); + + expect(ctrl.autoPagingEnabled()).toBe(false); + + expect(ItemResource.autoPage).toHaveBeenCalledWith(3, 2); + + })); + + + it('should autopage if more than 0 elements', inject(( + $controller, ItemResource, Publisher) => { + + let $route = { + current: { + $$route: { + type: 3 + } + } + }; + + let $routeParams = { + id: 2 + }; + + Publisher.subscribe(ItemResource).toChannels('items'); + ItemResource.autoPage = jasmine.createSpy('autoPage') + .andCallFake(() => { + return { + success: (callback) => { + callback({ + 'items': [{items: [{id: 3}]}] + }); + + return { + error: () => {} + }; + } + } + }); + + let ctrl = $controller('ContentController', { + $routeParams: $routeParams, + $route: $route, + Publisher: Publisher, + ItemResource: ItemResource, + data: {}, + }); + + expect(ctrl.autoPagingEnabled()).toBe(true); + + ctrl.autoPage(); + + expect(ctrl.autoPagingEnabled()).toBe(true); + expect(ItemResource.size()).toBe(1); + })); + + + it('should autopage if error', inject(( + $controller, ItemResource, Publisher) => { + + let $route = { + current: { + $$route: { + type: 3 + } + } + }; + + let $routeParams = { + id: 2 + }; + + Publisher.subscribe(ItemResource).toChannels('items'); + ItemResource.autoPage = jasmine.createSpy('autoPage') + .andCallFake(() => { + return { + success: (callback) => { + callback({ + 'items': [] + }); + + return { + error: (callback) => { + callback(); + } + }; + } + } + }); + + let ctrl = $controller('ContentController', { + $routeParams: $routeParams, + $route: $route, + Publisher: Publisher, + ItemResource: ItemResource, + data: {}, + }); + + expect(ctrl.autoPagingEnabled()).toBe(true); + + ctrl.autoPage(); + + expect(ctrl.autoPagingEnabled()).toBe(true); + })); + }); diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js index 653dfea26..433a40e3f 100644 --- a/js/tests/unit/controller/NavigationControllerSpec.js +++ b/js/tests/unit/controller/NavigationControllerSpec.js @@ -14,6 +14,7 @@ describe('NavigationController', () => { beforeEach(module('News', ($provide) => { $provide.value('BASE_URL', 'base'); + $provide.constant('ITEM_BATCH_SIZE', 5); })); beforeEach(inject(($controller) => { |