summaryrefslogtreecommitdiffstats
path: root/js/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-30 22:19:26 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-30 22:19:26 +0200
commit35d0d8750e579c40a05f46c0e29cafce9123ae60 (patch)
tree03a2641ca8fed4baa7682cc5c87ddc47b7b99df8 /js/tests
parente9a2c6bac0dceeffb86e9fb50802af945555d565 (diff)
more additions
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/controller/NavigationControllerSpec.js13
-rw-r--r--js/tests/unit/service/FeedResourceSpec.js103
-rw-r--r--js/tests/unit/service/FolderResourceSpec.js133
3 files changed, 246 insertions, 3 deletions
diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js
index 433a40e3f..adefd157f 100644
--- a/js/tests/unit/controller/NavigationControllerSpec.js
+++ b/js/tests/unit/controller/NavigationControllerSpec.js
@@ -111,6 +111,19 @@ describe('NavigationController', () => {
SettingsResource.set('showAll', true);
expect(ctrl.isShowAll()).toBe(true);
+ }));
+
+ it('should get all of folder', inject((FeedResource, $controller) => {
+ let ctrl = $controller('NavigationController', {
+ FeedResource: FeedResource,
+ });
+
+ FeedResource.getByFolderId = jasmine.createSpy('getByFolderId');
+ ctrl.getFeedsOfFolder(3);
+
+ expect(FeedResource.getByFolderId).toHaveBeenCalledWith(3);
}));
+
+
}); \ No newline at end of file
diff --git a/js/tests/unit/service/FeedResourceSpec.js b/js/tests/unit/service/FeedResourceSpec.js
index 5187435f0..a37ff42f3 100644
--- a/js/tests/unit/service/FeedResourceSpec.js
+++ b/js/tests/unit/service/FeedResourceSpec.js
@@ -10,19 +10,21 @@
describe('FeedResource', () => {
'use strict';
- let resource;
+ let resource,
+ http;
beforeEach(module('News', ($provide) => {
$provide.value('BASE_URL', 'base');
}));
- beforeEach(inject((FeedResource) => {
+ beforeEach(inject((FeedResource, $httpBackend) => {
resource = FeedResource;
+ http = $httpBackend;
FeedResource.receive([
{id: 1, folderId: 3, url: 'ye', unreadCount: 45},
{id: 2, folderId: 4, url: 'sye', unreadCount: 25},
- {id: 3, folderId: 3, url: '1sye', unreadCount: 0}
+ {id: 3, folderId: 3, title: 'hore', url: '1sye', unreadCount: 0}
]);
}));
@@ -104,4 +106,99 @@ describe('FeedResource', () => {
expect(FeedResource.getUnreadCount()).toBe(68);
}));
+
+
+ it ('should delete a feed', inject((FeedResource) => {
+ http.expectDELETE('base/feeds/1').respond(200, {});
+
+ FeedResource.delete('ye');
+
+ http.flush();
+
+ expect(FeedResource.size()).toBe(2);
+ }));
+
+
+ it ('should rename a feed', inject((FeedResource) => {
+ http.expectPOST('base/feeds/3/rename', {
+ feedTitle: 'heho'
+ }).respond(200, {});
+
+ FeedResource.rename('1sye', 'heho');
+
+ http.flush();
+
+ expect(FeedResource.get('1sye').title).toBe('heho');
+ }));
+
+
+ it ('should move a feed', inject((FeedResource) => {
+ http.expectPOST('base/feeds/3/move', {
+ parentFolderId: 5
+ }).respond(200, {});
+
+ FeedResource.move('1sye', 5);
+
+ http.flush();
+
+ expect(FeedResource.get('1sye').folderId).toBe(5);
+ }));
+
+
+ it ('should create a feed', inject((FeedResource) => {
+ http.expectPOST('base/feeds', {
+ parentFolderId: 5,
+ url: 'hey',
+ title: 'ABC'
+ }).respond(200, {});
+
+ FeedResource.create('hey', 5, 'abc');
+
+ http.flush();
+
+ expect(FeedResource.get('hey').folderId).toBe(5);
+ }));
+
+
+ it ('should not create a feed if it exists', inject((FeedResource) => {
+ http.expectPOST('base/feeds', {
+ parentFolderId: 5,
+ url: 'ye',
+ title: 'ABC'
+ }).respond(200, {});
+
+ FeedResource.create('ye', 5, 'abc');
+
+ http.flush();
+
+ expect(FeedResource.size()).toBe(3);
+ }));
+
+
+ it ('should undo a delete folder', inject((FeedResource) => {
+ http.expectDELETE('base/feeds/1').respond(200, {});
+
+ FeedResource.delete('ye');
+
+ http.flush();
+
+
+ http.expectPOST('base/feeds/1/restore').respond(200, {});
+
+ FeedResource.undoDelete();
+
+ http.flush();
+
+ expect(FeedResource.get('ye').id).toBe(1);
+ }));
+
+
+
+
+ afterEach(() => {
+ http.verifyNoOutstandingExpectation();
+ http.verifyNoOutstandingRequest();
+ });
+
+
});
diff --git a/js/tests/unit/service/FolderResourceSpec.js b/js/tests/unit/service/FolderResourceSpec.js
new file mode 100644
index 000000000..db8312232
--- /dev/null
+++ b/js/tests/unit/service/FolderResourceSpec.js
@@ -0,0 +1,133 @@
+/**
+ * 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('FolderResource', () => {
+ 'use strict';
+
+ let resource,
+ http;
+
+ beforeEach(module('News', ($provide) => {
+ $provide.value('BASE_URL', 'base');
+ }));
+
+
+ beforeEach(inject((FolderResource, $httpBackend) => {
+ resource = FolderResource;
+ http = $httpBackend;
+ FolderResource.receive([
+ {id: 1, name: 'ye'},
+ {id: 2, name: 'SYE'},
+ {id: 3, name: 'hore', opened: true}
+ ]);
+ }));
+
+
+ it ('should delete a folder', inject((FolderResource) => {
+ http.expectDELETE('base/folders/1').respond(200, {});
+
+ FolderResource.delete('ye');
+
+ http.flush();
+
+ expect(FolderResource.size()).toBe(2);
+ }));
+
+
+ it ('should rename a folder', inject((FolderResource) => {
+ http.expectPOST('base/folders/1/rename', {
+ folderName: 'HEHO'
+ }).respond(200, {});
+
+ FolderResource.rename('ye', 'heho');
+
+ http.flush();
+
+ expect(FolderResource.get('HEHO').id).toBe(1);
+ }));
+
+
+ it ('should not rename a folder if it exists', inject((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((FolderResource) => {
+ http.expectPOST('base/folders/3/open', {
+ folderId: 3,
+ open: false,
+ }).respond(200, {});
+
+ FolderResource.toggleOpen('hore');
+
+ http.flush();
+
+ expect(FolderResource.get('hore').opened).toBe(false);
+ }));
+
+
+ it ('should create a folder', inject((FolderResource) => {
+ http.expectPOST('base/folders', {
+ folderName: 'HEY'
+ }).respond(200, {});
+
+ FolderResource.create('hey');
+
+ http.flush();
+
+ expect(FolderResource.size()).toBe(4);
+ }));
+
+
+ it ('should not create a folder if it exists', inject((FolderResource) => {
+ http.expectPOST('base/folders', {
+ folderName: 'SYE'
+ }).respond(200, {});
+
+ FolderResource.create('SYE');
+
+ http.flush();
+
+ expect(FolderResource.size()).toBe(3);
+ }));
+
+
+ it ('should undo a delete folder', inject((FolderResource) => {
+ http.expectDELETE('base/folders/1').respond(200, {});
+
+ FolderResource.delete('ye');
+
+ http.flush();
+
+
+ http.expectPOST('base/folders/1/restore').respond(200, {});
+
+ FolderResource.undoDelete();
+
+ http.flush();
+
+ expect(FolderResource.get('ye').id).toBe(1);
+ }));
+
+
+ afterEach(() => {
+ http.verifyNoOutstandingExpectation();
+ http.verifyNoOutstandingRequest();
+ });
+
+
+});