summaryrefslogtreecommitdiffstats
path: root/js/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-05 13:50:30 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-05 13:50:30 +0200
commit1a169b29c153389117f462f70c4d08cf91fc5dfb (patch)
treebb42c2e7907e2390fe04c40944e01d139865933d /js/tests
parenta6d1cc915aed37ad6731ab28728d2f4e58f5b6da (diff)
fixed showall toggle and added methods to set items read and starred
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/services/bl/itemblSpec.coffee109
-rw-r--r--js/tests/services/bl/starredblSpec.coffee6
2 files changed, 110 insertions, 5 deletions
diff --git a/js/tests/services/bl/itemblSpec.coffee b/js/tests/services/bl/itemblSpec.coffee
index ff2bbd80a..01b02bfb2 100644
--- a/js/tests/services/bl/itemblSpec.coffee
+++ b/js/tests/services/bl/itemblSpec.coffee
@@ -28,13 +28,10 @@ describe 'ItemBl', ->
beforeEach =>
angular.module('News').factory 'Persistence', =>
- @setFeedReadSpy = jasmine.createSpy('setFeedRead')
- @persistence = {
-
- }
+ @persistence = {}
beforeEach inject (@ItemModel, @ItemBl, @StatusFlag, @ActiveFeed
- @FeedType) =>
+ @FeedType, @FeedModel, @StarredBl) =>
it 'should return all items', =>
@@ -69,3 +66,105 @@ describe 'ItemBl', ->
@ActiveFeed.handle({type: @FeedType.Feed, id: 0})
expect(@ItemBl.noFeedActive()).toBe(false)
+
+ it 'should return the correct feed title', =>
+ item1 = {id: 5, title: 'hi', unreadCount:134, urlHash: 'a3', folderId: 3}
+ @FeedModel.add(item1)
+
+ item2 = {id: 2, feedId: 5, guidHash: 'a3'}
+ @ItemModel.add(item2)
+
+ expect(@ItemBl.getFeedTitle(2)).toBe('hi')
+
+
+ it 'should set an item unstarred', =>
+ @persistence.unstarItem = jasmine.createSpy('star item')
+
+ item2 = {id: 2, feedId: 5, guidHash: 'a3', status: 0}
+ @ItemModel.add(item2)
+ item2.setStarred()
+
+ @ItemBl.toggleStarred(2)
+
+ expect(item2.isStarred()).toBe(false)
+ expect(@StarredBl.getUnreadCount()).toBe(-1)
+ expect(@persistence.unstarItem).toHaveBeenCalledWith(5, 'a3')
+
+
+ it 'should set an item starred', =>
+ @persistence.starItem = jasmine.createSpy('unstar item')
+
+ item2 = {id: 2, feedId: 5, guidHash: 'a3', status: 0}
+ @ItemModel.add(item2)
+ item2.setUnstarred()
+
+ @ItemBl.toggleStarred(2)
+
+ expect(item2.isStarred()).toBe(true)
+ expect(@StarredBl.getUnreadCount()).toBe(1)
+ expect(@persistence.starItem).toHaveBeenCalledWith(5, 'a3')
+
+
+ it 'should set an item read', =>
+ @persistence.readItem = jasmine.createSpy('read item')
+
+ item = {id: 2, feedId: 5, guidHash: 'a3', status: 0}
+ @ItemModel.add(item)
+ item.setUnread()
+
+ @ItemBl.setRead(2)
+
+ expect(item.isRead()).toBe(true)
+ expect(@persistence.readItem).toHaveBeenCalledWith(2)
+
+
+ it 'should return false when item kept unread does not exist', =>
+ expect(@ItemBl.isKeptUnread(2)).toBe(false)
+
+
+ it 'should return false if an item is not kept unread', =>
+ item = {id: 2, feedId: 5, guidHash: 'a3', status: 0}
+ @ItemModel.add(item)
+
+ expect(@ItemBl.isKeptUnread(2)).toBe(false)
+
+
+ it 'should toggle an item as kept unread', =>
+ @persistence.unreadItem = jasmine.createSpy('unread item')
+
+ item = {id: 2, feedId: 5, guidHash: 'a3', status: 0}
+ @ItemModel.add(item)
+
+ expect(@ItemBl.isKeptUnread(2)).toBe(false)
+
+ @ItemBl.toggleKeepUnread(2)
+ expect(@ItemBl.isKeptUnread(2)).toBe(true)
+
+ @ItemBl.toggleKeepUnread(2)
+ expect(@ItemBl.isKeptUnread(2)).toBe(false)
+
+
+ it 'should set an item as unread', =>
+ @persistence.unreadItem = jasmine.createSpy('unread item')
+
+ item = {id: 2, feedId: 5, guidHash: 'a3', status: 0}
+ @ItemModel.add(item)
+ item.setRead()
+
+ @ItemBl.setUnread(2)
+
+ expect(item.isRead()).toBe(false)
+ expect(@persistence.unreadItem).toHaveBeenCalledWith(2)
+
+
+ it 'should set item as unread if kept unread is toggled and it is read', =>
+ @persistence.unreadItem = jasmine.createSpy('unread item')
+
+ item = {id: 2, feedId: 5, guidHash: 'a3', status: 0}
+ @ItemModel.add(item)
+ item.setRead()
+
+ @ItemBl.toggleKeepUnread(2)
+
+ expect(item.isRead()).toBe(false)
+ expect(@persistence.unreadItem).toHaveBeenCalledWith(2)
diff --git a/js/tests/services/bl/starredblSpec.coffee b/js/tests/services/bl/starredblSpec.coffee
index 5f4ec7a4f..6115dcf5f 100644
--- a/js/tests/services/bl/starredblSpec.coffee
+++ b/js/tests/services/bl/starredblSpec.coffee
@@ -52,3 +52,9 @@ describe 'StarredBl', ->
expect(@StarredBl.getUnreadCount()).toBe(144)
+ it 'should increase the starred count', =>
+ expect(@StarredBl.increaseCount()).toBe(1)
+
+
+ it 'should decrease the starred count', =>
+ expect(@StarredBl.decreaseCount()).toBe(-1) \ No newline at end of file