summaryrefslogtreecommitdiffstats
path: root/js/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-04 19:58:51 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-04 19:59:06 +0200
commit346346e01c5c61e61b522520248de90e0ede3f17 (patch)
tree9d38239274db7e26eac9eda9f1853113e655857b /js/tests
parent2d8b635796ba117619063792b0a00c50dc91d2a6 (diff)
added most of the bl functionality
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/controllers/feedcontrollerSpec.coffee29
-rw-r--r--js/tests/services/bl/blSpec.coffee86
-rw-r--r--js/tests/services/bl/feedblSpec.coffee39
-rw-r--r--js/tests/services/bl/folderblSpec.coffee45
-rw-r--r--js/tests/services/bl/itemblSpec.coffee21
-rw-r--r--js/tests/services/bl/starredblSpec.coffee54
-rw-r--r--js/tests/services/bl/subscriptionsblSpec.coffee83
7 files changed, 296 insertions, 61 deletions
diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee
index af4eca57c..293a55f47 100644
--- a/js/tests/controllers/feedcontrollerSpec.coffee
+++ b/js/tests/controllers/feedcontrollerSpec.coffee
@@ -110,35 +110,6 @@ describe '_FeedController', ->
- xit '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()
-
-
- xit '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, 6)
-
-
- xit '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)
xit 'should set active feed to new feed if changed', =>
diff --git a/js/tests/services/bl/blSpec.coffee b/js/tests/services/bl/blSpec.coffee
new file mode 100644
index 000000000..6da4724ec
--- /dev/null
+++ b/js/tests/services/bl/blSpec.coffee
@@ -0,0 +1,86 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+describe 'Bl', ->
+
+ beforeEach module 'News'
+
+ beforeEach inject (@_Bl, @ActiveFeed, @FeedType, @ItemModel) =>
+ type = @FeedType.Starred
+ angular.module('News').factory 'Persistence', =>
+ @getItemsSpy = jasmine.createSpy('getItems')
+ @persistence = {
+ getItems: @getItemsSpy
+ }
+
+ class TestBl extends @_Bl
+
+ constructor: (activeFeed, persistence, itemModel) ->
+ super(activeFeed, persistence, itemModel, type)
+
+ @bl = new TestBl(@ActiveFeed, @persistence, @ItemModel)
+
+
+ it 'should reset the item cache when a different feed is being loaded', =>
+ @ItemModel.clear = jasmine.createSpy('clear')
+ @ActiveFeed.handle({id: 0, type: @FeedType.Starred})
+ @bl.load(0)
+
+ expect(@ItemModel.clear).not.toHaveBeenCalled()
+
+ @bl.load(2)
+ expect(@ItemModel.clear).toHaveBeenCalled()
+
+ @ActiveFeed.handle({id: 2, type: @FeedType.Feed})
+ @bl.load(2)
+ 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: @FeedType.Starred})
+ @bl.load(3)
+
+ expect(@persistence.getItems).toHaveBeenCalledWith(@FeedType.Starred, 3,
+ 0, null, 6)
+
+
+ it 'should send a get all items query when feed changed', =>
+ @persistence.getItems = jasmine.createSpy('latest')
+ @ActiveFeed.handle({id: 3, type: @FeedType.Feed})
+ @bl.load(3)
+
+ expect(@persistence.getItems).toHaveBeenCalledWith(@FeedType.Starred, 3,
+ 0)
+
+
+ it 'should be active when its selected', =>
+ expect(@bl.isActive(0)).toBe(false)
+
+ @ActiveFeed.handle({type: @FeedType.Starred, id:0})
+ expect(@bl.isActive(0)).toBe(true) \ No newline at end of file
diff --git a/js/tests/services/bl/feedblSpec.coffee b/js/tests/services/bl/feedblSpec.coffee
index 602e93909..241ba20f5 100644
--- a/js/tests/services/bl/feedblSpec.coffee
+++ b/js/tests/services/bl/feedblSpec.coffee
@@ -27,11 +27,23 @@ describe 'FeedBl', ->
beforeEach =>
angular.module('News').factory 'Persistence', =>
- @persistence = {}
+ @setFeedReadSpy = jasmine.createSpy('setFeedRead')
+ @persistence = {
+ setFeedRead: @setFeedReadSpy
+ }
beforeEach inject (@FeedBl, @FeedModel, @ItemModel) =>
+ it 'should delete feeds', =>
+ @FeedModel.removeById = jasmine.createSpy('remove')
+ @persistence.deleteFeed = jasmine.createSpy('deletequery')
+ @FeedBl.delete(3)
+
+ expect(@FeedModel.removeById).toHaveBeenCalledWith(3)
+ expect(@persistence.deleteFeed).toHaveBeenCalledWith(3)
+
+
it 'should return the number of unread feeds', =>
@FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'})
count = @FeedBl.getUnreadCount(3)
@@ -63,16 +75,6 @@ describe 'FeedBl', ->
expect(count).toBe(169)
- it 'should delete feeds', =>
- @FeedModel.removeById = jasmine.createSpy('remove')
- @persistence.deleteFeed = jasmine.createSpy('deletequery')
- @FeedBl.delete(3)
-
- expect(@FeedModel.removeById).toHaveBeenCalledWith(3)
- expect(@persistence.deleteFeed).toHaveBeenCalledWith(3)
-
-
-
it 'should mark feed as read', =>
@persistence.setFeedRead = jasmine.createSpy('setFeedRead')
@FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'})
@@ -83,6 +85,9 @@ describe 'FeedBl', ->
expect(@persistence.setFeedRead).toHaveBeenCalledWith(5, 6)
expect(@FeedModel.getById(5).unreadCount).toBe(0)
+ expect(@ItemModel.getById(6).isRead()).toBeTruthy()
+ expect(@ItemModel.getById(3).isRead()).toBeTruthy()
+ expect(@ItemModel.getById(2).isRead()).toBeTruthy()
it 'should mark all as read', =>
@@ -101,6 +106,14 @@ describe 'FeedBl', ->
it 'should get the correct unread count for subscribtions', =>
@FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'})
@FeedModel.add({id: 5, unreadCount:2, urlHash: 'a2'})
- count = @FeedBl.getUnreadCount()
+ count = @FeedBl.getAllUnreadCount()
+
+ expect(count).toBe(136)
+
+
+ it 'should return the correct number of feeds', =>
+ @FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'})
+ @FeedModel.add({id: 5, unreadCount:2, urlHash: 'a2'})
+ count = @FeedBl.getNumberOfFeeds()
- expect(count).toBe(136) \ No newline at end of file
+ expect(count).toBe(2) \ No newline at end of file
diff --git a/js/tests/services/bl/folderblSpec.coffee b/js/tests/services/bl/folderblSpec.coffee
index 299633cf5..c7590f51f 100644
--- a/js/tests/services/bl/folderblSpec.coffee
+++ b/js/tests/services/bl/folderblSpec.coffee
@@ -29,7 +29,10 @@ describe 'FolderBl', ->
angular.module('News').factory 'Persistence', =>
@persistence = {}
- beforeEach inject (@FolderBl, @FolderModel, @FeedModel) =>
+ beforeEach inject (@FolderBl, @FolderModel, @FeedModel, @ShowAll,
+ @ActiveFeed, @FeedType) =>
+ @ShowAll.setShowAll(false)
+ @ActiveFeed.handle({type: @FeedType.Feed, id:0})
it 'should delete folders', =>
@@ -76,4 +79,42 @@ describe 'FolderBl', ->
expect(@FeedModel.getById(3).unreadCount).toBe(0)
expect(@FeedModel.getById(1).unreadCount).toBe(0)
- expect(@FeedModel.getById(5).unreadCount).toBe(2) \ No newline at end of file
+ expect(@FeedModel.getById(5).unreadCount).toBe(2)
+
+
+ it 'should get the correct unread count', =>
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'})
+ @FeedModel.add({id: 6, unreadCount:3, folderId: 3, urlHash: 'a2'})
+ @FeedModel.add({id: 7, unreadCount:4, folderId: 2, urlHash: 'a3'})
+
+ expect(@FolderBl.getUnreadCount(2)).toBe(6)
+
+
+ it 'should be visible if show all is true', =>
+ expect(@FolderBl.isVisible(3)).toBe(false)
+
+ @ShowAll.setShowAll(true)
+ expect(@FolderBl.isVisible(3)).toBe(true)
+
+
+ it 'should be visible if its active', =>
+ @ActiveFeed.handle({type: @FeedType.Folder, id:3})
+ expect(@FolderBl.isVisible(3)).toBe(true)
+
+
+ it 'should be visible if one of its subfeeds is active', =>
+ @FeedModel.add({id: 5, unreadCount:0, folderId: 2, urlHash: 'a1'})
+ @FeedModel.add({id: 6, unreadCount:0, folderId: 3, urlHash: 'a2'})
+ @FeedModel.add({id: 7, unreadCount:0, folderId: 2, urlHash: 'a3'})
+
+ @ActiveFeed.handle({type: @FeedType.Feed, id:6})
+ expect(@FolderBl.isVisible(3)).toBe(true)
+
+
+ it 'should be visible if showAll is false and it has unread items', =>
+ @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'})
+ @FeedModel.add({id: 6, unreadCount:3, folderId: 3, urlHash: 'a2'})
+ @FeedModel.add({id: 7, unreadCount:4, folderId: 2, urlHash: 'a3'})
+
+ @ActiveFeed.handle({type: @FeedType.Folder, id:2})
+ expect(@FolderBl.isVisible(3)).toBe(true)
diff --git a/js/tests/services/bl/itemblSpec.coffee b/js/tests/services/bl/itemblSpec.coffee
index e2644989e..158b09467 100644
--- a/js/tests/services/bl/itemblSpec.coffee
+++ b/js/tests/services/bl/itemblSpec.coffee
@@ -28,22 +28,9 @@ describe 'ItemBl', ->
beforeEach =>
angular.module('News').factory 'Persistence', =>
- @persistence = {}
+ @setFeedReadSpy = jasmine.createSpy('setFeedRead')
+ @persistence = {
+
+ }
beforeEach inject (@ItemModel, @ItemBl, @StatusFlag) =>
-
-
- it 'should mark all items read of a feed', =>
- @persistence.setFeedRead = jasmine.createSpy('setFeedRead')
- item1 = {id: 6, feedId: 5, guidHash: 'a1', status: @StatusFlag.UNREAD}
- item2 = {id: 3, feedId: 5, guidHash: 'a2', status: @StatusFlag.UNREAD}
- item3 = {id: 2, feedId: 5, guidHash: 'a3', status: @StatusFlag.UNREAD}
- @ItemModel.add(item1)
- @ItemModel.add(item2)
- @ItemModel.add(item3)
- @ItemBl.markAllRead(5)
-
- expect(@persistence.setFeedRead).toHaveBeenCalledWith(5, 6)
- expect(item1.isRead()).toBe(true)
- expect(item2.isRead()).toBe(true)
- expect(item3.isRead()).toBe(true) \ No newline at end of file
diff --git a/js/tests/services/bl/starredblSpec.coffee b/js/tests/services/bl/starredblSpec.coffee
new file mode 100644
index 000000000..5f4ec7a4f
--- /dev/null
+++ b/js/tests/services/bl/starredblSpec.coffee
@@ -0,0 +1,54 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+describe 'StarredBl', ->
+
+ beforeEach module 'News'
+
+ beforeEach =>
+ angular.module('News').factory 'Persistence', =>
+ @persistence = {}
+
+ beforeEach inject (@StarredBl, @StarredCount, @ActiveFeed, @FeedType) =>
+ @ActiveFeed.handle({type: @FeedType.Feed, id:0})
+ @StarredCount.setStarredCount(0)
+
+
+ it 'should not be visible if starredCount is 0', =>
+ expect(@StarredBl.isVisible()).toBe(false)
+
+ @StarredCount.setStarredCount(144)
+ expect(@StarredBl.isVisible()).toBe(true)
+
+
+ it 'should always be visible if its the active feed', =>
+ @ActiveFeed.handle({type: @FeedType.Starred, id:0})
+ expect(@StarredBl.isVisible()).toBe(true)
+
+
+ it 'should get the correct unread count', =>
+ @StarredCount.setStarredCount(144)
+
+ expect(@StarredBl.getUnreadCount()).toBe(144)
+
+
diff --git a/js/tests/services/bl/subscriptionsblSpec.coffee b/js/tests/services/bl/subscriptionsblSpec.coffee
new file mode 100644
index 000000000..90f39cef3
--- /dev/null
+++ b/js/tests/services/bl/subscriptionsblSpec.coffee
@@ -0,0 +1,83 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+describe 'SubscriptionsBl', ->
+
+ beforeEach module 'News'
+
+ beforeEach =>
+ angular.module('News').factory 'Persistence', =>
+ @setFeedReadSpy = jasmine.createSpy('setFeedRead')
+ @persistence = {
+ setFeedRead: @setFeedReadSpy
+ }
+
+ beforeEach inject (@SubscriptionsBl, @ShowAll, @FeedModel, @ActiveFeed,
+ @FeedType) =>
+ @ShowAll.setShowAll(false)
+ @ActiveFeed.handle({type: @FeedType.Feed, id:0})
+
+
+ it 'should be visible shows all items is set to true and there are feeds', =>
+ @FeedModel.add({id: 3, unreadCount: 5})
+
+ expect(@SubscriptionsBl.isVisible()).toBe(true)
+
+ @ShowAll.setShowAll(true)
+ expect(@SubscriptionsBl.isVisible()).toBe(true)
+
+
+ it 'should not be visible if there are no feeds', =>
+ expect(@SubscriptionsBl.isVisible()).toBe(false)
+
+ @ShowAll.setShowAll(true)
+ expect(@SubscriptionsBl.isVisible()).toBe(false)
+
+
+ it 'should not be visible if showall is false + there are no unread', =>
+ @FeedModel.add({id: 3, unreadCount: 0})
+ expect(@SubscriptionsBl.isVisible()).toBe(false)
+
+
+ it 'should always be visible if its the active feed', =>
+ @ActiveFeed.handle({type: @FeedType.Subscriptions, id:0})
+ expect(@SubscriptionsBl.isVisible()).toBe(true)
+
+
+ it 'should mark all feeds as read', =>
+ item = {id: 3, unreadCount: 132}
+ @FeedModel.add(item)
+
+ @SubscriptionsBl.markAllRead()
+
+ expect(item.unreadCount).toBe(0)
+ expect(@setFeedReadSpy).toHaveBeenCalled()
+
+
+ it 'should get the correct unread count', =>
+ @FeedModel.add({id: 3, unreadCount: 132, urlHash: 'hoho'})
+ @FeedModel.add({id: 4, unreadCount: 12, urlHash: 'hohod'})
+
+ expect(@SubscriptionsBl.getUnreadCount()).toBe(144)
+
+