diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-25 21:13:09 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-25 21:13:09 +0100 |
commit | 7ade1165ddd0aa2d650ea28ae2f38a412375f9cc (patch) | |
tree | d2afa45ede7e721e2e0c0efdc0106bc3e049db17 /js/tests | |
parent | 29b4fc15528cd88ab1b7b77aa7b9b4632042dd0c (diff) |
added feedcontroller methods and tests
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/controllers/feedcontrollerSpec.coffee | 174 | ||||
-rw-r--r-- | js/tests/services/showallSpec.coffee | 17 | ||||
-rw-r--r-- | js/tests/services/starredcountSpec.coffee | 15 |
3 files changed, 174 insertions, 32 deletions
diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee index a356e8f81..f338dcf75 100644 --- a/js/tests/controllers/feedcontrollerSpec.coffee +++ b/js/tests/controllers/feedcontrollerSpec.coffee @@ -28,36 +28,33 @@ describe '_FeedController', -> beforeEach inject (@_FeedController, @ActiveFeed, @ShowAll, @FeedType, - @StarredCount) => + @StarredCount, @FeedModel, @FolderModel, @ItemModel) => @scope = {} - @feedModel = - getAll: -> - @folderModel = - getAll: -> - @controller = new @_FeedController(@scope, @folderModel, @feedModel, @ActiveFeed, - @ShowAll, @FeedType, @StarredCount) + @persistence = { + getItems: -> + } + @controller = new @_FeedController(@scope, @FolderModel, @FeedModel, + @ActiveFeed, @ShowAll, @FeedType, + @StarredCount, @persistence, + @ItemModel) it 'should make folders available', => - @folderModel = - getAll: jasmine.createSpy('FolderModel') - - new @_FeedController(@scope, @folderModel, @feedModel, @_ActiveFeed) + @FolderModel.getAll = jasmine.createSpy('FolderModel') + new @_FeedController(@scope, @FolderModel, @FeedModel, @_ActiveFeed) - expect(@folderModel.getAll).toHaveBeenCalled() + expect(@FolderModel.getAll).toHaveBeenCalled() it 'should make feeds availabe', => - @feedModel = - getAll: jasmine.createSpy('FeedModel') - - new @_FeedController(@scope, @folderModel, @feedModel, @_ActiveFeed) + @FeedModel.getAll = jasmine.createSpy('FeedModel') + new @_FeedController(@scope, @FolderModel, @FeedModel, @_ActiveFeed) - expect(@feedModel.getAll).toHaveBeenCalled() + expect(@FeedModel.getAll).toHaveBeenCalled() it 'should make feedtype available', => - expect(@scope.feedType).toBe(@FeedType) + expect(@scope.feedType).toBe(@FeedType) it 'should check the active feed', => @@ -72,5 +69,142 @@ describe '_FeedController', -> it 'should provide ShowAll', => expect(@scope.isShowAll()).toBeFalsy() - @ShowAll.handle(true) - expect(@scope.isShowAll()).toBeTruthy()
\ No newline at end of file + @ShowAll.setShowAll(true) + expect(@scope.isShowAll()).toBeTruthy() + + + it 'should handle show all correctly', => + @persistence.userSettingsReadHide = jasmine.createSpy('hide') + @persistence.userSettingsReadShow = jasmine.createSpy('show') + + @scope.setShowAll(true) + expect(@ShowAll.getShowAll()).toBeTruthy() + expect(@persistence.userSettingsReadShow).toHaveBeenCalled() + expect(@persistence.userSettingsReadHide).not.toHaveBeenCalled() + + + it 'should handle hide all correctly', => + @persistence.userSettingsReadHide = jasmine.createSpy('hide') + @persistence.userSettingsReadShow = jasmine.createSpy('show') + + @scope.setShowAll(false) + expect(@ShowAll.getShowAll()).toBeFalsy() + expect(@persistence.userSettingsReadShow).not.toHaveBeenCalled() + expect(@persistence.userSettingsReadHide).toHaveBeenCalled() + + + it 'should get the correct count for starred items', => + @StarredCount.setStarredCount(133) + count = @scope.getUnreadCount(@FeedType.Starred, 0) + + expect(count).toBe(133) + + + it 'should set the count to 999+ if the count is over 999', => + @StarredCount.setStarredCount(1000) + count = @scope.getUnreadCount(@FeedType.Starred, 0) + + expect(count).toBe('999+') + + + it 'should get the correct unread count for feeds', => + @FeedModel.add({id: 3, unreadCount:134}) + count = @scope.getUnreadCount(@FeedType.Feed, 3) + + expect(count).toBe(134) + + + it 'should get the correct unread count for subscribtions', => + @FeedModel.add({id: 3, unreadCount:134}) + @FeedModel.add({id: 5, unreadCount:2}) + count = @scope.getUnreadCount(@FeedType.Subscriptions, 0) + + expect(count).toBe(136) + + + it 'should get the correct unread count for folders', => + @FeedModel.add({id: 3, unreadCount:134, folderId: 3}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2}) + @FeedModel.add({id: 1, unreadCount:12, folderId: 5}) + @FeedModel.add({id: 2, unreadCount:35, folderId: 3}) + count = @scope.getUnreadCount(@FeedType.Folder, 3) + + expect(count).toBe(169) + + + it 'should reset the item cache when a different feed is being loaded', => + @ItemModel.clear = jasmine.createSpy('clear') + @ActiveFeed.handle({id: 3, type: 3}) + @scope.loadFeed(3, 3) + + expect(@ItemModel.clear).not.toHaveBeenCalled() + + @scope.loadFeed(3, 4) + expect(@ItemModel.clear).toHaveBeenCalled() + + + it 'should send a get latest items query when feed did not change', => + @ItemModel.add({id: 1, lastModified: 5}) + @ItemModel.add({id: 2, lastModified: 1}) + @ItemModel.add({id: 4, lastModified: 323}) + @ItemModel.add({id: 6, lastModified: 44}) + @persistence.getItems = jasmine.createSpy('latest') + @ActiveFeed.handle({id: 3, type: 3}) + @scope.loadFeed(3, 3) + + expect(@persistence.getItems).toHaveBeenCalledWith(3, 3, 0, null, 323) + + + it 'should send a get all items query when feed changed', => + @persistence.getItems = jasmine.createSpy('latest') + @ActiveFeed.handle({id: 3, type: 3}) + @scope.loadFeed(4, 3) + + expect(@persistence.getItems).toHaveBeenCalledWith(4, 3, 0) + + + it 'should set active feed to new feed if changed', => + @ActiveFeed.handle({id: 3, type: 3}) + @scope.loadFeed(4, 3) + + expect(@ActiveFeed.getId()).toBe(3) + expect(@ActiveFeed.getType()).toBe(4) + + + it 'should return true when calling isShown and ShowAll is set to true', => + @ShowAll.setShowAll(true) + expect(@scope.isShown(3, 4)).toBeTruthy() + + @ShowAll.setShowAll(false) + expect(@scope.isShown(3, 4)).toBeFalsy() + + + it 'should return true if ShowAll is false but unreadcount is not 0', => + @ShowAll.setShowAll(false) + @FeedModel.add({id: 4, unreadCount: 0}) + expect(@scope.isShown(@FeedType.Feed, 4)).toBeFalsy() + + @FeedModel.add({id: 4, unreadCount: 12}) + expect(@scope.isShown(@FeedType.Feed, 4)).toBeTruthy() + + + it 'should return all feeds of a folder', => + @FeedModel.add({id: 3, unreadCount:134, folderId: 3}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2}) + @FeedModel.add({id: 1, unreadCount:12, folderId: 5}) + @FeedModel.add({id: 2, unreadCount:35, folderId: 3}) + + result = @scope.getFeedsOfFolder(3) + + expect(result).toContain(@FeedModel.getById(3)) + expect(result).toContain(@FeedModel.getById(2)) + expect(result).not.toContain(@FeedModel.getById(1)) + expect(result).not.toContain(@FeedModel.getById(5)) + + + it 'should return true when folder has feeds', => + @FeedModel.add({id: 5, unreadCount:2, folderId: 2}) + expect(@scope.hasFeeds(3)).toBeFalsy() + + @FeedModel.add({id: 2, unreadCount:35, folderId: 3}) + expect(@scope.hasFeeds(3)).toBeTruthy()
\ No newline at end of file diff --git a/js/tests/services/showallSpec.coffee b/js/tests/services/showallSpec.coffee index 65c163ccf..7eba354f4 100644 --- a/js/tests/services/showallSpec.coffee +++ b/js/tests/services/showallSpec.coffee @@ -27,16 +27,23 @@ describe '_ShowAll', -> beforeEach module 'News' beforeEach inject (@_ShowAll) => + @showAll = new @_ShowAll() it 'should be false by default', => - showAll = new @_ShowAll() + - expect(showAll.getShowAll()).toBeFalsy() + expect(@showAll.getShowAll()).toBeFalsy() it 'should set the correct showAll value', => - showAll = new @_ShowAll() - showAll.handle(true) + @showAll.handle(true) + expect(@showAll.getShowAll()).toBeTruthy() - expect(showAll.getShowAll()).toBeTruthy()
\ No newline at end of file + + it 'should provide a set showall setter', => + @showAll.setShowAll(true) + expect(@showAll.getShowAll()).toBeTruthy() + + @showAll.setShowAll(false) + expect(@showAll.getShowAll()).toBeFalsy() diff --git a/js/tests/services/starredcountSpec.coffee b/js/tests/services/starredcountSpec.coffee index f7b619a95..61598324a 100644 --- a/js/tests/services/starredcountSpec.coffee +++ b/js/tests/services/starredcountSpec.coffee @@ -27,16 +27,17 @@ describe '_StarredCount', -> beforeEach module 'News' beforeEach inject (@_StarredCount) => - + @starred = new @_StarredCount() it 'should be 0 by default', => - starred = new @_StarredCount() - - expect(starred.getStarredCount()).toBe(0) + expect(@starred.getStarredCount()).toBe(0) it 'should set the correct starred count', => - starred = new @_StarredCount() - starred.handle(3) + @starred.handle(3) + expect(@starred.getStarredCount()).toBe(3) + - expect(starred.getStarredCount()).toBe(3)
\ No newline at end of file + it 'should provide a setter', => + @starred.setStarredCount(15) + expect(@starred.getStarredCount()).toBe(15)
\ No newline at end of file |