/**
* ownCloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2014
*/
describe('NavigationController', function () {
'use strict';
var controller;
beforeEach(module('News', function ($provide) {
$provide.value('BASE_URL', 'base');
$provide.value('FEED_TYPE', {
FEED: 0,
FOLDER: 1,
STARRED: 2,
SUBSCRIPTIONS: 3,
SHARED: 4
});
$provide.constant('ITEM_BATCH_SIZE', 5);
}));
beforeEach(inject(function ($controller, FeedResource) {
controller = $controller('NavigationController');
FeedResource.receive([
{id: 1, folderId: 3, url: 'ye', unreadCount: 45},
{id: 2, folderId: 4, url: 'sye', unreadCount: 25},
{id: 3, folderId: 3, title: 'hore', url: '1sye', unreadCount: 1}
]);
}));
it('should expose Feeds', inject(function (FeedResource) {
FeedResource.add({url: 1});
expect(controller.getFeeds()).toBe(FeedResource.getAll());
}));
it('should expose Folders', inject(function (FolderResource) {
FolderResource.add({name: 1});
expect(controller.getFolders()).toBe(FolderResource.getAll());
}));
it('should mark Folders read', inject(function ($controller) {
var FeedResource = {
markFolderRead: jasmine.createSpy('folder'),
getByFolderId: function () {
return [
{id: 3},
{id: 4}
];
}
};
var ItemResource = {
markFeedRead: jasmine.createSpy('feedfolder')
};
controller = $controller('NavigationController', {
FeedResource: FeedResource,
ItemResource: ItemResource
});
controller.markFolderRead(3);
expect(FeedResource.markFolderRead).toHaveBeenCalledWith(3);
expect(ItemResource.markFeedRead.callCount).toBe(2);
}));
it('should mark a feed read', inject(function ($controller) {
var FeedResource = {
markFeedRead: jasmine.createSpy('folder'),
};
var ItemResource = {
markFeedRead: jasmine.createSpy('feedfolder')
};
controller = $controller('NavigationController', {
FeedResource: FeedResource,
ItemResource: ItemResource
});
controller.markFeedRead(3);
expect(FeedResource.markFeedRead).toHaveBeenCalledWith(3);
expect(ItemResource.markFeedRead).toHaveBeenCalledWith(3);
}));
it('should mark all read', inject(function ($controller) {
var FeedResource = {
markRead: jasmine.createSpy('folder'),
};
var ItemResource = {
markRead: jasmine.createSpy('feedfolder')
};
controller = $controller('NavigationController', {
FeedResource: FeedResource,
ItemResource: ItemResource
});
controller.markRead();
expect(FeedResource.markRead).toHaveBeenCalled();
expect(ItemResource.markRead).toHaveBeenCalled();
}));
it('should mark all read', inject(function (SettingsResource, $controller) {
var ctrl = $controller('NavigationController', {
SettingsResource: SettingsResource,
});