diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-07 15:12:39 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-07 15:12:39 +0200 |
commit | ef1ed919da40b33bbc3f2fc8d94daff7e355dab6 (patch) | |
tree | 1a8efccd0e5707219503074a8864128632ab55bb /js/tests | |
parent | 608ffd302640fb3fa990f138fa343527d3ce83ab (diff) |
fix #75
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/unit/controller/NavigationControllerSpec.js | 114 | ||||
-rw-r--r-- | js/tests/unit/service/FolderResourceSpec.js | 10 |
2 files changed, 122 insertions, 2 deletions
diff --git a/js/tests/unit/controller/NavigationControllerSpec.js b/js/tests/unit/controller/NavigationControllerSpec.js index c3c34bad6..1c23c35f1 100644 --- a/js/tests/unit/controller/NavigationControllerSpec.js +++ b/js/tests/unit/controller/NavigationControllerSpec.js @@ -343,7 +343,7 @@ describe('NavigationController', function () { ctrl.createFeed(feed); - expect(ctrl.newFolder).toBe(false); + expect(ctrl.showNewFolder).toBe(false); expect(FeedResource.create).toHaveBeenCalledWith('test', 3, undefined); expect(Publisher.publishAll).toHaveBeenCalledWith({feeds: [{ @@ -419,7 +419,7 @@ describe('NavigationController', function () { ctrl.createFeed(feed); - expect(ctrl.newFolder).toBe(false); + expect(ctrl.showNewFolder).toBe(false); expect(FeedResource.create).toHaveBeenCalledWith('test', 19, undefined); expect(FolderResource.create).toHaveBeenCalledWith('john'); @@ -885,5 +885,115 @@ describe('NavigationController', function () { expect(FeedResource.deleteFolder).toHaveBeenCalledWith(3); })); + var createRoute = function (type, id) { + return { + current: { + $$route: { + type: type + }, + params: { + id: id + } + } + }; + }; + + it ('should select a folder on route change for add feed section', + inject(function ($controller, FolderResource, FeedResource, $rootScope, + FEED_TYPE) { + + FolderResource.add({id: 3, name: 'test'}); + var route = createRoute(FEED_TYPE.FOLDER, 3); + var ctrl = $controller('NavigationController', { + $route: route + }); + + expect(ctrl.feed.existingFolder).toBe(undefined); + + $rootScope.$broadcast('$routeChangeSuccess'); + + expect(ctrl.feed.existingFolder).toBe(FolderResource.getById(3)); + })); + + + it ('should select a folder on route change for add feed section if a sub' + + ' feed is selected', + inject(function ($controller, FolderResource, FeedResource, $rootScope, + FEED_TYPE) { + + FeedResource.add({id: 2, url: 'http://test.com', folderId: 3}); + FolderResource.add({id: 3, name: 'test'}); + var route = createRoute(FEED_TYPE.FEED, 2); + var ctrl = $controller('NavigationController', { + $route: route + }); + + expect(ctrl.feed.existingFolder).toBe(undefined); + + $rootScope.$broadcast('$routeChangeSuccess'); + + expect(ctrl.feed.existingFolder).toBe(FolderResource.getById(3)); + })); + + + it ('should not select a folder on route change for add feed section if ' + + 'no subfeed is selected', + inject(function ($controller, FolderResource, FeedResource, $rootScope, + FEED_TYPE) { + + FeedResource.add({id: 2, url: 'http://test.com', folderId: 2}); + FolderResource.add({id: 3, name: 'test'}); + var route = createRoute(FEED_TYPE.FEED, 2); + var ctrl = $controller('NavigationController', { + $route: route + }); + + expect(ctrl.feed.existingFolder).toBe(undefined); + + $rootScope.$broadcast('$routeChangeSuccess'); + + expect(ctrl.feed.existingFolder).toBe(undefined); + })); + + + it ('should not select a folder on route change for add feed section if ' + + 'starred feed is selected', + inject(function ($controller, FolderResource, FeedResource, $rootScope, + FEED_TYPE) { + + FeedResource.add({id: 2, url: 'http://test.com', folderId: 3}); + FolderResource.add({id: 3, name: 'test'}); + var route = createRoute(FEED_TYPE.STARRED); + var ctrl = $controller('NavigationController', { + $route: route + }); + + expect(ctrl.feed.existingFolder).toBe(undefined); + + $rootScope.$broadcast('$routeChangeSuccess'); + + expect(ctrl.feed.existingFolder).toBe(undefined); + })); + + + it ('should not select a folder on route change for add feed section if ' + + 'all articles feed is selected', + inject(function ($controller, FolderResource, FeedResource, $rootScope, + FEED_TYPE) { + + FeedResource.add({id: 2, url: 'http://test.com', folderId: 3}); + FolderResource.add({id: 3, name: 'test'}); + var route = createRoute(FEED_TYPE.SUBSCRIPTIONS); + var ctrl = $controller('NavigationController', { + $route: route + }); + + expect(ctrl.feed.existingFolder).toBe(undefined); + + $rootScope.$broadcast('$routeChangeSuccess'); + + expect(ctrl.feed.existingFolder).toBe(undefined); + })); + }); diff --git a/js/tests/unit/service/FolderResourceSpec.js b/js/tests/unit/service/FolderResourceSpec.js index ee6485121..cfed886a0 100644 --- a/js/tests/unit/service/FolderResourceSpec.js +++ b/js/tests/unit/service/FolderResourceSpec.js @@ -135,4 +135,14 @@ describe('FolderResource', function () { })); + it ('should get a folder by id', inject(function (FolderResource) { + expect(FolderResource.getById(1).name).toBe('ye'); + })); + + + it ('should delete a folder and its id cache', inject( + function (FolderResource) { + FolderResource.delete('ye'); + expect(FolderResource.getById(1)).toBe(undefined); + })); }); |