summaryrefslogtreecommitdiffstats
path: root/js/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-09-11 20:26:04 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-09-11 20:26:04 +0200
commitf3091d84e14537a42334e66ea6588cf2b83f9ab6 (patch)
tree943151aa564177e956d5dc1b2fff12845e48c4c0 /js/tests
parentf50dba835fa58f9ba979a9038ffd185ab8fe3b96 (diff)
various work on creating feeds, folders and showing folders
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/controller/NavigationControllerSpec.js160
-rw-r--r--js/tests/unit/service/FeedResourceSpec.js40
-rw-r--r--js/tests/unit/service/FolderResourceSpec.js25
-rw-r--r--js/tests/unit/stubs/OC.js4
4 files changed, 203 insertions, 26 deletions
diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js
index e871a2174..56533ad9f 100644
--- a/js/tests/unit/controller/NavigationControllerSpec.js
+++ b/js/tests/unit/controller/NavigationControllerSpec.js
@@ -207,6 +207,7 @@ describe('NavigationController', function () {
expect(ctrl.subFeedActive(3)).toBe(true);
}));
+
it('should check if a subscriptions is active', inject(function (
FeedResource, FEED_TYPE, $controller) {
var ctrl = $controller('NavigationController', {
@@ -285,8 +286,165 @@ describe('NavigationController', function () {
it('should expose check if folder exists', inject(function (
FolderResource) {
expect(controller.folderNameExists('hi')).toBe(false);
- FolderResource.add({name: 'hi'});
+ FolderResource.add({name: 'HI'});
expect(controller.folderNameExists('hi')).toBe(true);
+ expect(controller.folderNameExists('HI')).toBe(true);
+ }));
+
+
+ it('should create a feed with a folderId', inject(function ($controller) {
+ var FeedResource = {
+ create: jasmine.createSpy('create').andCallFake(
+ function (url, folderId) {
+ return {
+ then: function (callback) {
+ callback({
+ url: url,
+ folderId: folderId
+ });
+ }
+ };
+ })
+ };
+
+ var Publisher = {
+ publishAll: jasmine.createSpy('publishAll')
+ };
+
+ var ctrl = $controller('NavigationController', {
+ FeedResource: FeedResource,
+ Publisher: Publisher
+ });
+
+ var feed = {
+ url: 'test',
+ folderId: 3
+ };
+
+ ctrl.createFeed(feed);
+
+ expect(ctrl.newFolder).toBe(false);
+ expect(FeedResource.create).toHaveBeenCalledWith('test', 3,
+ undefined);
+ expect(Publisher.publishAll).toHaveBeenCalledWith({
+ url: 'test',
+ folderId: 3
+ });
+ expect(feed.url).toBe('');
+ }));
+
+
+ it('should create a feed with a foldername', inject(function ($controller) {
+
+ var FeedResource = {
+ create: jasmine.createSpy('create').andCallFake(
+ function (url, folderId) {
+ return {
+ then: function (callback) {
+ callback({
+ url: url,
+ folderId: folderId
+ });
+ }
+ };
+ })
+ };
+
+ var FolderResource = {
+ create: jasmine.createSpy('create').andCallFake(
+ function (folder) {
+ return {
+ then: function (callback) {
+ callback({
+ name: folder
+ });
+ }
+ };
+ })
+ };
+
+ var Publisher = {
+ publishAll: jasmine.createSpy('publishAll')
+ };
+
+ var ctrl = $controller('NavigationController', {
+ FeedResource: FeedResource,
+ Publisher: Publisher,
+ FolderResource: FolderResource
+ });
+
+ var feed = {
+ url: 'test',
+ folder: 'john'
+ };
+
+ ctrl.createFeed(feed);
+
+ expect(ctrl.newFolder).toBe(false);
+ expect(FeedResource.create).toHaveBeenCalledWith('test', 'john',
+ undefined);
+ expect(FolderResource.create).toHaveBeenCalledWith('john');
+ expect(Publisher.publishAll).toHaveBeenCalledWith({
+ url: 'test',
+ folderId: 'john'
+ });
+ expect(Publisher.publishAll).toHaveBeenCalledWith({
+ name: 'john'
+ });
+ expect(feed.url).toBe('');
+ expect(feed.folder).toBe('');
+ expect(feed.folderId).toBe('john');
+ }));
+
+
+ it('should create a folder', inject(function ($controller) {
+ var FolderResource = {
+ create: jasmine.createSpy('create').andCallFake(
+ function (folder) {
+ return {
+ then: function (callback) {
+ callback({
+ name: folder
+ });
+ }
+ };
+ })
+ };
+
+ var Publisher = {
+ publishAll: jasmine.createSpy('publishAll')
+ };
+
+ var ctrl = $controller('NavigationController', {
+ Publisher: Publisher,
+ FolderResource: FolderResource
+ });
+
+ var folder = {
+ name: 'test',
+ };
+
+ ctrl.createFolder(folder);
+
+ expect(FolderResource.create).toHaveBeenCalledWith('test');
+ expect(Publisher.publishAll).toHaveBeenCalledWith({
+ name: 'test'
+ });
+ expect(folder.name).toBe('');
}));
+
+ it('should move a folder', inject(function ($controller) {
+ var FeedResource = {
+ move: jasmine.createSpy('move')
+ };
+
+ var ctrl = $controller('NavigationController', {
+ FeedResource: FeedResource
+ });
+
+ ctrl.moveFeed(1, 3);
+
+ expect(FeedResource.move).toHaveBeenCalledWith(1, 3);
+ }));
});
diff --git a/js/tests/unit/service/FeedResourceSpec.js b/js/tests/unit/service/FeedResourceSpec.js
index 839ae650d..4b0f291f8 100644
--- a/js/tests/unit/service/FeedResourceSpec.js
+++ b/js/tests/unit/service/FeedResourceSpec.js
@@ -138,15 +138,15 @@ describe('FeedResource', function () {
it ('should move a feed', inject(function (FeedResource) {
- http.expectPOST('base/feeds/3/move', {
+ http.expectPOST('base/feeds/2/move', {
parentFolderId: 5
}).respond(200, {});
- FeedResource.move('1sye', 5);
+ FeedResource.move(2, 5);
http.flush();
- expect(FeedResource.get('1sye').folderId).toBe(5);
+ expect(FeedResource.get('sye').folderId).toBe(5);
}));
@@ -165,6 +165,40 @@ describe('FeedResource', function () {
}));
+ it ('should display a feed error', inject(function (FeedResource) {
+ http.expectPOST('base/feeds', {
+ parentFolderId: 5,
+ url: 'hey',
+ title: 'ABC'
+ }).respond(400, {message: 'noo'});
+
+ FeedResource.create('hey', 5, 'abc');
+
+ http.flush();
+
+ expect(FeedResource.get('hey').error).toBe('noo');
+ expect(FeedResource.get('hey').faviconLink).toBe('');
+ }));
+
+
+ it ('should create a feed with no folder', inject(function (FeedResource) {
+ http.expectPOST('base/feeds', {
+ parentFolderId: 0,
+ url: 'hey',
+ title: 'ABC'
+ }).respond(200, {});
+
+ FeedResource.create('hey', undefined, 'abc');
+
+ http.flush();
+
+ expect(FeedResource.get('hey').folderId).toBe(0);
+ expect(FeedResource.get('hey').faviconLink).toBe(
+ '/base/apps/news/css/loading.gif');
+ }));
+
+
+
it ('should not create a feed if it exists', inject(function (
FeedResource) {
http.expectPOST('base/feeds', {
diff --git a/js/tests/unit/service/FolderResourceSpec.js b/js/tests/unit/service/FolderResourceSpec.js
index 01858bbc6..2a9108282 100644
--- a/js/tests/unit/service/FolderResourceSpec.js
+++ b/js/tests/unit/service/FolderResourceSpec.js
@@ -58,20 +58,6 @@ describe('FolderResource', function () {
}));
- it ('should not rename a folder if it exists', inject(function (
- FolderResource) {
- http.expectPOST('base/folders/1/rename', {
- folderName: 'SYE'
- }).respond(200, {});
-
- FolderResource.rename('ye', 'sye');
-
- http.flush();
-
- expect(FolderResource.get('ye').id).toBe(1);
- }));
-
-
it ('should open a folder', inject(function (FolderResource) {
http.expectPOST('base/folders/3/open', {
folderId: 3,
@@ -99,17 +85,16 @@ describe('FolderResource', function () {
}));
- it ('should not create a folder if it exists', inject(function (
- FolderResource) {
+ it ('should set a folder error message', inject(function (FolderResource) {
http.expectPOST('base/folders', {
- folderName: 'SYE'
- }).respond(200, {});
+ folderName: 'HEY'
+ }).respond(400, {message: 'carramba'});
- FolderResource.create('SYE');
+ FolderResource.create('hey');
http.flush();
- expect(FolderResource.size()).toBe(3);
+ expect(FolderResource.get('HEY').error).toBe('carramba');
}));
diff --git a/js/tests/unit/stubs/OC.js b/js/tests/unit/stubs/OC.js
index 387469469..495c64dee 100644
--- a/js/tests/unit/stubs/OC.js
+++ b/js/tests/unit/stubs/OC.js
@@ -8,9 +8,9 @@
* @copyright Bernhard Posselt 2012, 2014
*/
window.OC = {
- generateUrl: function () {
+ generateUrl: function (url) {
'use strict';
- return '';
+ return '/base' + url;
}
}; \ No newline at end of file