summaryrefslogtreecommitdiffstats
path: root/js/build/tests/services/businesslayer
diff options
context:
space:
mode:
Diffstat (limited to 'js/build/tests/services/businesslayer')
-rw-r--r--js/build/tests/services/businesslayer/businesslayerSpec.js88
-rw-r--r--js/build/tests/services/businesslayer/feedbusinesslayerSpec.js478
-rw-r--r--js/build/tests/services/businesslayer/folderbusinesslayerSpec.js577
-rw-r--r--js/build/tests/services/businesslayer/itembusinesslayerSpec.js330
-rw-r--r--js/build/tests/services/businesslayer/starredbusinesslayerSpec.js69
-rw-r--r--js/build/tests/services/businesslayer/subsriptionsbusinesslayerSpec.js130
6 files changed, 0 insertions, 1672 deletions
diff --git a/js/build/tests/services/businesslayer/businesslayerSpec.js b/js/build/tests/services/businesslayer/businesslayerSpec.js
deleted file mode 100644
index 8a5a9c1b2..000000000
--- a/js/build/tests/services/businesslayer/businesslayerSpec.js
+++ /dev/null
@@ -1,88 +0,0 @@
-// Generated by CoffeeScript 1.6.3
-/*
-
-ownCloud - News
-
-@author Bernhard Posselt
-@copyright 2012 Bernhard Posselt dev@bernhard-posselt.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() {
- 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; };
-
- describe('BusinessLayer', function() {
- var _this = this;
- beforeEach(module('News'));
- beforeEach(inject(function(_BusinessLayer, ActiveFeed, FeedType, ItemModel) {
- var TestBusinessLayer, type;
- _this._BusinessLayer = _BusinessLayer;
- _this.ActiveFeed = ActiveFeed;
- _this.FeedType = FeedType;
- _this.ItemModel = ItemModel;
- type = _this.FeedType.Starred;
- _this.getItemsSpy = jasmine.createSpy('getItems');
- _this.persistence = {
- getItems: _this.getItemsSpy
- };
- TestBusinessLayer = (function(_super) {
- __extends(TestBusinessLayer, _super);
-
- function TestBusinessLayer(activeFeed, persistence, itemModel) {
- TestBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, type);
- }
-
- return TestBusinessLayer;
-
- })(_this._BusinessLayer);
- return _this.BusinessLayer = new TestBusinessLayer(_this.ActiveFeed, _this.persistence, _this.ItemModel);
- }));
- it('should reset the item cache when a different feed is being loaded', function() {
- _this.ItemModel.clear = jasmine.createSpy('clear');
- _this.ActiveFeed.handle({
- id: 0,
- type: _this.FeedType.Starred
- });
- _this.BusinessLayer.load(2);
- expect(_this.ItemModel.clear).toHaveBeenCalled();
- _this.ActiveFeed.handle({
- id: 2,
- type: _this.FeedType.Feed
- });
- _this.BusinessLayer.load(2);
- return expect(_this.ItemModel.clear).toHaveBeenCalled();
- });
- it('should send a get all items query when feed changed', function() {
- _this.persistence.getItems = jasmine.createSpy('latest');
- _this.ActiveFeed.handle({
- id: 3,
- type: _this.FeedType.Feed
- });
- _this.BusinessLayer.load(3);
- return expect(_this.persistence.getItems).toHaveBeenCalledWith(_this.FeedType.Starred, 3, 0);
- });
- return it('should be active when its selected', function() {
- expect(_this.BusinessLayer.isActive(0)).toBe(false);
- _this.ActiveFeed.handle({
- type: _this.FeedType.Starred,
- id: 0
- });
- return expect(_this.BusinessLayer.isActive(0)).toBe(true);
- });
- });
-
-}).call(this);
diff --git a/js/build/tests/services/businesslayer/feedbusinesslayerSpec.js b/js/build/tests/services/businesslayer/feedbusinesslayerSpec.js
deleted file mode 100644
index 592b90057..000000000
--- a/js/build/tests/services/businesslayer/feedbusinesslayerSpec.js
+++ /dev/null
@@ -1,478 +0,0 @@
-// Generated by CoffeeScript 1.6.3
-/*
-
-ownCloud - News
-
-@author Bernhard Posselt
-@copyright 2012 Bernhard Posselt dev@bernhard-posselt.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() {
- describe('FeedBusinessLayer', function() {
- var _this = this;
- beforeEach(module('News'));
- beforeEach(module(function($provide) {
- _this.setFeedReadSpy = jasmine.createSpy('setFeedRead');
- _this.getItemsSpy = jasmine.createSpy('Get Items');
- _this.persistence = {
- setFeedRead: _this.setFeedReadSpy,
- getItems: _this.getItemsSpy,
- createFeed: function() {},
- test: 'feedbusinesslayer'
- };
- _this.imagePath = jasmine.createSpy('imagePath');
- _this.utils = {
- imagePath: _this.imagePath
- };
- $provide.value('Persistence', _this.persistence);
- $provide.value('Utils', _this.utils);
- }));
- beforeEach(inject(function(FeedBusinessLayer, FeedModel, ItemModel, FeedType, ShowAll, ActiveFeed, _ExistsError, $timeout, NewestItem, $rootScope) {
- _this.FeedBusinessLayer = FeedBusinessLayer;
- _this.FeedModel = FeedModel;
- _this.ItemModel = ItemModel;
- _this.FeedType = FeedType;
- _this.ShowAll = ShowAll;
- _this.ActiveFeed = ActiveFeed;
- _this._ExistsError = _ExistsError;
- _this.$timeout = $timeout;
- _this.NewestItem = NewestItem;
- _this.$rootScope = $rootScope;
- _this.ShowAll.setShowAll(false);
- return _this.ActiveFeed.handle({
- type: _this.FeedType.Folder,
- id: 0
- });
- }));
- it('should delete feeds', function() {
- var data;
- data = null;
- _this.$rootScope.$on('undoMessage', function(scope, data) {
- return data = data;
- });
- _this.FeedModel.removeById = jasmine.createSpy('remove').andCallFake(function() {
- return {
- id: 3,
- title: 'test'
- };
- });
- _this.persistence.deleteFeed = jasmine.createSpy('deletequery');
- _this.FeedBusinessLayer["delete"](3);
- expect(_this.FeedModel.removeById).toHaveBeenCalledWith(3);
- return expect(_this.persistence.deleteFeed).toHaveBeenCalledWith(3);
- });
- it('should return the number of unread feeds', function() {
- var count;
- _this.FeedModel.add({
- id: 3,
- unreadCount: 134,
- url: 'a1'
- });
- count = _this.FeedBusinessLayer.getUnreadCount(3);
- return expect(count).toBe(134);
- });
- it('should return all feeds of a folder', function() {
- var feed1, feed2, feed3, feeds;
- feed1 = {
- id: 3,
- unreadCount: 134,
- url: 'a1',
- folderId: 3
- };
- feed2 = {
- id: 4,
- unreadCount: 134,
- url: 'a2',
- folderId: 2
- };
- feed3 = {
- id: 5,
- unreadCount: 134,
- url: 'a3',
- folderId: 3
- };
- _this.FeedModel.add(feed1);
- _this.FeedModel.add(feed2);
- _this.FeedModel.add(feed3);
- feeds = _this.FeedBusinessLayer.getFeedsOfFolder(3);
- expect(feeds).toContain(feed1);
- return expect(feeds).toContain(feed3);
- });
- it('should get the correct unread count for folders', function() {
- var count;
- _this.FeedModel.add({
- id: 3,
- unreadCount: 134,
- folderId: 3,
- url: 'a1'
- });
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 2,
- url: 'a2'
- });
- _this.FeedModel.add({
- id: 1,
- unreadCount: 12,
- folderId: 5,
- url: 'a3'
- });
- _this.FeedModel.add({
- id: 2,
- unreadCount: 35,
- folderId: 3,
- url: 'a4'
- });
- count = _this.FeedBusinessLayer.getFolderUnreadCount(3);
- return expect(count).toBe(169);
- });
- it('should not mark feed read when no highest item id', function() {
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 2,
- url: 'a1'
- });
- _this.persistence.setFeedRead = jasmine.createSpy('setFeedRead');
- _this.FeedBusinessLayer.markRead(5);
- return expect(_this.persistence.setFeedRead).not.toHaveBeenCalled();
- });
- it('should mark feed as read', function() {
- var item1, item2;
- _this.NewestItem.handle(25);
- _this.ActiveFeed.handle({
- type: _this.FeedType.Feed,
- id: 5
- });
- _this.persistence.setFeedRead = jasmine.createSpy('setFeedRead');
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 2,
- url: 'a1'
- });
- item1 = {
- id: 3,
- feedId: 5,
- guidHash: 'a3',
- status: 0
- };
- _this.ItemModel.add(item1);
- item1.setUnread();
- item2 = {
- id: 2,
- feedId: 3,
- guidHash: 'a3',
- status: 0
- };
- _this.ItemModel.add(item2);
- item2.setUnread();
- _this.FeedBusinessLayer.markRead(5);
- expect(_this.persistence.setFeedRead).toHaveBeenCalledWith(5, 25);
- expect(_this.FeedModel.getById(5).unreadCount).toBe(0);
- expect(item1.isRead()).toBe(true);
- return expect(item2.isRead()).toBe(false);
- });
- it('should get the correct unread count for subscribtions', function() {
- var count;
- _this.FeedModel.add({
- id: 3,
- unreadCount: 134,
- url: 'a1'
- });
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- url: 'a2'
- });
- count = _this.FeedBusinessLayer.getAllUnreadCount();
- return expect(count).toBe(136);
- });
- it('should return the correct number of feeds', function() {
- var count;
- _this.FeedModel.add({
- id: 3,
- unreadCount: 134,
- url: 'a1'
- });
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- url: 'a2'
- });
- count = _this.FeedBusinessLayer.getNumberOfFeeds();
- return expect(count).toBe(2);
- });
- it('should be visible if its active', function() {
- _this.ActiveFeed.handle({
- type: _this.FeedType.Feed,
- id: 3
- });
- return expect(_this.FeedBusinessLayer.isVisible(3)).toBe(true);
- });
- it('should be visible if show all is true', function() {
- expect(_this.FeedBusinessLayer.isVisible(3)).toBe(false);
- _this.ShowAll.setShowAll(true);
- return expect(_this.FeedBusinessLayer.isVisible(3)).toBe(true);
- });
- it('should be visible if unreadcount bigger than 0', function() {
- _this.FeedModel.add({
- id: 2,
- unreadCount: 134,
- url: 'a1'
- });
- return expect(_this.FeedBusinessLayer.isVisible(2)).toBe(true);
- });
- it('should not move the feed to a new folder', function() {
- _this.persistence.moveFeed = jasmine.createSpy('Move feed');
- _this.FeedModel.add({
- id: 2,
- unreadCount: 134,
- url: 'a1',
- folderId: 3
- });
- _this.FeedBusinessLayer.move(2, 4);
- expect(_this.persistence.moveFeed).toHaveBeenCalledWith(2, 4);
- return expect(_this.FeedModel.getById(2).folderId).toBe(4);
- });
- it('should not move the feed to the same folder', function() {
- _this.persistence.moveFeed = jasmine.createSpy('Move feed');
- _this.FeedModel.add({
- id: 2,
- unreadCount: 134,
- url: 'a1',
- folderId: 3
- });
- _this.FeedBusinessLayer.move(2, 3);
- return expect(_this.persistence.moveFeed).not.toHaveBeenCalled();
- });
- it('should set the show all setting', function() {
- _this.persistence.userSettingsReadShow = jasmine.createSpy('Show All');
- _this.FeedBusinessLayer.setShowAll(true);
- return expect(_this.persistence.userSettingsReadShow).toHaveBeenCalled();
- });
- it('should set the hide read setting', function() {
- _this.persistence.userSettingsReadHide = jasmine.createSpy('Hide Read');
- _this.FeedBusinessLayer.setShowAll(false);
- return expect(_this.persistence.userSettingsReadHide).toHaveBeenCalled();
- });
- it('should return all feeds', function() {
- var item1, item2;
- item1 = {
- id: 2,
- unreadCount: 134,
- url: 'a1',
- folderId: 3
- };
- item2 = {
- id: 4,
- unreadCount: 134,
- url: 'a2',
- folderId: 3
- };
- _this.FeedModel.add(item1);
- _this.FeedModel.add(item2);
- expect(_this.FeedBusinessLayer.getAll()).toContain(item1);
- return expect(_this.FeedBusinessLayer.getAll()).toContain(item2);
- });
- it('should return if ShowAll is set', function() {
- _this.persistence.userSettingsReadShow = jasmine.createSpy('Show All');
- expect(_this.FeedBusinessLayer.isShowAll()).toBe(false);
- _this.FeedBusinessLayer.setShowAll(true);
- return expect(_this.FeedBusinessLayer.isShowAll()).toBe(true);
- });
- it('should return all feeds of a folder', function() {
- var folders, item1, item2, item3;
- item1 = {
- id: 2,
- unreadCount: 134,
- url: 'a1',
- folderId: 3
- };
- item2 = {
- id: 4,
- unreadCount: 134,
- url: 'a2',
- folderId: 2
- };
- item3 = {
- id: 5,
- unreadCount: 134,
- url: 'a3',
- folderId: 3
- };
- _this.FeedModel.add(item1);
- _this.FeedModel.add(item2);
- _this.FeedModel.add(item3);
- folders = _this.FeedBusinessLayer.getFeedsOfFolder(3);
- expect(folders).toContain(item1);
- return expect(folders).toContain(item3);
- });
- it('should return the correct feed link', function() {
- var item2;
- item2 = {
- id: 4,
- unreadCount: 134,
- url: 'a2',
- folderId: 3,
- link: 'test.com'
- };
- _this.FeedModel.add(item2);
- return expect(_this.FeedBusinessLayer.getFeedLink(4)).toBe('test.com');
- });
- it('should not create a feed if it already exists', function() {
- var item1;
- item1 = {
- url: 'http://john'
- };
- _this.FeedModel.add(item1);
- expect(function() {
- return _this.FeedBusinessLayer.create('john');
- }).toThrow(new _this._ExistsError('Exists already'));
- return expect(function() {
- return _this.FeedBusinessLayer.create('johns');
- }).not.toThrow(new _this._ExistsError('Exists already'));
- });
- it('should not create feeds that are empty', function() {
- return expect(function() {
- return _this.FeedBusinessLayer.create(' ');
- }).toThrow(new Error('Url must not be empty'));
- });
- it('should create a feed before theres a response from the server', function() {
- _this.FeedBusinessLayer.create('johns');
- return expect(_this.FeedModel.size()).toBe(1);
- });
- it('should set a title and an url to the newly created feed', function() {
- var feed, url;
- url = 'www.google.de';
- _this.FeedBusinessLayer.create(url);
- feed = _this.FeedModel.getByUrl('http://' + url);
- expect(feed.title).toBe('http://www.google.de');
- expect(feed.url).toBe('http://' + url);
- expect(feed.folderId).toBe(0);
- expect(feed.unreadCount).toBe(0);
- return expect(_this.imagePath).toHaveBeenCalledWith('core', 'loading.gif');
- });
- it('should not add http when it already is at the start of created feed', function() {
- var feed, url;
- url = 'https://www.google.de';
- _this.FeedBusinessLayer.create(url);
- feed = _this.FeedModel.getByUrl(url);
- return expect(feed.url).toBe(url);
- });
- it('should make a create feed request', function() {
- _this.persistence.createFeed = jasmine.createSpy('add feed');
- _this.FeedBusinessLayer.create(' johns ');
- return expect(_this.persistence.createFeed).toHaveBeenCalledWith('http://johns', 0, jasmine.any(Function));
- });
- it('should call the onSuccess function on response status ok', function() {
- var onSuccess;
- onSuccess = jasmine.createSpy('Success');
- _this.persistence.createFeed = jasmine.createSpy('add feed');
- _this.persistence.createFeed.andCallFake(function(folderName, parentId, success) {
- _this.response = {
- status: 'ok',
- data: 'hi'
- };
- return success(_this.response);
- });
- _this.FeedBusinessLayer.create(' johns ', 0, onSuccess);
- return expect(onSuccess).toHaveBeenCalledWith(_this.response.data);
- });
- it('should call the handle a response error when creating a folder', function() {
- var onFailure, onSuccess;
- onSuccess = jasmine.createSpy('Success');
- onFailure = jasmine.createSpy('Failure');
- _this.persistence.createFeed = jasmine.createSpy('add feed');
- _this.persistence.createFeed.andCallFake(function(folderName, parentId, success) {
- _this.response = {
- status: 'error',
- msg: 'this is an error'
- };
- return success(_this.response);
- });
- _this.FeedBusinessLayer.create(' johns ', 0, onSuccess, onFailure);
- expect(onSuccess).not.toHaveBeenCalled();
- expect(onFailure).toHaveBeenCalled();
- return expect(_this.FeedModel.getByUrl('http://johns').error).toBe(_this.response.msg);
- });
- it('should mark a feed error as read by removing it', function() {
- _this.FeedModel.add({
- id: 3,
- url: 'john'
- });
- _this.FeedBusinessLayer.markErrorRead('john');
- expect(_this.FeedModel.size()).toBe(0);
- return expect(_this.FeedModel.getByUrl('john')).toBe(void 0);
- });
- it('should not import google reader json', function() {
- var imported, json;
- _this.persistence.importGoogleReader = jasmine.createSpy('importGoogleReader');
- json = {
- "test": "hi"
- };
- _this.FeedBusinessLayer.importGoogleReader(json);
- imported = _this.FeedModel.getByUrl('http://owncloud/googlereader');
- expect(imported.title).toBe('Google Reader');
- expect(imported.folderId).toBe(0);
- return expect(imported.unreadCount).toBe(0);
- });
- it('should not create a google reader feed if it already exists', function() {
- var imported, json;
- _this.persistence.importGoogleReader = jasmine.createSpy('importGoogleReader');
- _this.FeedModel.add({
- id: 3,
- url: 'http://owncloud/googlereader'
- });
- json = {
- "test": "hi"
- };
- _this.FeedBusinessLayer.importGoogleReader(json);
- imported = _this.FeedModel.getByUrl('http://owncloud/googlereader');
- return expect(imported.folderId).not.toBeDefined();
- });
- return it('should create an import google reader request', function() {
- var json, returned;
- returned = {
- data: {
- feeds: [
- {
- id: 3,
- url: 'hi'
- }
- ]
- }
- };
- _this.persistence.getItems = jasmine.createSpy('importGoogleReader');
- _this.persistence.importGoogleReader = jasmine.createSpy('importGoogleReader');
- _this.persistence.importGoogleReader.andCallFake(function(data, onSuccess) {
- _this.FeedModel.handle(returned.data.feeds);
- return onSuccess(returned);
- });
- json = {
- "test": "hi"
- };
- _this.FeedBusinessLayer.importGoogleReader(json);
- expect(_this.persistence.importGoogleReader).toHaveBeenCalledWith(json, jasmine.any(Function));
- expect(_this.persistence.getItems).toHaveBeenCalledWith(_this.FeedType.Feed, returned.data.feeds[0].id, 0);
- expect(_this.ActiveFeed.getId()).toBe(returned.data.feeds[0].id);
- return expect(_this.ActiveFeed.getType()).toBe(_this.FeedType.Feed);
- });
- });
-
-}).call(this);
diff --git a/js/build/tests/services/businesslayer/folderbusinesslayerSpec.js b/js/build/tests/services/businesslayer/folderbusinesslayerSpec.js
deleted file mode 100644
index be4e3cd3a..000000000
--- a/js/build/tests/services/businesslayer/folderbusinesslayerSpec.js
+++ /dev/null
@@ -1,577 +0,0 @@
-// Generated by CoffeeScript 1.6.3
-/*
-
-ownCloud - News
-
-@author Bernhard Posselt
-@copyright 2012 Bernhard Posselt dev@bernhard-posselt.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() {
- describe('FolderBusinessLayer', function() {
- var _this = this;
- beforeEach(module('News'));
- beforeEach(module(function($provide) {
- _this.persistence = {
- test: 'folderbusinesslayer'
- };
- _this.imagePath = jasmine.createSpy('imagePath');
- _this.utils = {
- imagePath: _this.imagePath
- };
- $provide.value('Persistence', _this.persistence);
- $provide.value('Utils', _this.utils);
- }));
- beforeEach(inject(function(FolderBusinessLayer, FolderModel, FeedModel, ShowAll, ActiveFeed, FeedType, _ExistsError, $timeout, NewestItem, ItemModel, $rootScope) {
- _this.FolderBusinessLayer = FolderBusinessLayer;
- _this.FolderModel = FolderModel;
- _this.FeedModel = FeedModel;
- _this.ShowAll = ShowAll;
- _this.ActiveFeed = ActiveFeed;
- _this.FeedType = FeedType;
- _this._ExistsError = _ExistsError;
- _this.$timeout = $timeout;
- _this.NewestItem = NewestItem;
- _this.ItemModel = ItemModel;
- _this.$rootScope = $rootScope;
- _this.ShowAll.setShowAll(false);
- return _this.ActiveFeed.handle({
- type: _this.FeedType.Feed,
- id: 0
- });
- }));
- it('should delete folders', function() {
- var data;
- data = null;
- _this.$rootScope.$on('undoMessage', function(scope, data) {
- return data = data;
- });
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 3,
- url: 'a1'
- });
- _this.FolderModel.removeById = jasmine.createSpy('remove').andCallFake(function() {
- return {
- id: 3,
- name: 'test'
- };
- });
- _this.FeedModel.removeById = jasmine.createSpy('remove').andCallFake(function() {
- return {
- id: 5,
- name: 'test',
- folderId: 3
- };
- });
- _this.persistence.deleteFolder = jasmine.createSpy('deletequery');
- _this.FolderBusinessLayer["delete"](3);
- expect(_this.FolderModel.removeById).toHaveBeenCalledWith(3);
- expect(_this.FeedModel.removeById).toHaveBeenCalledWith(5);
- return expect(_this.persistence.deleteFolder).toHaveBeenCalledWith(3);
- });
- it('should return true when folder has feeds', function() {
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 2,
- url: 'a1'
- });
- expect(_this.FolderBusinessLayer.hasFeeds(3)).toBeFalsy();
- _this.FeedModel.add({
- id: 2,
- unreadCount: 35,
- folderId: 3,
- url: 'a2'
- });
- return expect(_this.FolderBusinessLayer.hasFeeds(3)).toBeTruthy();
- });
- it('should toggle folder', function() {
- _this.persistence.openFolder = jasmine.createSpy('open');
- _this.persistence.collapseFolder = jasmine.createSpy('collapse');
- _this.FolderModel.add({
- id: 3,
- opened: false,
- name: 'ho'
- });
- _this.FolderBusinessLayer.toggleFolder(4);
- expect(_this.FolderModel.getById(3).opened).toBeFalsy();
- _this.FolderBusinessLayer.toggleFolder(3);
- expect(_this.FolderModel.getById(3).opened).toBeTruthy();
- expect(_this.persistence.openFolder).toHaveBeenCalledWith(3);
- _this.FolderBusinessLayer.toggleFolder(3);
- expect(_this.FolderModel.getById(3).opened).toBeFalsy();
- return expect(_this.persistence.collapseFolder).toHaveBeenCalledWith(3);
- });
- it('should mark folder as read', function() {
- var item1, item2;
- _this.NewestItem.handle(25);
- _this.persistence.setFolderRead = jasmine.createSpy('setFeedRead');
- item1 = {
- id: 3,
- feedId: 5,
- guidHash: 'a3',
- status: 0
- };
- _this.ItemModel.add(item1);
- item1.setUnread();
- item2 = {
- id: 2,
- feedId: 3,
- guidHash: 'a3',
- status: 0
- };
- _this.ItemModel.add(item2);
- item2.setUnread();
- _this.FolderModel.add({
- id: 3,
- opened: false,
- name: 'ho'
- });
- _this.FeedModel.add({
- id: 3,
- unreadCount: 134,
- folderId: 3,
- url: 'a1'
- });
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 2,
- url: 'a2'
- });
- _this.FeedModel.add({
- id: 1,
- unreadCount: 12,
- folderId: 3,
- url: 'a3'
- });
- _this.FolderBusinessLayer.markRead(3);
- expect(_this.FeedModel.getById(3).unreadCount).toBe(0);
- expect(_this.FeedModel.getById(1).unreadCount).toBe(0);
- expect(_this.FeedModel.getById(5).unreadCount).toBe(2);
- expect(item1.isRead()).toBe(false);
- expect(item2.isRead()).toBe(true);
- return expect(_this.persistence.setFolderRead).toHaveBeenCalledWith(3, 25);
- });
- it('should not mark folder read when no highest item id', function() {
- _this.FolderModel.add({
- id: 5,
- opened: false,
- name: 'ho'
- });
- _this.persistence.setFolderRead = jasmine.createSpy('setFolderRead');
- _this.FolderBusinessLayer.markRead(5);
- return expect(_this.persistence.setFolderRead).not.toHaveBeenCalled();
- });
- it('should get the correct unread count', function() {
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 2,
- url: 'a1'
- });
- _this.FeedModel.add({
- id: 6,
- unreadCount: 3,
- folderId: 3,
- url: 'a2'
- });
- _this.FeedModel.add({
- id: 7,
- unreadCount: 4,
- folderId: 2,
- url: 'a3'
- });
- return expect(_this.FolderBusinessLayer.getUnreadCount(2)).toBe(6);
- });
- it('should be visible if show all is true', function() {
- expect(_this.FolderBusinessLayer.isVisible(3)).toBe(false);
- _this.ShowAll.setShowAll(true);
- return expect(_this.FolderBusinessLayer.isVisible(3)).toBe(true);
- });
- it('should be visible if its active', function() {
- _this.ActiveFeed.handle({
- type: _this.FeedType.Folder,
- id: 3
- });
- return expect(_this.FolderBusinessLayer.isVisible(3)).toBe(true);
- });
- it('should be visible if one of its subfeeds is active', function() {
- _this.FeedModel.add({
- id: 5,
- unreadCount: 0,
- folderId: 2,
- url: 'a1'
- });
- _this.FeedModel.add({
- id: 6,
- unreadCount: 0,
- folderId: 3,
- url: 'a2'
- });
- _this.FeedModel.add({
- id: 7,
- unreadCount: 0,
- folderId: 2,
- url: 'a3'
- });
- _this.ActiveFeed.handle({
- type: _this.FeedType.Feed,
- id: 6
- });
- return expect(_this.FolderBusinessLayer.isVisible(3)).toBe(true);
- });
- it('should be visible if showAll is false and it has unread items', function() {
- _this.FeedModel.add({
- id: 5,
- unreadCount: 2,
- folderId: 2,
- url: 'a1'
- });
- _this.FeedModel.add({
- id: 6,
- unreadCount: 3,
- folderId: 3,
- url: 'a2'
- });
- _this.FeedModel.add({
- id: 7,
- unreadCount: 4,
- folderId: 2,
- url: 'a3'
- });
- _this.ActiveFeed.handle({
- type: _this.FeedType.Folder,
- id: 2
- });
- return expect(_this.FolderBusinessLayer.isVisible(3)).toBe(true);
- });
- it('should return all folders', function() {
- var item1, item2;
- item1 = {
- id: 3,
- open: false,
- name: 'ho'
- };
- item2 = {
- id: 4,
- open: true,
- name: 'hod'
- };
- _this.FolderModel.add(item1);
- _this.FolderModel.add(item2);
- expect(_this.FolderBusinessLayer.getAll()).toContain(item1);
- return expect(_this.FolderBusinessLayer.getAll()).toContain(item2);
- });
- it('should not create a folder if it already exists', function() {
- var item1;
- item1 = {
- id: 4,
- open: true,
- name: 'john'
- };
- _this.FolderModel.add(item1);
- expect(function() {
- return _this.FolderBusinessLayer.create('john');
- }).toThrow(new _this._ExistsError('Exists already'));
- return expect(function() {
- return _this.FolderBusinessLayer.create('johns');
- }).not.toThrow(new _this._ExistsError('Exists already'));
- });
- it('should not create folders that are empty', function() {
- return expect(function() {
- return _this.FolderBusinessLayer.create(' ');
- }).toThrow(new Error('Folder name must not be empty'));
- });
- it('should create a folder before theres a response from the server', function() {
- _this.persistence.createFolder = jasmine.createSpy('create folder');
- _this.FolderBusinessLayer.create('johns');
- expect(_this.FolderModel.size()).toBe(1);
- return expect(_this.FolderModel.getByName('johns').opened).toBe(true);
- });
- it('should make a create folder request', function() {
- _this.persistence.createFolder = jasmine.createSpy('add folder');
- _this.FolderBusinessLayer.create(' johns ');
- return expect(_this.persistence.createFolder).toHaveBeenCalledWith('johns', 0, jasmine.any(Function));
- });
- it('should call the onSuccess function on response status ok', function() {
- var onSuccess;
- onSuccess = jasmine.createSpy('Success');
- _this.persistence.createFolder = jasmine.createSpy('add folder');
- _this.persistence.createFolder.andCallFake(function(folderName, parentId, success) {
- _this.response = {
- status: 'ok',
- data: 'jooo'
- };
- return success(_this.response);
- });
- _this.FolderBusinessLayer.create(' johns ', onSuccess);
- return expect(onSuccess).toHaveBeenCalledWith(_this.response.data);
- });
- it('should call the handle a response error when creating a folder', function() {
- var onFailure, onSuccess;
- onSuccess = jasmine.createSpy('Success');
- onFailure = jasmine.createSpy('Failure');
- _this.persistence.createFolder = jasmine.createSpy('add folder');
- _this.persistence.createFolder.andCallFake(function(folderName, parentId, success) {
- _this.response = {
- status: 'error',
- msg: 'this is an error'
- };
- return success(_this.response);
- });
- _this.FolderBusinessLayer.create(' johns ', onSuccess, onFailure);
- expect(onSuccess).not.toHaveBeenCalled();
- expect(onFailure).toHaveBeenCalled();
- return expect(_this.FolderModel.getByName('johns').error).toBe(_this.response.msg);
- });
- it('should mark a folder error as read by removing it', function() {
- _this.FolderModel.add({
- id: 3,
- name: 'john'
- });
- _this.FolderBusinessLayer.markErrorRead('John');
- expect(_this.FolderModel.size()).toBe(0);
- return expect(_this.FolderModel.getByName('john')).toBe(void 0);