diff options
Diffstat (limited to 'js/tests/unit/service')
-rw-r--r-- | js/tests/unit/service/ItemResourceSpec.js | 99 |
1 files changed, 98 insertions, 1 deletions
diff --git a/js/tests/unit/service/ItemResourceSpec.js b/js/tests/unit/service/ItemResourceSpec.js index 8d0f1864e..49989472f 100644 --- a/js/tests/unit/service/ItemResourceSpec.js +++ b/js/tests/unit/service/ItemResourceSpec.js @@ -10,10 +10,16 @@ describe('ItemResource', () => { 'use strict'; + let http; + beforeEach(module('News', ($provide) => { $provide.value('BASE_URL', 'base'); })); + beforeEach(inject(($httpBackend) => { + http = $httpBackend; + })); + it('should receive the newestItemId', inject((ItemResource) => { ItemResource.receive(3, 'newestItemId'); @@ -43,7 +49,83 @@ describe('ItemResource', () => { })); + it ('should keep item unread', inject((ItemResource) => { + http.expectPOST('base/items/3/read', {isRead: false}).respond(200, {}); + + ItemResource.receive([ + { + id: 3, + feedId: 4, + unread: false + }, + { + id: 4, + feedId: 3, + unread: false + } + ], 'items'); + + ItemResource.keepUnread(3); + + http.flush(); + + expect(ItemResource.get(3).keepUnread).toBe(true); + expect(ItemResource.get(3).unread).toBe(true); + })); + + it ('should mark item as read', inject((ItemResource) => { + http.expectPOST('base/items/3/read', {isRead: true}).respond(200, {}); + + ItemResource.receive([ + { + id: 3, + feedId: 4, + unread: true + }, + { + id: 4, + feedId: 3, + unread: true + } + ], 'items'); + + ItemResource.read(3); + + http.flush(); + + expect(ItemResource.get(3).unread).toBe(false); + })); + + + it ('should star item', inject((ItemResource) => { + http.expectPOST('base/items/4/a/star', {isStarred: true}).respond(200, {}); + + ItemResource.receive([ + { + id: 3, + feedId: 4, + starred: false, + guidHash: 'a' + }, + { + id: 4, + feedId: 3, + starred: false + } + ], 'items'); + + ItemResource.star(3); + + http.flush(); + + expect(ItemResource.get(3).starred).toBe(true); + })); + + + it ('should mark feed as read', inject((ItemResource) => { + http.expectPOST('base/feeds/4/read').respond(200, {}); + ItemResource.receive([ { id: 3, @@ -54,12 +136,27 @@ describe('ItemResource', () => { id: 4, feedId: 3, unread: true + }, + { + id: 5, + feedId: 4, + unread: true } ], 'items'); - ItemResource.markRead(3); + ItemResource.readFeed(4); + + http.flush(); expect(ItemResource.get(3).unread).toBe(false); + expect(ItemResource.get(5).unread).toBe(false); })); + + afterEach(() => { + http.verifyNoOutstandingExpectation(); + http.verifyNoOutstandingRequest(); + }); + + });
\ No newline at end of file |