diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-26 11:20:55 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-26 11:52:50 +0200 |
commit | f987751d8c5c7a3ee660411afb9d01e6a822aed5 (patch) | |
tree | 9eb35d0575c62648b7f50e6c94afb808366cf05c /js | |
parent | d947c35d05ddb12dad591d29a9b0f948c5f4f732 (diff) |
order by pubdate on the client side fix #115
Diffstat (limited to 'js')
-rw-r--r-- | js/app/services/businesslayer/businesslayer.coffee | 2 | ||||
-rw-r--r-- | js/app/services/businesslayer/feedbusinesslayer.coffee | 10 | ||||
-rw-r--r-- | js/app/services/businesslayer/itembusinesslayer.coffee | 16 | ||||
-rw-r--r-- | js/app/services/models/itemmodel.coffee | 21 | ||||
-rw-r--r-- | js/app/services/newestitem.coffee | 39 | ||||
-rw-r--r-- | js/app/services/persistence.coffee | 15 | ||||
-rw-r--r-- | js/app/services/services.coffee | 5 | ||||
-rw-r--r-- | js/public/app.js | 130 | ||||
-rw-r--r-- | js/tests/controllers/itemcontrollerSpec.coffee | 18 | ||||
-rw-r--r-- | js/tests/services/businesslayer/feedbusinesslayerSpec.coffee | 6 | ||||
-rw-r--r-- | js/tests/services/businesslayer/itembusinesslayerSpec.coffee | 6 | ||||
-rw-r--r-- | js/tests/services/models/itemmodelSpec.coffee | 9 | ||||
-rw-r--r-- | js/tests/services/newestitemSpec.coffee | 39 | ||||
-rw-r--r-- | js/tests/services/persistenceSpec.coffee | 27 |
14 files changed, 199 insertions, 144 deletions
diff --git a/js/app/services/businesslayer/businesslayer.coffee b/js/app/services/businesslayer/businesslayer.coffee index 3096eb71e..622351333 100644 --- a/js/app/services/businesslayer/businesslayer.coffee +++ b/js/app/services/businesslayer/businesslayer.coffee @@ -25,7 +25,7 @@ angular.module('News').factory '_BusinessLayer', -> class BusinessLayer - constructor: (@_activeFeed, @_persistence, @_itemModel, @_type) -> + constructor: (@_activeFeed, @_persistence, @_itemModel, @_type, @_newest) -> load: (id) -> diff --git a/js/app/services/businesslayer/feedbusinesslayer.coffee b/js/app/services/businesslayer/feedbusinesslayer.coffee index 9a23bec43..804b68423 100644 --- a/js/app/services/businesslayer/feedbusinesslayer.coffee +++ b/js/app/services/businesslayer/feedbusinesslayer.coffee @@ -24,15 +24,15 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. angular.module('News').factory 'FeedBusinessLayer', ['_BusinessLayer', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewLoading', '_ExistsError', 'Utils', '$rootScope', -'UndoQueue', +'UndoQueue', 'NewestItem', (_BusinessLayer, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, -FeedModel, NewLoading, _ExistsError, Utils, $rootScope, UndoQueue) -> +FeedModel, NewLoading, _ExistsError, Utils, $rootScope, UndoQueue, NewestItem) -> class FeedBusinessLayer extends _BusinessLayer constructor: (@_showAll, @_feedModel, persistence, activeFeed, feedType, itemModel, @_newLoading, @_utils, @_$rootScope, - @_undoQueue) -> + @_undoQueue, @_newestItem) -> super(activeFeed, persistence, itemModel, feedType.Feed) @_feedType = feedType @@ -70,7 +70,7 @@ FeedModel, NewLoading, _ExistsError, Utils, $rootScope, UndoQueue) -> feed.unreadCount = 0 if @_activeFeed.getId() == feedId and @_activeFeed.getType() == @_feedType.Feed - highestItemId = @_itemModel.getHighestId() + highestItemId = @_newestItem.getId() else highestItemId = 0 @_persistence.setFeedRead(feedId, highestItemId) @@ -198,6 +198,6 @@ FeedModel, NewLoading, _ExistsError, Utils, $rootScope, UndoQueue) -> return new FeedBusinessLayer(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel, NewLoading, Utils, - $rootScope, UndoQueue) + $rootScope, UndoQueue, NewestItem) ]
\ No newline at end of file diff --git a/js/app/services/businesslayer/itembusinesslayer.coffee b/js/app/services/businesslayer/itembusinesslayer.coffee index 99a400385..6d12661ff 100644 --- a/js/app/services/businesslayer/itembusinesslayer.coffee +++ b/js/app/services/businesslayer/itembusinesslayer.coffee @@ -23,14 +23,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. angular.module('News').factory 'ItemBusinessLayer', ['ItemModel', 'FeedModel', 'Persistence', 'ActiveFeed', 'FeedType', -'StarredBusinessLayer', +'StarredBusinessLayer', 'NewestItem', (ItemModel, FeedModel, Persistence, ActiveFeed, FeedType, -StarredBusinessLayer) -> +StarredBusinessLayer, NewestItem) -> class ItemBusinessLayer constructor: (@_itemModel, @_feedModel, @_persistence, @_activeFeed, - @_feedType, @_starredBusinessLayer) -> + @_feedType, @_starredBusinessLayer, @_newestItem) -> getAll: -> return @_itemModel.getAll() @@ -106,10 +106,12 @@ StarredBusinessLayer) -> loadNext: (callback) -> - lowestItemId = @_itemModel.getLowestId() - if lowestItemId != 0 + size = @_itemModel.size() + if size != 0 @_persistence.getItems @_activeFeed.getType(), - @_activeFeed.getId(), lowestItemId, + @_activeFeed.getId(), + size, + @_newestItem.getId(), callback else callback() @@ -121,6 +123,6 @@ StarredBusinessLayer) -> return new ItemBusinessLayer(ItemModel, FeedModel, Persistence, ActiveFeed, - FeedType, StarredBusinessLayer) + FeedType, StarredBusinessLayer, NewestItem) ]
\ No newline at end of file diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee index 1b03d65f8..12f557421 100644 --- a/js/app/services/models/itemmodel.coffee +++ b/js/app/services/models/itemmodel.coffee @@ -99,26 +99,5 @@ angular.module('News').factory 'ItemModel', super(id) - getHighestId: -> - query = new _MaximumQuery('id') - highestId = @get(query) - - if angular.isDefined(highestId) - return highestId.id - else - return 0 - - - getLowestId: -> - query = new _MinimumQuery('id') - lowestId = @get(query) - - if angular.isDefined(lowestId) - return lowestId.id - else - return 0 - - - return new ItemModel() ]
\ No newline at end of file diff --git a/js/app/services/newestitem.coffee b/js/app/services/newestitem.coffee new file mode 100644 index 000000000..3afa9b079 --- /dev/null +++ b/js/app/services/newestitem.coffee @@ -0,0 +1,39 @@ +### + +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/>. + +### + +angular.module('News').factory 'NewestItem', -> + + class NewestItem + + constructor: -> + @_id = 0 + + + handle: (data) -> + @_id = data + + + getId: -> + return @_id + + + return new NewestItem() diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee index 188f5a7c7..8eea196db 100644 --- a/js/app/services/persistence.coffee +++ b/js/app/services/persistence.coffee @@ -51,7 +51,7 @@ $rootScope) -> ### ITEM CONTROLLER ### - getItems: (type, id, offset, onSuccess=null, updatedSince=null) -> + getItems: (type, id, offset, newestItemId=0, onSuccess=null) -> onSuccess or= -> # show different loading signs @@ -68,20 +68,13 @@ $rootScope) -> failureCallbackWrapper = (data) => loading.decrease() - if updatedSince != null - data = - updatedSince: updatedSince - type: type - id: id - else - data = + params = + data: limit: @_config.itemBatchSize offset: offset id: id type: type - - params = - data: data + newestItemId: newestItemId onSuccess: successCallbackWrapper onFailure: failureCallbackWrapper diff --git a/js/app/services/services.coffee b/js/app/services/services.coffee index 537a4492c..fa600b517 100644 --- a/js/app/services/services.coffee +++ b/js/app/services/services.coffee @@ -45,9 +45,9 @@ angular.module('News').factory 'NewLoading', ['_Loading', (_Loading) -> angular.module('News').factory 'Publisher', ['_Publisher', 'ActiveFeed', 'ShowAll', 'StarredCount', 'ItemModel', -'FolderModel', 'FeedModel', 'Language', +'FolderModel', 'FeedModel', 'Language', 'NewestItem', (_Publisher, ActiveFeed, ShowAll, StarredCount, ItemModel, -FolderModel, FeedModel, Language) -> +FolderModel, FeedModel, Language, NewestItem) -> # register items at publisher to automatically add incoming items publisher = new _Publisher() @@ -58,6 +58,7 @@ FolderModel, FeedModel, Language) -> publisher.subscribeObjectTo(FolderModel, 'folders') publisher.subscribeObjectTo(FeedModel, 'feeds') publisher.subscribeObjectTo(ItemModel, 'items') + publisher.subscribeObjectTo(NewestItem, 'newestItemId') return publisher ] diff --git a/js/public/app.js b/js/public/app.js index 01bb7cbae..80a678995 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -741,11 +741,12 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. var BusinessLayer; BusinessLayer = (function() { - function BusinessLayer(_activeFeed, _persistence, _itemModel, _type) { + function BusinessLayer(_activeFeed, _persistence, _itemModel, _type, _newest) { this._activeFeed = _activeFeed; this._persistence = _persistence; this._itemModel = _itemModel; this._type = _type; + this._newest = _newest; } BusinessLayer.prototype.load = function(id) { @@ -797,19 +798,20 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; angular.module('News').factory('FeedBusinessLayer', [ - '_BusinessLayer', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewLoading', '_ExistsError', 'Utils', '$rootScope', 'UndoQueue', function(_BusinessLayer, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, NewLoading, _ExistsError, Utils, $rootScope, UndoQueue) { + '_BusinessLayer', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewLoading', '_ExistsError', 'Utils', '$rootScope', 'UndoQueue', 'NewestItem', function(_BusinessLayer, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, NewLoading, _ExistsError, Utils, $rootScope, UndoQueue, NewestItem) { var FeedBusinessLayer; FeedBusinessLayer = (function(_super) { __extends(FeedBusinessLayer, _super); - function FeedBusinessLayer(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading, _utils, _$rootScope, _undoQueue) { + function FeedBusinessLayer(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading, _utils, _$rootScope, _undoQueue, _newestItem) { this._showAll = _showAll; this._feedModel = _feedModel; this._newLoading = _newLoading; this._utils = _utils; this._$rootScope = _$rootScope; this._undoQueue = _undoQueue; + this._newestItem = _newestItem; FeedBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Feed); this._feedType = feedType; } @@ -851,7 +853,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. if (angular.isDefined(feed)) { feed.unreadCount = 0; if (this._activeFeed.getId() === feedId && this._activeFeed.getType() === this._feedType.Feed) { - highestItemId = this._itemModel.getHighestId(); + highestItemId = this._newestItem.getId(); } else { highestItemId = 0; } @@ -1016,7 +1018,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. return FeedBusinessLayer; })(_BusinessLayer); - return new FeedBusinessLayer(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel, NewLoading, Utils, $rootScope, UndoQueue); + return new FeedBusinessLayer(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel, NewLoading, Utils, $rootScope, UndoQueue, NewestItem); } ]); @@ -1281,17 +1283,18 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. (function() { angular.module('News').factory('ItemBusinessLayer', [ - 'ItemModel', 'FeedModel', 'Persistence', 'ActiveFeed', 'FeedType', 'StarredBusinessLayer', function(ItemModel, FeedModel, Persistence, ActiveFeed, FeedType, StarredBusinessLayer) { + 'ItemModel', 'FeedModel', 'Persistence', 'ActiveFeed', 'FeedType', 'StarredBusinessLayer', 'NewestItem', function(ItemModel, FeedModel, Persistence, ActiveFeed, FeedType, StarredBusinessLayer, NewestItem) { var ItemBusinessLayer; ItemBusinessLayer = (function() { - function ItemBusinessLayer(_itemModel, _feedModel, _persistence, _activeFeed, _feedType, _starredBusinessLayer) { + function ItemBusinessLayer(_itemModel, _feedModel, _persistence, _activeFeed, _feedType, _starredBusinessLayer, _newestItem) { this._itemModel = _itemModel; this._feedModel = _feedModel; this._persistence = _persistence; this._activeFeed = _activeFeed; this._feedType = _feedType; this._starredBusinessLayer = _starredBusinessLayer; + this._newestItem = _newestItem; } ItemBusinessLayer.prototype.getAll = function() { @@ -1387,11 +1390,11 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. }; ItemBusinessLayer.prototype.loadNext = function(callback) { - var lowestItemId; + var size; - lowestItemId = this._itemModel.getLowestId(); - if (lowestItemId !== 0) { - return this._persistence.getItems(this._activeFeed.getType(), this._activeFeed.getId(), lowestItemId, callback); + size = this._itemModel.size(); + if (size !== 0) { + return this._persistence.getItems(this._activeFeed.getType(), this._activeFeed.getId(), size, this._newestItem.getId(), callback); } else { return callback(); } @@ -1402,7 +1405,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. return ItemBusinessLayer; })(); - return new ItemBusinessLayer(ItemModel, FeedModel, Persistence, ActiveFeed, FeedType, StarredBusinessLayer); + return new ItemBusinessLayer(ItemModel, FeedModel, Persistence, ActiveFeed, FeedType, StarredBusinessLayer, NewestItem); } ]); @@ -2179,30 +2182,6 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. return ItemModel.__super__.removeById.call(this, id); }; - ItemModel.prototype.getHighestId = function() { - var highestId, query; - - query = new _MaximumQuery('id'); - highestId = this.get(query); - if (angular.isDefined(highestId)) { - return highestId.id; - } else { - return 0; - } - }; - - ItemModel.prototype.getLowestId = function() { - var lowestId, query; - - query = new _MinimumQuery('id'); - lowestId = this.get(query); - if (angular.isDefined(lowestId)) { - return lowestId.id; - } else { - return 0; - } - }; - return ItemModel; })(_Model); @@ -2236,6 +2215,54 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. (function() { + angular.module('News').factory('NewestItem', function() { + var NewestItem; + + NewestItem = (function() { + function NewestItem() { + this._id = 0; + } + + NewestItem.prototype.handle = function(data) { + return this._id = data; + }; + + NewestItem.prototype.getId = function() { + return this._id; + }; + + return NewestItem; + + })(); + return new NewestItem(); + }); + +}).call(this); + +// Generated by CoffeeScript 1.6.2 +/* + +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/>. +*/ + + +(function() { angular.module('News').factory('OPMLParser', function() { var Feed, Folder, OPMLParser; @@ -2387,16 +2414,16 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. */ - Persistence.prototype.getItems = function(type, id, offset, onSuccess, updatedSince) { - var data, failureCallbackWrapper, loading, params, successCallbackWrapper, + Persistence.prototype.getItems = function(type, id, offset, newestItemId, onSuccess) { + var failureCallbackWrapper, loading, params, successCallbackWrapper, _this = this; + if (newestItemId == null) { + newestItemId = 0; + } if (onSuccess == null) { onSuccess = null; } - if (updatedSince == null) { - updatedSince = null; - } onSuccess || (onSuccess = function() {}); if (offset === 0) { loading = this._feedLoading; @@ -2411,22 +2438,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. failureCallbackWrapper = function(data) { return loading.decrease(); }; - if (updatedSince !== null) { - data = { - updatedSince: updatedSince, - type: type, - id: id - }; - } else { - data = { + params = { + data: { limit: this._config.itemBatchSize, offset: offset, id: id, - type: type - }; - } - params = { - data: data, + type: type, + newestItemId: newestItemId + }, onSuccess: successCallbackWrapper, onFailure: failureCallbackWrapper }; @@ -2933,7 +2952,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ]); angular.module('News').factory('Publisher', [ - '_Publisher', 'ActiveFeed', 'ShowAll', 'StarredCount', 'ItemModel', 'FolderModel', 'FeedModel', 'Language', function(_Publisher, ActiveFeed, ShowAll, StarredCount, ItemModel, FolderModel, FeedModel, Language) { + '_Publisher', 'ActiveFeed', 'ShowAll', 'StarredCount', 'ItemModel', 'FolderModel', 'FeedModel', 'Language', 'NewestItem', function(_Publisher, ActiveFeed, ShowAll, StarredCount, ItemModel, FolderModel, FeedModel, Language, NewestItem) { var publisher; publisher = new _Publisher(); @@ -2944,6 +2963,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. publisher.subscribeObjectTo(FolderModel, 'folders'); publisher.subscribeObjectTo(FeedModel, 'feeds'); publisher.subscribeObjectTo(ItemModel, 'items'); + publisher.subscribeObjectTo(NewestItem, 'newestItemId'); return publisher; } ]); diff --git a/js/tests/controllers/itemcontrollerSpec.coffee b/js/tests/controllers/itemcontrollerSpec.coffee index d700dc89f..3a7e6712a 100644 --- a/js/tests/controllers/itemcontrollerSpec.coffee +++ b/js/tests/controllers/itemcontrollerSpec.coffee @@ -40,7 +40,7 @@ describe 'ItemController', -> beforeEach inject ($controller, @ItemBusinessLayer, @FeedBusinessLayer, $rootScope, @FeedLoading, @AutoPageLoading, @FeedModel, @ItemModel, - @ActiveFeed, @FeedType) => + @ActiveFeed, @FeedType, @NewestItem) => @ActiveFeed.handle({type: @FeedType.Folder, id: 3}) @scope = $rootScope.$new() @@ -101,7 +101,9 @@ describe 'ItemController', -> expect(@persistence.getItems).not.toHaveBeenCalled() - it 'should autoPage with the lowest Item Id', => + it 'should autoPage with the newest Item Id', => + @NewestItem.handle(25) + @persistence.getItems = jasmine.createSpy('getItems') item1 = {id: 4, guidHash: 'abc', feedId: 3} @ItemModel.add(item1) @@ -114,11 +116,12 @@ describe 'ItemController', -> @scope.$broadcast 'autoPage' expect(@persistence.getItems).toHaveBeenCalledWith( - @FeedType.Folder, 3, 3, jasmine.any(Function) + @FeedType.Folder, 3, 3, 25, jasmine.any(Function) ) it 'should not prevent autopaging if there are no items', => + @NewestItem.handle(25) @scope.$broadcast 'autoPage' @persistence.getItems = jasmine.createSpy('getItems') @@ -127,11 +130,12 @@ describe 'ItemController', -> @scope.$broadcast 'autoPage' expect(@persistence.getItems).toHaveBeenCalledWith( - @FeedType.Folder, 3, 3, jasmine.any(Function) + @FeedType.Folder, 3, 1, 25, jasmine.any(Function) ) it 'should not send multiple autopage requests at once', => + @NewestItem.handle(25) @persistence.getItems = jasmine.createSpy('getItems') item1 = {id: 3, guidHash: 'abcd', feedId: 3} @ItemModel.add(item1) @@ -144,13 +148,15 @@ describe 'ItemController', -> @scope.$broadcast 'autoPage' expect(@persistence.getItems).not.toHaveBeenCalledWith( - @FeedType.Folder, 2, 3, jasmine.any(Function) + @FeedType.Folder, 2, 1, 25, jasmine.any(Function) ) it 'should allow another autopaging request if the last one finished', => + @NewestItem.handle(25) @persistence.getItems = jasmine.createSpy('getItems') - @persistence.getItems.andCallFake (type, id, offset, onSuccess) -> + @persistence.getItems.andCallFake (type, id, offset, newestItemId, + onSuccess) -> onSuccess() item1 = {id: 3, guidHash: 'abcd', feedId: 3} diff --git a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee index 833af6da8..1c663d279 100644 --- a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee @@ -44,7 +44,8 @@ describe 'FeedBusinessLayer', -> beforeEach inject (@FeedBusinessLayer, @FeedModel, @ItemModel, @FeedType, - @ShowAll, @ActiveFeed, @_ExistsError, @$timeout) => + @ShowAll, @ActiveFeed, @_ExistsError, @$timeout, + @NewestItem) => @ShowAll.setShowAll(false) @ActiveFeed.handle({type: @FeedType.Folder, id:0}) @@ -93,6 +94,7 @@ describe 'FeedBusinessLayer', -> it 'should mark feed as read', => + @NewestItem.handle(25) @ActiveFeed.handle({type: @FeedType.Feed, id: 5}) @persistence.setFeedRead = jasmine.createSpy('setFeedRead') @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a1'}) @@ -101,7 +103,7 @@ describe 'FeedBusinessLayer', -> @ItemModel.add({id: 2, feedId: 5, guidHash: 'a3'}) @FeedBusinessLayer.markFeedRead(5) - expect(@persistence.setFeedRead).toHaveBeenCalledWith(5, 6) + expect(@persistence.setFeedRead).toHaveBeenCalledWith(5, 25) expect(@FeedModel.getById(5).unreadCount).toBe(0) expect(@ItemModel.getById(6).isRead()).toBeTruthy() expect(@ItemModel.getById(3).isRead()).toBeTruthy() diff --git a/js/tests/services/businesslayer/itembusinesslayerSpec.coffee b/js/tests/services/businesslayer/itembusinesslayerSpec.coffee index 0b8358f2a..4b8d520ee 100644 --- a/js/tests/services/businesslayer/itembusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/itembusinesslayerSpec.coffee @@ -32,7 +32,8 @@ describe 'ItemBusinessLayer', -> return beforeEach inject (@ItemModel, @ItemBusinessLayer, @StatusFlag, @ActiveFeed - @FeedType, @FeedModel, @StarredBusinessLayer) => + @FeedType, @FeedModel, @StarredBusinessLayer, + @NewestItem) => @item1 = {id: 5, title: 'hi', unreadCount:134, url: 'a3', folderId: 3} @FeedModel.add(@item1) @ActiveFeed.handle({type: @FeedType.Feed, id: 3}) @@ -234,6 +235,7 @@ describe 'ItemBusinessLayer', -> it 'should load the next items', => + @NewestItem.handle(13) @persistence.getItems = jasmine.createSpy('autopage') callback = -> @@ -245,4 +247,4 @@ describe 'ItemBusinessLayer', -> @ItemBusinessLayer.loadNext(callback) expect(@persistence.getItems).toHaveBeenCalledWith( - @FeedType.Feed, 3, 1, jasmine.any(Function)) + @FeedType.Feed, 3, 4, 13, jasmine.any(Function)) diff --git a/js/tests/services/models/itemmodelSpec.coffee b/js/tests/services/models/itemmodelSpec.coffee index 2171f12ea..b4a74d122 100644 --- a/js/tests/services/models/itemmodelSpec.coffee +++ b/js/tests/services/models/itemmodelSpec.coffee @@ -102,12 +102,3 @@ describe 'ItemModel', -> item.setUnstarred() expect(@ItemModel.getById(3).isStarred()).toBe(false) - - - it 'should return the lowest id', => - @ItemModel.add({id: 2, guidHash: 'abc', feedId: 2, status: 16}) - @ItemModel.add({id: 3, guidHash: 'abcd', feedId: 2, status: 16}) - @ItemModel.add({id: 1, guidHash: 'abce', feedId: 2, status: 16}) - @ItemModel.add({id: 6, guidHash: 'abcf', feedId: 2, status: 16}) - - expect(@ItemModel.getLowestId()).toBe(1)
\ No newline at end of file diff --git a/js/tests/services/newestitemSpec.coffee b/js/tests/services/newestitemSpec.coffee new file mode 100644 index 000000000..715ca2079 --- /dev/null +++ b/js/tests/services/newestitemSpec.coffee @@ -0,0 +1,39 @@ +### + +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 'NewestItem', -> + + beforeEach module 'News' + + beforeEach inject (@NewestItem) => + @data = 5 + + + it 'should be 0 by default', => + expect(@NewestItem.getId()).toBe(0) + + + it 'should set the correct feed id', => + @NewestItem.handle(@data) + expect(@NewestItem.getId()).toBe(5) + diff --git a/js/tests/services/persistenceSpec.coffee b/js/tests/services/persistenceSpec.coffee index 90bd82783..91d732c5e 100644 --- a/js/tests/services/persistenceSpec.coffee +++ b/js/tests/services/persistenceSpec.coffee @@ -56,10 +56,12 @@ describe 'Persistence', -> id: 5 limit: @config.itemBatchSize offset: 3 + newestItemId: 4 onSuccess: -> @Persistence.getItems(params.data.type, params.data.id, - params.data.offset, params.onSuccess, null) + params.data.offset, params.data.newestItemId, + params.onSuccess) expected = onSuccess: jasmine.any(Function) @@ -69,28 +71,7 @@ describe 'Persistence', -> id: 5 limit: @config.itemBatchSize offset: 3 - - expect(@req.get).toHaveBeenCalledWith('news_items', expected) - - - it 'should send a load newest items request', => - params = - data: - type: 2 - id: 5 - updatedSince: 1333 - onSuccess: -> - - @Per |