From 8df6d36d49d89f3bb7186b36436606adb039b3f8 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 16 Apr 2013 13:19:28 +0200 Subject: move instantiation into file where object is declared, fix unittests that overwrote services for all unittests and caused them to fail --- js/app/directives/newsitemscroll.coffee | 62 ++ js/app/directives/scrollmarksread.coffee | 62 -- js/app/services/activefeed.coffee | 4 +- .../businesslayer/itembusinesslayer.coffee | 2 +- js/app/services/models/feedmodel.coffee | 10 +- js/app/services/models/foldermodel.coffee | 4 +- js/app/services/models/itemmodel.coffee | 4 +- js/app/services/persistence.coffee | 139 +++- js/app/services/services.coffee | 43 +- js/app/services/showall.coffee | 4 +- js/app/services/starredcount.coffee | 5 +- js/public/app.js | 886 ++++++++++----------- js/tests/controllers/feedcontrollerSpec.coffee | 10 +- js/tests/controllers/itemcontrollerSpec.coffee | 11 +- js/tests/controllers/settingscontrollerSpec.coffee | 5 + .../businesslayer/businesslayerSpec.coffee | 2 +- .../businesslayer/feedbusinesslayerSpec.coffee | 32 +- .../businesslayer/folderbusinesslayerSpec.coffee | 22 +- .../businesslayer/itembusinesslayerSpec.coffee | 10 +- .../businesslayer/starredbusinesslayerSpec.coffee | 11 +- .../subsriptionsbusinesslayerSpec.coffee | 15 +- js/tests/services/models/feedmodelSpec.coffee | 12 +- js/tests/services/persistenceSpec.coffee | 184 +++-- 23 files changed, 776 insertions(+), 763 deletions(-) create mode 100644 js/app/directives/newsitemscroll.coffee delete mode 100644 js/app/directives/scrollmarksread.coffee (limited to 'js') diff --git a/js/app/directives/newsitemscroll.coffee b/js/app/directives/newsitemscroll.coffee new file mode 100644 index 000000000..5e7e42a3e --- /dev/null +++ b/js/app/directives/newsitemscroll.coffee @@ -0,0 +1,62 @@ +### + +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 . + +### + +scrolling = true +markingRead = true + +angular.module('News').directive 'newsItemScroll', ['$rootScope', 'Config', +($rootScope, Config) -> + + return (scope, elm, attr) -> + + elm.bind 'scroll', -> + # prevent from doing to many scroll actions + # the first timeout prevents accidental and too early marking as read + if scrolling + scrolling = false + setTimeout -> + scrolling = true + , Config.ScrollTimeout + + if markingRead + markingRead = false + setTimeout -> + markingRead = true + # only broadcast elements that are not already read + # and that are beyond the top border + $elems = elm.find('.feed_item:not(.read)') + + for feedItem in $elems + offset = $(feedItem).position().top + if offset <= -50 + id = parseInt($(feedItem).data('id'), 10) + #$rootScope.$broadcast 'readItem', id + + else + break + + , Config.MarkReadTimeout + + scope.$apply attr.newsItemScroll + +] + diff --git a/js/app/directives/scrollmarksread.coffee b/js/app/directives/scrollmarksread.coffee deleted file mode 100644 index 854f17923..000000000 --- a/js/app/directives/scrollmarksread.coffee +++ /dev/null @@ -1,62 +0,0 @@ -### - -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 . - -### - -scrolling = true -markingRead = true - -angular.module('News').directive 'scrollMarksRead', ['$rootScope', 'Config', -($rootScope, Config) -> - - return (scope, elm, attr) -> - - elm.bind 'scroll', -> - # prevent from doing to many scroll actions - # the first timeout prevents accidental and too early marking as read - if scrolling - scrolling = false - setTimeout -> - scrolling = true - , Config.ScrollTimeout - - if markingRead - markingRead = false - setTimeout -> - markingRead = true - # only broadcast elements that are not already read - # and that are beyond the top border - $elems = elm.find('.feed_item:not(.read)') - - for feedItem in $elems - offset = $(feedItem).position().top - if offset <= -50 - id = parseInt($(feedItem).data('id'), 10) - $rootScope.$broadcast 'readItem', id - - else - break - - , Config.MarkReadTimeout - - scope.$apply attr.scrollMarksRead - -] - diff --git a/js/app/services/activefeed.coffee b/js/app/services/activefeed.coffee index 8af9f7573..bdd963f78 100644 --- a/js/app/services/activefeed.coffee +++ b/js/app/services/activefeed.coffee @@ -20,7 +20,7 @@ License along with this library. If not, see . ### -angular.module('News').factory '_ActiveFeed', -> +angular.module('News').factory 'ActiveFeed', -> class ActiveFeed @@ -45,4 +45,4 @@ angular.module('News').factory '_ActiveFeed', -> return @_id - return ActiveFeed + return new ActiveFeed() diff --git a/js/app/services/businesslayer/itembusinesslayer.coffee b/js/app/services/businesslayer/itembusinesslayer.coffee index 7f8d4fba6..b93f9035d 100644 --- a/js/app/services/businesslayer/itembusinesslayer.coffee +++ b/js/app/services/businesslayer/itembusinesslayer.coffee @@ -73,7 +73,7 @@ StarredBusinessLayer) -> item = @_itemModel.getById(itemId) if angular.isDefined(item) - keptUnread = angular.isDefined(item.keptUnread) and + keptUnread = angular.isDefined(item.keptUnread) and item.keptUnread if not (item.isRead() or keptUnread) diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee index e0006e8d2..fb0ba8e14 100644 --- a/js/app/services/models/feedmodel.coffee +++ b/js/app/services/models/feedmodel.coffee @@ -20,10 +20,9 @@ License along with this library. If not, see . ### - -angular.module('News').factory '_FeedModel', -['_Model', '_EqualQuery', -(_Model, _EqualQuery) -> +angular.module('News').factory 'FeedModel', +['_Model', '_EqualQuery', 'Utils', +(_Model, _EqualQuery, Utils) -> class FeedModel extends _Model @@ -166,5 +165,6 @@ angular.module('News').factory '_FeedModel', @_invalidateCache() break - return FeedModel + + return new FeedModel(Utils) ] \ No newline at end of file diff --git a/js/app/services/models/foldermodel.coffee b/js/app/services/models/foldermodel.coffee index 5dad0bdae..b724ad044 100644 --- a/js/app/services/models/foldermodel.coffee +++ b/js/app/services/models/foldermodel.coffee @@ -20,7 +20,7 @@ License along with this library. If not, see . ### -angular.module('News').factory '_FolderModel', +angular.module('News').factory 'FolderModel', ['_Model', '_EqualQuery', (_Model, _EqualQuery) -> class FolderModel extends _Model @@ -138,5 +138,5 @@ angular.module('News').factory '_FolderModel', break - return FolderModel + return new FolderModel() ] \ No newline at end of file diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee index 61030b50e..70b3a9f5c 100644 --- a/js/app/services/models/itemmodel.coffee +++ b/js/app/services/models/itemmodel.coffee @@ -20,7 +20,7 @@ License along with this library. If not, see . ### -angular.module('News').factory '_ItemModel', +angular.module('News').factory 'ItemModel', ['_Model', '_MaximumQuery', '_MinimumQuery', 'StatusFlag', (_Model, _MaximumQuery, _MinimumQuery, StatusFlag) -> @@ -109,5 +109,5 @@ angular.module('News').factory '_ItemModel', return 0 - return ItemModel + return new ItemModel() ] \ No newline at end of file diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee index 2b627301a..4c4ceb370 100644 --- a/js/app/services/persistence.coffee +++ b/js/app/services/persistence.coffee @@ -20,33 +20,31 @@ License along with this library. If not, see . ### +angular.module('News').factory 'Persistence', +['Request', 'FeedLoading', 'AutoPageLoading', 'NewLoading', 'Config', +'ActiveFeed', '$rootScope', +(Request, FeedLoading, AutoPageLoading, NewLoading, Config, ActiveFeed, +$rootScope) -> -angular.module('News').factory '_Persistence', -> - class Persistence - constructor: (@_request, @_loading, @_config, @_activeFeed, - @_$rootScope) -> + constructor: (@_request, @_feedLoading, @_autoPageLoading, @_newLoading, + @_config, @_activeFeed, @_$rootScope) -> init: -> ### Loads the initial data from the server ### - @_loading.increase() # items can only be loaded after the active feed is known @getActiveFeed => - @getItems @_activeFeed.getType(), @_activeFeed.getId(), 0, => - @_loading.decrease() + @getItems(@_activeFeed.getType(), @_activeFeed.getId()) - triggerHideRead = => - @_triggerHideRead - - @getAllFolders(triggerHideRead) - @getAllFeeds(triggerHideRead) - @userSettingsRead(triggerHideRead) - @getStarredItems(triggerHideRead) + @getAllFolders() + @getAllFeeds() + @userSettingsRead() + @getStarredItems() @userSettingsLanguage() @@ -54,9 +52,22 @@ angular.module('News').factory '_Persistence', -> ITEM CONTROLLER ### getItems: (type, id, offset, onSuccess=null, updatedSince=null) -> - onSuccess or= -> + # show different loading signs + if offset == 0 + loading = @_feedLoading + else + loading = @_autoPageLoading + + # loading sign handling + loading.increase() + successCallbackWrapper = (data) => + onSuccess() + loading.decrease() + failureCallbackWrapper = (data) => + loading.decrease() + if updatedSince != null data = updatedSince: updatedSince @@ -71,14 +82,27 @@ angular.module('News').factory '_Persistence', -> params = data: data - onSuccess: onSuccess + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_items', params getStarredItems: (onSuccess) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: onSuccess + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper + @_request.get 'news_items_starred', params @@ -132,17 +156,36 @@ angular.module('News').factory '_Persistence', -> ### FEED CONTROLLER ### - getAllFeeds: (callback) -> - callback or= -> + getAllFeeds: (onSuccess) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_feeds', params getActiveFeed: (onSuccess) -> + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: onSuccess + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_feeds_active', params @@ -208,10 +251,20 @@ angular.module('News').factory '_Persistence', -> ### FOLDER CONTROLLER ### - getAllFolders: (callback) -> - callback or= -> + getAllFolders: (onSuccess) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_folders', params @@ -292,13 +345,23 @@ angular.module('News').factory '_Persistence', -> ### USERSETTINGS CONTROLLER ### - userSettingsRead: (callback=null) -> + userSettingsRead: (onSuccess=null) -> ### Gets the configs for read settings ### - callback or= -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + params = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper @_request.get 'news_usersettings_read', params @@ -321,10 +384,21 @@ angular.module('News').factory '_Persistence', -> @_request.post 'news_usersettings_read_hide', data - userSettingsLanguage: (callback=null) -> - callback or= -> + userSettingsLanguage: (onSuccess=null) -> + onSuccess or= -> + + # loading sign handling + @_feedLoading.increase() + successCallbackWrapper = (data) => + onSuccess() + @_feedLoading.decrease() + failureCallbackWrapper = (data) => + @_feedLoading.decrease() + data = - onSuccess: callback + onSuccess: successCallbackWrapper + onFailure: failureCallbackWrapper + @_request.get 'news_usersettings_language', data @@ -332,5 +406,8 @@ angular.module('News').factory '_Persistence', -> @_$rootScope.$broadcast('triggerHideRead') - return Persistence + return new Persistence(Request, FeedLoading, AutoPageLoading, NewLoading, + Config, ActiveFeed, $rootScope) + +] diff --git a/js/app/services/services.coffee b/js/app/services/services.coffee index d67e1d2c5..537a4492c 100644 --- a/js/app/services/services.coffee +++ b/js/app/services/services.coffee @@ -22,12 +22,6 @@ License along with this library. If not, see . # request related stuff -angular.module('News').factory 'Persistence', ['_Persistence', 'Request', -'FeedLoading', 'Config', 'ActiveFeed', '$rootScope', -(_Persistence, Request, FeedLoading, Config, ActiveFeed, $rootScope) -> - return new _Persistence(Request, FeedLoading, Config, ActiveFeed, $rootScope) -] - angular.module('News').factory 'Request', ['_Request', '$http', 'Publisher', 'Router', (_Request, $http, Publisher, Router) -> @@ -36,49 +30,18 @@ angular.module('News').factory 'Request', # loading helpers -angular.module('News').factory 'FeedLoading', -['_Loading', (_Loading) -> +angular.module('News').factory 'FeedLoading', ['_Loading', (_Loading) -> return new _Loading() ] -angular.module('News').factory 'AutoPageLoading', -['_Loading', (_Loading) -> +angular.module('News').factory 'AutoPageLoading', ['_Loading', (_Loading) -> return new _Loading() ] -angular.module('News').factory 'NewLoading', -['_Loading', (_Loading) -> +angular.module('News').factory 'NewLoading', ['_Loading', (_Loading) -> return new _Loading() ] -# models -angular.module('News').factory 'ActiveFeed', ['_ActiveFeed', (_ActiveFeed) -> - return new _ActiveFeed() -] - -angular.module('News').factory 'ShowAll', ['_ShowAll', (_ShowAll) -> - return new _ShowAll() -] - -angular.module('News').factory 'StarredCount', ['_StarredCount', -(_StarredCount) -> - return new _StarredCount() -] - -angular.module('News').factory 'FeedModel', ['_FeedModel', 'Utils', -(_FeedModel, Utils) -> - return new _FeedModel(Utils) -] - -angular.module('News').factory 'FolderModel', -['_FolderModel', (_FolderModel) -> - return new _FolderModel() -] - -angular.module('News').factory 'ItemModel', ['_ItemModel', (_ItemModel) -> - return new _ItemModel() -] - angular.module('News').factory 'Publisher', ['_Publisher', 'ActiveFeed', 'ShowAll', 'StarredCount', 'ItemModel', diff --git a/js/app/services/showall.coffee b/js/app/services/showall.coffee index a40f176bc..1d12864c6 100644 --- a/js/app/services/showall.coffee +++ b/js/app/services/showall.coffee @@ -21,7 +21,7 @@ License along with this library. If not, see . ### -angular.module('News').factory '_ShowAll', -> +angular.module('News').factory 'ShowAll', -> class ShowAll @@ -41,4 +41,4 @@ angular.module('News').factory '_ShowAll', -> @_showAll = showAll - return ShowAll + return new ShowAll() diff --git a/js/app/services/starredcount.coffee b/js/app/services/starredcount.coffee index 9d3d9deb5..1157b4748 100644 --- a/js/app/services/starredcount.coffee +++ b/js/app/services/starredcount.coffee @@ -21,7 +21,7 @@ License along with this library. If not, see . ### -angular.module('News').factory '_StarredCount', -> +angular.module('News').factory 'StarredCount', -> class StarredCount @@ -41,5 +41,4 @@ angular.module('News').factory '_StarredCount', -> return @_count - - return StarredCount + return new StarredCount() diff --git a/js/public/app.js b/js/public/app.js index c76a338ee..ab3c73783 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -66,46 +66,6 @@ License along with this library. If not, see . }).call(this); -// Generated by CoffeeScript 1.4.0 - -/* - -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 . -*/ - - -(function() { - - angular.module('News').directive('clickFocus', function() { - return function(scope, elm, attr) { - var options; - options = scope.$eval(attr.clickFocus); - if (angular.isDefined(options) && angular.isDefined(options.selector)) { - return elm.click(function() { - return $(options.selector).focus(); - }); - } - }; - }); - -}).call(this); - // Generated by CoffeeScript 1.6.2 /* @@ -159,40 +119,6 @@ License along with this library. If not, see . }).call(this); -// Generated by CoffeeScript 1.4.0 - -/* - -ownCloud - App Framework - -@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 . -*/ - - -(function() { - - angular.module('OC').directive('focusFirstInput', function() { - return function(scope, elm, attr) { - return elm.find('input:first').focus(); - }; - }); - -}).call(this); - // Generated by CoffeeScript 1.6.2 /* @@ -317,7 +243,7 @@ License along with this library. If not, see . markingRead = true; - angular.module('News').directive('scrollMarksRead', [ + angular.module('News').directive('newsItemScroll', [ '$rootScope', 'Config', function($rootScope, Config) { return function(scope, elm, attr) { return elm.bind('scroll', function() { @@ -338,8 +264,7 @@ License along with this library. If not, see . feedItem = $elems[_i]; offset = $(feedItem).position().top; if (offset <= -50) { - id = parseInt($(feedItem).data('id'), 10); - _results.push($rootScope.$broadcast('readItem', id)); + _results.push(id = parseInt($(feedItem).data('id'), 10)); } else { break; } @@ -347,7 +272,7 @@ License along with this library. If not, see . return _results; }, Config.MarkReadTimeout); } - return scope.$apply(attr.scrollMarksRead); + return scope.$apply(attr.newsItemScroll); } }); }; @@ -627,7 +552,7 @@ License along with this library. If not, see . (function() { - angular.module('News').factory('_ActiveFeed', function() { + angular.module('News').factory('ActiveFeed', function() { var ActiveFeed; ActiveFeed = (function() { @@ -655,7 +580,7 @@ License along with this library. If not, see . return ActiveFeed; })(); - return ActiveFeed; + return new ActiveFeed(); }); }).call(this); @@ -1617,8 +1542,8 @@ License along with this library. If not, see . var __hasProp = {}.hasOwnProperty, __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('_FeedModel', [ - '_Model', '_EqualQuery', function(_Model, _EqualQuery) { + angular.module('News').factory('FeedModel', [ + '_Model', '_EqualQuery', 'Utils', function(_Model, _EqualQuery, Utils) { var FeedModel; FeedModel = (function(_super) { @@ -1788,7 +1713,7 @@ License along with this library. If not, see . return FeedModel; })(_Model); - return FeedModel; + return new FeedModel(Utils); } ]); @@ -1821,7 +1746,7 @@ License along with this library. If not, see . var __hasProp = {}.hasOwnProperty, __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('_FolderModel', [ + angular.module('News').factory('FolderModel', [ '_Model', '_EqualQuery', function(_Model, _EqualQuery) { var FolderModel; @@ -1953,7 +1878,7 @@ License along with this library. If not, see . return FolderModel; })(_Model); - return FolderModel; + return new FolderModel(); } ]); @@ -1986,7 +1911,7 @@ License along with this library. If not, see . var __hasProp = {}.hasOwnProperty, __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('_ItemModel', [ + angular.module('News').factory('ItemModel', [ '_Model', '_MaximumQuery', '_MinimumQuery', 'StatusFlag', function(_Model, _MaximumQuery, _MinimumQuery, StatusFlag) { var ItemModel; @@ -2093,7 +2018,7 @@ License along with this library. If not, see . return ItemModel; })(_Model); - return ItemModel; + return new ItemModel(); } ]); @@ -2237,442 +2162,515 @@ License along with this library. If not, see . (function() { - angular.module('News').factory('_Persistence', function() { - var Persistence; - - Persistence = (function() { - function Persistence(_request, _loading, _config, _activeFeed, _$rootScope) { - this._request = _request; - this._loading = _loading; - this._config = _config; - this._activeFeed = _activeFeed; - this._$rootScope = _$rootScope; - } + angular.module('News').factory('Persistence', [ + 'Request', 'FeedLoading', 'AutoPageLoading', 'NewLoading', 'Config', 'ActiveFeed', '$rootScope', function(Request, FeedLoading, AutoPageLoading, NewLoading, Config, ActiveFeed, $rootScope) { + var Persistence; - Persistence.prototype.init = function() { - /* - Loads the initial data from the server - */ + Persistence = (function() { + function Persistence(_request, _feedLoading, _autoPageLoading, _newLoading, _config, _activeFeed, _$rootScope) { + this._request = _request; + this._feedLoading = _feedLoading; + this._autoPageLoading = _autoPageLoading; + this._newLoading = _newLoading; + this._config = _config; + this._activeFeed = _activeFeed; + this._$rootScope = _$rootScope; + } - var triggerHideRead, - _this = this; + Persistence.prototype.init = function() { + /* + Loads the initial data from the server + */ + + var _this = this; - this._loading.increase(); - this.getActiveFeed(function() { - return _this.getItems(_this._activeFeed.getType(), _this._activeFeed.getId(), 0, function() { - return _this._loading.decrease(); + this.getActiveFeed(function() { + return _this.getItems(_this._activeFeed.getType(), _this._activeFeed.getId()); }); - }); - triggerHideRead = function() { - return _this._triggerHideRead; - }; - this.getAllFolders(triggerHideRead); - this.getAllFeeds(triggerHideRead); - this.userSettingsRead(triggerHideRead); - this.getStarredItems(triggerHideRead); - return this.userSettingsLanguage(); - }; + this.getAllFolders(); + this.getAllFeeds(); + this.userSettingsRead(); + this.getStarredItems(); + return this.userSettingsLanguage(); + }; - /* - ITEM CONTROLLER - */ + /* + ITEM CONTROLLER + */ - Persistence.prototype.getItems = function(type, id, offset, onSuccess, updatedSince) { - var data, params; + Persistence.prototype.getItems = function(type, id, offset, onSuccess, updatedSince) { + var data, failureCallbackWrapper, loading, params, successCallbackWrapper, + _this = this; - if (onSuccess == null) { - onSuccess = null; - } - if (updatedSince == null) { - updatedSince = null; - } - onSuccess || (onSuccess = function() {}); - if (updatedSince !== null) { - data = { - updatedSince: updatedSince, - type: type, - id: id + if (onSuccess == null) { + onSuccess = null; + } + if (updatedSince == null) { + updatedSince = null; + } + onSuccess || (onSuccess = function() {}); + if (offset === 0) { + loading = this._feedLoading; + } else { + loading = this._autoPageLoading; + } + loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return loading.decrease(); }; - } else { - data = { - limit: this._config.itemBatchSize, - offset: offset, - id: id, - type: type + failureCallbackWrapper = function(data) { + return loading.decrease(); }; - } - params = { - data: data, - onSuccess: onSuccess + if (updatedSince !== null) { + data = { + updatedSince: updatedSince, + type: type, + id: id + }; + } else { + data = { + limit: this._config.itemBatchSize, + offset: offset, + id: id, + type: type + }; + } + params = { + data: data, + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('news_items', params); }; - return this._request.get('news_items', params); - }; - Persistence.prototype.getStarredItems = function(onSuccess) { - var params; + Persistence.prototype.getStarredItems = function(onSuccess) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; - params = { - onSuccess: onSuccess + onSuccess || (onSuccess = function() {}); + this._feedLoading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._feedLoading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._feedLoading.decrease(); + }; + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('news_items_starred', params); }; - return this._request.get('news_items_starred', params); - }; - Persistence.prototype.starItem = function(feedId, guidHash) { - /* - Stars an item - */ + Persistence.prototype.starItem = function(feedId, guidHash) { + /* + Stars an item + */ - var params; + var params; - params = { - routeParams: { - feedId: feedId, - guidHash: guidHash - } + params = { + routeParams: { + feedId: feedId, + guidHash: guidHash + } + }; + return this._request.post('news_items_star', params); }; - return this._request.post('news_items_star', params); - }; - Persistence.prototype.unstarItem = function(feedId, guidHash) { - /* - Unstars an item - */ + Persistence.prototype.unstarItem = function(feedId, guidHash) { + /* + Unstars an item + */ - var params; + var params; - params = { - routeParams: { - feedId: feedId, - guidHash: guidHash - } + params = { + routeParams: { + feedId: feedId, + guidHash: guidHash + } + }; + return this._request.post('news_items_unstar', params); }; - return this._request.post('news_items_unstar', params); - }; - Persistence.prototype.readItem = function(itemId) { - /* - Sets an item as read - */ + Persistence.prototype.readItem = function(itemId) { + /* + Sets an item as read + */ - var params; + var params; - params = { - routeParams: { - itemId: itemId - } + params = { + routeParams: { + itemId: itemId + } + }; + return this._request.post('news_items_read', params); }; - return this._request.post('news_items_read', params); - }; - Persistence.prototype.unreadItem = function(itemId) { - /* - Sets an item as unread - */ + Persistence.prototype.unreadItem = function(itemId) { + /* + Sets an item as unread + */ - var params; + var params; - params = { - routeParams: { - itemId: itemId - } + params = { + routeParams: { + itemId: itemId + } + }; + return this._request.post('news_items_unread', params); }; - return this._request.post('news_items_unread', params); - }; - /* - FEED CONTROLLER - */ + /* + FEED CONTROLLER + */ - Persistence.prototype.getAllFeeds = function(callback) { - var params; + Persistence.prototype.getAllFeeds = function(onSuccess) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; - callback || (callback = function() {}); - params = { - onSuccess: callback + onSuccess || (onSuccess = function() {}); + this._feedLoading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._feedLoading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._feedLoading.decrease(); + }; + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('news_feeds', params); }; - return this._request.get('news_feeds', params); - }; - Persistence.prototype.getActiveFeed = function(onSuccess) { - var params; + Persistence.prototype.getActiveFeed = function(onSuccess) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; - params = { - onSuccess: onSuccess + this._feedLoading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._feedLoading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._feedLoading.decrease(); + }; + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('news_feeds_active', params); }; - return this._request.get('news_feeds_active', params); - }; - - Persistence.prototype.createFeed = function(url, parentFolderId, onSuccess, onFailure) { - var params; - - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - onSuccess || (onSuccess = function() {}); - onFailure || (onFailure = function() {}); - params = { - data: { - parentFolderId: parentFolderId, - url: url - }, - onSuccess: onSuccess, - onFailure: onFailure - }; - return this._request.post('news_feeds_create', params); - }; - Persistence.prototype.deleteFeed = function(feedId) { - var params; + Persistence.prototype.createFeed = function(url, parentFolderId, onSuccess, onFailure) { + var params; - params = { - routeParams: { - feedId: feedId + if (onSuccess == null) { + onSuccess = null; } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + params = { + data: { + parentFolderId: parentFolderId, + url: url + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('news_feeds_create', params); }; - return this._request.post('news_feeds_delete', params); - }; - Persistence.prototype.moveFeed = function(feedId, folderId) { - /* - moves a feed to a new folder - */ - - var params; + Persistence.prototype.deleteFeed = function(feedId) { + var params; - params = { - routeParams: { - feedId: feedId - }, - data: { - parentFolderId: folderId - } + params = { + routeParams: { + feedId: feedId + } + }; + return this._request.post('news_feeds_delete', params); }; - return this._request.post('news_feeds_move', params); - }; - Persistence.prototype.setFeedRead = function(feedId, highestItemId) { - /* - sets all items of a feed as read - */ + Persistence.prototype.moveFeed = function(feedId, folderId) { + /* + moves a feed to a new folder + */ - var params; + var params; - params = { - routeParams: { - feedId: feedId - }, - data: { - highestItemId: highestItemId - } + params = { + routeParams: { + feedId: feedId + }, + data: { + parentFolderId: folderId + } + }; + return this._request.post('news_feeds_move', params); }; - return this._request.post('news_feeds_read', params); - }; - Persistence.prototype.updateFeed = function(feedId) { - /* - moves a feed to a new folder - */ + Persistence.prototype.setFeedRead = function(feedId, highestItemId) { + /* + sets all items of a feed as read + */ - var params; + var params; - params = { - routeParams: { - feedId: feedId - } + params = { + routeParams: { + feedId: feedId + }, + data: { + highestItemId: highestItemId + } + }; + return this._request.post('news_feeds_read', params); }; - return this._request.post('news_feeds_update', params); - }; - - /* - FOLDER CONTROLLER - */ + Persistence.prototype.updateFeed = function(feedId) { + /* + moves a feed to a new folder + */ - Persistence.prototype.getAllFolders = function(callback) { - var params; + var params; - callback || (callback = function() {}); - params = { - onSuccess: callback + params = { + routeParams: { + feedId: feedId + } + }; + return this._request.post('news_feeds_update', params); }; - return this._request.get('news_folders', params); - }; - Persistence.prototype.openFolder = function(folderId) { /* - Save if a folder was opened + FOLDER CONTROLLER */ - var params; - params = { - routeParams: { - folderId: folderId - } + Persistence.prototype.getAllFolders = function(onSuccess) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + + onSuccess || (onSuccess = function() {}); + this._feedLoading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._feedLoading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._feedLoading.decrease(); + }; + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('news_folders', params); }; - return this._request.post('news_folders_open', params); - }; - Persistence.prototype.collapseFolder = function(folderId) { - /* - Save if a folder was collapsed - */ + Persistence.prototype.openFolder = function(folderId) { + /* + Save if a folder was opened + */ - var params; + var params; - params = { - routeParams: { - folderId: folderId - } + params = { + routeParams: { + folderId: folderId + } + }; + return this._request.post('news_folders_open', params); }; - return this._request.post('news_folders_collapse', params); - }; - Persistence.prototype.createFolder = function(folderName, parentFolderId, onSuccess, onFailure) { - var params; + Persistence.prototype.collapseFolder = function(folderId) { + /* + Save if a folder was collapsed + */ - if (parentFolderId == null) { - parentFolderId = 0; - } - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - onSuccess || (onSuccess = function() {}); - onFailure || (onFailure = function() {}); - params = { - data: { - folderName: folderName, - parentFolderId: parentFolderId - }, - onSuccess: onSuccess, - onFailure: onFailure - }; - return this._request.post('news_folders_create', params); - }; + var params; - Persistence.prototype.deleteFolder = function(folderId) { - /* - Save if a folder was collapsed - */ + params = { + routeParams: { + folderId: folderId + } + }; + return this._request.post('news_folders_collapse', params); + }; - var params; + Persistence.prototype.createFolder = function(folderName, parentFolderId, onSuccess, onFailure) { + var params; - params = { - routeParams: { - folderId: folderId + if (parentFolderId == null) { + parentFolderId = 0; } + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + params = { + data: { + folderName: folderName, + parentFolderId: parentFolderId + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('news_folders_create', params); }; - return this._request.post('news_folders_delete', params); - }; - Persistence.prototype.renameFolder = function(folderId, folderName) { - /* - Save if a folder was collapsed - */ + Persistence.prototype.deleteFolder = function(folderId) { + /* + Save if a folder was collapsed + */ - var params; + var params; - params = { - routeParams: { - folderId: folderId - }, - data: { - folderName: folderName - } + params = { + routeParams: { + folderId: folderId + } + }; + return this._request.post('news_folders_delete', params); }; - return this._request.post('news_folders_rename', params); - }; - /* - EXPORT CONTROLLER - */ + Persistence.prototype.renameFolder = function(folderId, folderName) { + /* + Save if a folder was collapsed + */ + + var params; + params = { + routeParams: { + folderId: folderId + }, + data: { + folderName: folderName + } + }; + return this._request.post('news_folders_rename', params); + }; - Persistence.prototype.exportOPML = function() { /* - Prompts for an OPML download + EXPORT CONTROLLER */ - return this._request.get('news_export_opml'); - }; - - /* - USERSETTINGS CONTROLLER - */ - Persistence.prototype.userSettingsRead = function(callback) { - var params; + Persistence.prototype.exportOPML = function() { + /* + Prompts for an OPML download + */ + return this._request.get('news_export_opml'); + }; - if (callback == null) { - callback = null; - } /* - Gets the configs for read settings + USERSETTINGS CONTROLLER */ - callback || (callback = function() {}); - params = { - onSuccess: callback + + Persistence.prototype.userSettingsRead = function(onSuccess) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + + if (onSuccess == null) { + onSuccess = null; + } + /* + Gets the configs for read settings + */ + + onSuccess || (onSuccess = function() {}); + this._feedLoading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._feedLoading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._feedLoading.decrease(); + }; + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('news_usersettings_read', params); }; - return this._request.get('news_usersettings_read', params); - }; - Persistence.prototype.userSettingsReadShow = function(callback) { - /* - Sets the reader mode to show all - */ + Persistence.prototype.userSettingsReadShow = function(callback) { + /* + Sets the reader mode to show all + */ - var data; + var data; - data = { - onSuccess: callback + data = { + onSuccess: callback + }; + return this._request.post('news_usersettings_read_show', data); }; - return this._request.post('news_usersettings_read_show', data); - }; - Persistence.prototype.userSettingsReadHide = function(callback) { - /* - Sets the reader mode to show only unread - */ + Persistence.prototype.userSettingsReadHide = function(callback) { + /* + Sets the reader mode to show only unread + */ - var data; + var data; - data = { - onSuccess: callback + data = { + onSuccess: callback + }; + return this._request.post('news_usersettings_read_hide', data); }; - return this._request.post('news_usersettings_read_hide', data); - }; - Persistence.prototype.userSettingsLanguage = function(callback) { - var data; + Persistence.prototype.userSettingsLanguage = function(onSuccess) { + var data, failureCallbackWrapper, successCallbackWrapper, + _this = this; - if (callback == null) { - callback = null; - } - callback || (callback = function() {}); - data = { - onSuccess: callback + if (onSuccess == null) { + onSuccess = null; + } + onSuccess || (onSuccess = function() {}); + this._feedLoading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._feedLoading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._feedLoading.decrease(); + }; + data = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('news_usersettings_language', data); }; - return this._request.get('news_usersettings_language', data); - }; - Persistence.prototype._triggerHideRead = function() { - return this._$rootScope.$broadcast('triggerHideRead'); - }; + Persistence.prototype._triggerHideRead = function() { + return this._$rootScope.$broadcast('triggerHideRead'); + }; - return Persistence; + return Persistence; - })(); - return Persistence; - }); + })(); + return new Persistence(Request, FeedLoading, AutoPageLoading, NewLoading, Config, ActiveFeed, $rootScope); + } + ]); }).call(this); @@ -2700,12 +2698,6 @@ License along with this library. If not, see . (function() { - angular.module('News').factory('Persistence', [ - '_Persistence', 'Request', 'FeedLoading', 'Config', 'ActiveFeed', '$rootScope', function(_Persistence, Request, FeedLoading, Config, ActiveFeed, $rootScope) { - return new _Persistence(Request, FeedLoading, Config, ActiveFeed, $rootScope); - } - ]); - angular.module('News').factory('Request', [ '_Request', '$http', 'Publisher', 'Router', function(_Request, $http, Publisher, Router) { return new _Request($http, Publisher, Router); @@ -2730,42 +2722,6 @@ License along with this library. If not, see . } ]); - angular.module('News').factory('ActiveFeed', [ - '_ActiveFeed', function(_ActiveFeed) { - return new _ActiveFeed(); - } - ]); - - angular.module('News').factory('ShowAll', [ - '_ShowAll', function(_ShowAll) { - return new _ShowAll(); - } - ]); - - angular.module('News').factory('StarredCount', [ - '_StarredCount', function(_StarredCount) { - return new _StarredCount(); - } - ]); - - angular.module('News').factory('FeedModel', [ - '_FeedModel', 'Utils', function(_FeedModel, Utils) { - return new _FeedModel(Utils); - } - ]); - - angular.module('News').factory('FolderModel', [ - '_FolderModel', function(_FolderModel) { - return new _FolderModel(); - } - ]); - - angular.module('News').factory('ItemModel', [ - '_ItemModel', function(_ItemModel) { - return new _ItemModel(); - } - ]); - angular.module('News').factory('Publisher', [ '_Publisher', 'ActiveFeed', 'ShowAll', 'StarredCount', 'ItemModel', 'FolderModel', 'FeedModel', 'Language', function(_Publisher, ActiveFeed, ShowAll, StarredCount, ItemModel, FolderModel, FeedModel, Language) { var publisher; @@ -2808,7 +2764,7 @@ License along with this library. If not, see . (function() { - angular.module('News').factory('_ShowAll', function() { + angular.module('News').factory('ShowAll', function() { var ShowAll; ShowAll = (function() { @@ -2831,7 +2787,7 @@ License along with this library. If not, see . return ShowAll; })(); - return ShowAll; + return new ShowAll(); }); }).call(this); @@ -2860,7 +2816,7 @@ License along with this library. If not, see . (function() { - angular.module('News').factory('_StarredCount', function() { + angular.module('News').factory('StarredCount', function() { var StarredCount; StarredCount = (function() { @@ -2883,7 +2839,7 @@ License along with this library. If not, see . return StarredCount; })(); - return StarredCount; + return new StarredCount(); }); }).call(this); diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee index f28319bdf..133ab57ee 100644 --- a/js/tests/controllers/feedcontrollerSpec.coffee +++ b/js/tests/controllers/feedcontrollerSpec.coffee @@ -25,10 +25,10 @@ describe 'FeedController', -> beforeEach module 'News' - beforeEach => - angular.module('News').factory 'Persistence', => - @persistence = {} - + beforeEach module ($provide) => + @persistence = {} + $provide.value 'Persistence', @persistence + return beforeEach inject ($controller, @FolderBusinessLayer, @FeedBusinessLayer, $rootScope, @unreadCountFormatter, @@ -36,12 +36,10 @@ describe 'FeedController', -> @scope = $rootScope.$new() replace = $scope: @scope - Persistence: @persistence @controller = $controller('FeedController', replace) - it 'isAddingFolder should return false in the beginning', => expect(@scope.isAddingFolder()).toBeFalsy() diff --git a/js/tests/controllers/itemcontrollerSpec.coffee b/js/tests/controllers/itemcontrollerSpec.coffee index 96e15e292..2316ee509 100644 --- a/js/tests/controllers/itemcontrollerSpec.coffee +++ b/js/tests/controllers/itemcontrollerSpec.coffee @@ -26,16 +26,17 @@ describe 'ItemController', -> beforeEach module 'News' + beforeEach module ($provide) => + @persistence = + getItems: -> + $provide.value 'Persistence', @persistence + return + beforeEach inject ($controller, @ItemBusinessLayer, @FeedBusinessLayer, $rootScope) => @scope = $rootScope.$new() - @persistence = { - getItems: -> - } - replace = $scope: @scope - Persistence: @persistence @controller = $controller('ItemController', replace) diff --git a/js/tests/controllers/settingscontrollerSpec.coffee b/js/tests/controllers/settingscontrollerSpec.coffee index ded9232e2..88e16c969 100644 --- a/js/tests/controllers/settingscontrollerSpec.coffee +++ b/js/tests/controllers/settingscontrollerSpec.coffee @@ -25,6 +25,11 @@ describe 'SettingsController', -> beforeEach module 'News' + beforeEach module ($provide) => + @persistence = {} + $provide.value 'Persistence', @persistence + return + beforeEach inject ($controller, @FeedBusinessLayer, @FolderBusinessLayer, @ShowAll) => @scope = {} diff --git a/js/tests/services/businesslayer/businesslayerSpec.coffee b/js/tests/services/businesslayer/businesslayerSpec.coffee index e93fcedd5..db4cb62a0 100644 --- a/js/tests/services/businesslayer/businesslayerSpec.coffee +++ b/js/tests/services/businesslayer/businesslayerSpec.coffee @@ -27,7 +27,7 @@ describe 'BusinessLayer', -> beforeEach inject (@_BusinessLayer, @ActiveFeed, @FeedType, @ItemModel) => type = @FeedType.Starred - angular.module('News').factory 'Persistence', => + @getItemsSpy = jasmine.createSpy('getItems') @persistence = { getItems: @getItemsSpy diff --git a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee index 476d74d30..8e09e7be9 100644 --- a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee @@ -25,22 +25,24 @@ describe 'FeedBusinessLayer', -> beforeEach module 'News' - beforeEach => - angular.module('News').factory 'Persistence', => - @setFeedReadSpy = jasmine.createSpy('setFeedRead') - @getItemsSpy = jasmine.createSpy('Get Items') - @persistence = { - setFeedRead: @setFeedReadSpy - getItems: @getItemsSpy - createFeed: -> - } - angular.module('News').factory 'Utils', => - @imagePath = jasmine.createSpy('imagePath') - @utils = { - imagePath: @imagePath - } - + beforeEach module ($provide) => + @setFeedReadSpy = jasmine.createSpy('setFeedRead') + @getItemsSpy = jasmine.createSpy('Get Items') + @persistence = + setFeedRead: @setFeedReadSpy + getItems: @getItemsSpy + createFeed: -> + test: 'feedbusinesslayer' + + @imagePath = jasmine.createSpy('imagePath') + @utils = + imagePath: @imagePath + + $provide.value 'Persistence', @persistence + $provide.value 'Utils', @utils + return + beforeEach inject (@FeedBusinessLayer, @FeedModel, @ItemModel, @FeedType, @ShowAll, @ActiveFeed, @_ExistsError) => @ShowAll.setShowAll(false) diff --git a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee index 32573dde5..a4cb80162 100644 --- a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee @@ -25,12 +25,18 @@ describe 'FolderBusinessLayer', -> beforeEach module 'News' - beforeEach => - angular.module('News').factory 'Persistence', => - @persistence = - createFolder: -> - createFeed: -> - openFolder: -> + beforeEach module ($provide) => + @persistence = + test: 'folderbusinesslayer' + + @imagePath = jasmine.createSpy('imagePath') + @utils = + imagePath: @imagePath + + $provide.value 'Persistence', @persistence + $provide.value 'Utils', @utils + return + beforeEach inject (@FolderBusinessLayer, @FolderModel, @FeedModel, @ShowAll, @ActiveFeed, @FeedType, @_ExistsError) => @@ -38,7 +44,6 @@ describe 'FolderBusinessLayer', -> @ActiveFeed.handle({type: @FeedType.Feed, id:0}) - it 'should delete folders', => @FolderModel.removeById = jasmine.createSpy('remove') @persistence.deleteFolder = jasmine.createSpy('deletequery') @@ -154,6 +159,7 @@ describe 'FolderBusinessLayer', -> it 'should create a folder before theres a response from the server', => + @persistence.createFolder = jasmine.createSpy('create folder') @FolderBusinessLayer.create('johns') expect(@FolderModel.size()).toBe(1) expect(@FolderModel.getByName('johns').opened).toBe(true) @@ -366,7 +372,7 @@ describe 'FolderBusinessLayer', -> it 'should use an existing folder when importing a folder', => @persistence.createFolder = jasmine.createSpy('create folder') @persistence.createFeed = jasmine.createSpy('create feed') - @persistence.openFolder = jasmine.createSpy('open folder') + @persistence.openFolder = jasmine.createSpy('open') folder = {id: 2, name: 'design', opened: false} @FolderModel.add(folder) diff --git a/js/tests/services/businesslayer/itembusinesslayerSpec.coffee b/js/tests/services/businesslayer/itembusinesslayerSpec.coffee index 0bc8a3188..d5333c1f4 100644 --- a/js/tests/services/businesslayer/itembusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/itembusinesslayerSpec.coffee @@ -26,14 +26,16 @@ describe 'ItemBusinessLayer', -> beforeEach module 'News' - beforeEach => - angular.module('News').factory 'Persistence', => - @persistence = {} - + beforeEach module ($provide) => + @persistence = {} + $provide.value 'Persistence', @persistence + return + beforeEach inject (@ItemModel, @ItemBusinessLayer, @StatusFlag, @ActiveFeed @FeedType, @FeedModel, @StarredBusinessLayer) => @item1 = {id: 5, title: 'hi', unreadCount:134, urlHash: 'a3', folderId: 3} @FeedModel.add(@item1) + it 'should return all items', => diff --git a/js/tests/services/businesslayer/starredbusinesslayerSpec.coffee b/js/tests/services/businesslayer/starredbusinesslayerSpec.coffee index feefdb181..88b5cbeef 100644 --- a/js/tests/services/businesslayer/starredbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/starredbusinesslayerSpec.coffee @@ -25,12 +25,15 @@ describe 'StarredBusinessLayer', -> beforeEach module 'News' - beforeEach => - angular.module('News').factory 'Persistence', => - @persistence = {} + beforeEach module ($provide) => + @persistence = + test: 'starredbusinesslayer' + + $provide.value 'Persistence', @persistence + return beforeEach inject (@StarredBusinessLayer, @StarredCount, @ActiveFeed, - @FeedType) => + @FeedType) => @ActiveFeed.handle({type: @FeedType.Feed, id:0}) @StarredCount.setStarredCount(0) diff --git a/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee b/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee index 0047f9437..8ab904c0a 100644 --- a/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee @@ -25,12 +25,13 @@ describe 'SubscriptionsBusinessLayer', -> beforeEach module 'News' - beforeEach => - angular.module('News').factory 'Persistence', => - @setFeedReadSpy = jasmine.createSpy('setFeedRead') - @persistence = { - setFeedRead: @setFeedReadSpy - } + beforeEach module ($provide) => + @persistence = + setFeedRead: jasmine.createSpy('setFeedRead') + test: 'subscriptionsbusinesslayer' + + $provide.value 'Persistence', @persistence + return beforeEach inject (@SubscriptionsBusinessLayer, @ShowAll, @FeedModel, @ActiveFeed, @FeedType) => @@ -71,7 +72,7 @@ describe 'SubscriptionsBusinessLayer', -> @SubscriptionsBusinessLayer.markAllRead() expect(item.unreadCount).toBe(0) - expect(@setFeedReadSpy).toHaveBeenCalled() + expect(@persistence.setFeedRead).toHaveBeenCalled() it 'should get the correct unread count', => diff --git a/js/tests/services/models/feedmodelSpec.coffee b/js/tests/services/models/feedmodelSpec.coffee index c73c2149d..6df9d6e9f 100644 --- a/js/tests/services/models/feedmodelSpec.coffee +++ b/js/tests/services/models/feedmodelSpec.coffee @@ -25,10 +25,14 @@ describe 'FeedModel', -> beforeEach module 'News' - beforeEach => - angular.module('News').factory 'Utils', => - @utils = - imagePath: jasmine.createSpy('utils') + beforeEach module ($provide) => + @imagePath = jasmine.createSpy('imagePath') + @utils = + imagePath: @imagePath + + $provide.value 'Utils', @utils + return + beforeEach inject (@FeedModel, @_Model) => diff --git a/js/tests/services/persistenceSpec.coffee b/js/tests/services/persistenceSpec.coffee index 80a95c758..3fca95cc2 100644 --- a/js/tests/services/persistenceSpec.coffee +++ b/js/tests/services/persistenceSpec.coffee @@ -21,37 +21,24 @@ License along with this library. If not, see . ### -describe '_Persistence', -> - +describe 'Persistence', -> beforeEach module 'News' - beforeEach inject (@_Persistence, @$rootScope) => + beforeEach module ($provide) => @req = - post: jasmine.createSpy('POST') - get: jasmine.createSpy('GET').andCallFake (route, data) -> - if angular.isDefined(data) and data.onSuccess - data.onSuccess() + get: jasmine.createSpy('get') + post: jasmine.createSpy('post') @config = - itemBatchSize: 12 - @active = - getType: -> 3 - getId: -> 1 - @loading = - increase: -> - decrease: -> - - - it 'should should show a loading sign when init', => - loading = - increase: jasmine.createSpy('loading') - decrease: jasmine.createSpy('finished loading') - - pers = new @_Persistence(@req, loading, @config, @active, @$rootScope) - pers.init() + itemBatchSize: 3 - expect(loading.increase).toHaveBeenCalled() - expect(loading.decrease).toHaveBeenCalled() + $provide.value 'Request', @req + $provide.value 'Config', @config + return + + + beforeEach inject (@Persistence) => + ### @@ -66,11 +53,19 @@ describe '_Persistence', -> offset: 3 onSuccess: -> - pers = new @_Persistence(@req, @loading, @config, @active, @$rootScope) - pers.getItems(params.data.type, params.data.id, params.data.offset, - params.onSuccess, null) + @Persistence.getItems(params.data.type, params.data.id, +