diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-15 03:00:53 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-15 03:00:53 +0200 |
commit | 3ce894af1e72c9488b8cb3340fd61656122f7d50 (patch) | |
tree | a603121e8b1e860201370399f8095121cd9c6bf7 /js/tests | |
parent | 10d76fff64363ea59d916b550854cf3540dadfbc (diff) |
use markdown, refactor js
Diffstat (limited to 'js/tests')
45 files changed, 0 insertions, 5064 deletions
diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee deleted file mode 100644 index 5f35830cb..000000000 --- a/js/tests/controllers/feedcontrollerSpec.coffee +++ /dev/null @@ -1,216 +0,0 @@ -### - -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/>. - -### - - -describe 'FeedController', -> - - beforeEach module 'News' - - beforeEach module ($provide) => - @imagePath = jasmine.createSpy('imagePath') - @utils = - imagePath: @imagePath - $provide.value 'Utils', @utils - - @persistence = {} - - $provide.value 'Persistence', @persistence - return - - beforeEach inject ($controller, @FolderBusinessLayer, @FeedBusinessLayer, - $rootScope, @unreadCountFormatter, @FeedModel, - @SubscriptionsBusinessLayer, @StarredBusinessLayer, - @$window, @_ExistsError, @FolderModel, @FeedType) => - @scope = $rootScope.$new() - replace = - $scope: @scope - - @$window.document.title = '' - - @controller = $controller('FeedController', replace) - - - it 'isAddingFolder should return false in the beginning', => - expect(@scope.isAddingFolder()).toBeFalsy() - - - it 'isAddingFeed should return false in the beginning', => - expect(@scope.isAddingFeed()).toBeFalsy() - - - it 'should make unreadCountFormatter available', => - expect(@scope.unreadCountFormatter).toBe(@unreadCountFormatter) - - - it 'should make FeedBusinessLayer available', => - expect(@scope.feedBusinessLayer).toBe(@FeedBusinessLayer) - - - it 'should make FolderBusinessLayer available', => - expect(@scope.folderBusinessLayer).toBe(@FolderBusinessLayer) - - - it 'should make SubscriptionsBusinessLayer available', => - expect(@scope.subscriptionsBusinessLayer).toBe( - @SubscriptionsBusinessLayer) - - - it 'should make StarredBusinessLayer available', => - expect(@scope.starredBusinessLayer).toBe(@StarredBusinessLayer) - - - it 'should set the window title to the total unread count', => - @scope.translations = - appName: 'News' - expect(@$window.document.title).toBe('') - - @scope.getTotalUnreadCount() - expect(@$window.document.title).toBe('News | ownCloud') - - item = {id: 3, unreadCount: 5, faviconLink: 'test', url: 'hi'} - @FeedModel.add(item) - @scope.getTotalUnreadCount() - - expect(@$window.document.title).toBe('News (5) | ownCloud') - - - it 'should show 99+ if in window title when more than 99 unread count', => - @scope.translations = - appName: 'News' - item = {id: 3, unreadCount: 1, faviconLink: 'test', url: 'hi'} - item1 = {id: 5, unreadCount: 999, faviconLink: 'test', url: 'his'} - @FeedModel.add(item) - @FeedModel.add(item1) - - @scope.getTotalUnreadCount() - - expect(@$window.document.title).toBe('News (999+) | ownCloud') - - - it 'should move a feed if moveFeedToFolder is broadcasted', => - item = {id: 3, unreadCount: 1, faviconLink: 'test', url: 'hi'} - @FeedModel.add(item) - @persistence.moveFeed = jasmine.createSpy('move feed') - @scope.$broadcast 'moveFeedToFolder', {feedId: 3, folderId: 1} - - expect(@persistence.moveFeed).toHaveBeenCalledWith(3, 1) - - - it 'should set isAddingFolder to true if there were no problems', => - @persistence.createFolder = jasmine.createSpy('create') - @scope.addFolder(' Ola') - expect(@scope.isAddingFolder()).toBe(true) - - - it 'should set isAddingFolder to false after a failed request', => - @persistence.createFolder = jasmine.createSpy('create') - @persistence.createFolder.andCallFake (name, id, onSuccess, onFailure) -> - onFailure() - - @scope.addFolder(' Ola') - expect(@scope.isAddingFolder()).toBe(false) - - - it 'should show an error if the folder exists and reset the input', => - @FolderBusinessLayer.create = jasmine.createSpy('create') - @FolderBusinessLayer.create.andCallFake => - throw new @_ExistsError('ye') - - @scope.addFolder(' Ola') - - expect(@scope.folderExistsError).toBe(true) - expect(@scope.isAddingFolder()).toBe(false) - - - it 'should reset the add folder form and set the created as selected', => - @persistence.createFolder = jasmine.createSpy('create') - data = - folders: [ - {id: 3, name: 'soba'} - ] - @persistence.createFolder.andCallFake (id, parent, onSuccess) => - @FolderModel.handle(data.folders) - onSuccess(data) - - @scope.addFolder(' Soba') - - expect(@scope.folderName).toBe('') - expect(@scope.addNewFolder).toBe(false) - expect(@scope.isAddingFolder()).toBe(false) - expect(@scope.folderId.name).toBe('soba') - - - it 'should set isAddingFeed to true if there were no problems', => - @persistence.createFeed = jasmine.createSpy('create') - @scope.addFeed('Ola') - expect(@scope.isAddingFeed()).toBe(true) - - - it 'should set isAddingFeed to false after a failed request', => - @persistence.createFeed = jasmine.createSpy('create') - @persistence.createFeed.andCallFake (name, id, onSuccess, onFailure) -> - onFailure() - - @scope.addFolder(' Ola') - expect(@scope.isAddingFeed()).toBe(false) - - - it 'should show an error if the feed exists and reset the input', => - @FeedBusinessLayer.create = jasmine.createSpy('create') - @FeedBusinessLayer.create.andCallFake => - throw new @_ExistsError('ye') - - @scope.addFeed(' Ola') - - expect(@scope.feedExistsError).toBe(true) - expect(@scope.isAddingFeed()).toBe(false) - - - it 'should open the parent folder of the added feed', => - item = {opened: false, id: 3, name: 'john'} - @FolderModel.add(item) - - @scope.addFeed(' Ola', 3) - - expect(item.opened).toBe(true) - - - it 'should reset the add feed form and load the added feed', => - @persistence.createFeed = jasmine.createSpy('create') - @persistence.getItems = jasmine.createSpy('load') - - data = - feeds: [ - {id: 3, url: 'http://soba', title: 'hi'} - ] - status: 'success' - @persistence.createFeed.andCallFake (id, parent, onSuccess) => - @FeedModel.handle(data.feeds) - onSuccess(data) - - @scope.addFeed(' Soba') - - expect(@scope.feedUrl).toBe('') - expect(@scope.isAddingFeed()).toBe(false) - expect(@persistence.getItems).toHaveBeenCalledWith( - @FeedType.Feed, 3, 0, jasmine.any(Function) - )
\ No newline at end of file diff --git a/js/tests/controllers/itemcontrollerSpec.coffee b/js/tests/controllers/itemcontrollerSpec.coffee deleted file mode 100644 index 7b2c50cb9..000000000 --- a/js/tests/controllers/itemcontrollerSpec.coffee +++ /dev/null @@ -1,193 +0,0 @@ -### - -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/>. - -### - - -describe 'ItemController', -> - - - beforeEach module 'News' - - beforeEach module ($provide) => - @imagePath = jasmine.createSpy('imagePath') - @utils = - imagePath: @imagePath - $provide.value 'Utils', @utils - - @persistence = - getItems: -> - readItem: -> - $provide.value 'Persistence', @persistence - return - - beforeEach inject ($controller, @ItemBusinessLayer, @FeedBusinessLayer, - $rootScope, @FeedLoading, @AutoPageLoading, @FeedModel, @ItemModel, - @ActiveFeed, @FeedType, @NewestItem, @Compact) => - - @ActiveFeed.handle({type: @FeedType.Folder, id: 3}) - @scope = $rootScope.$new() - replace = - $scope: @scope - @controller = $controller('ItemController', replace) - - - it 'should make ItemBusinessLayer availabe', => - expect(@scope.itemBusinessLayer).toBe(@ItemBusinessLayer) - - - it 'should make FeedBusinessLayer availabe', => - expect(@scope.feedBusinessLayer).toBe(@FeedBusinessLayer) - - - it 'should make feedloading available', => - expect(@scope.isLoading()).toBe(false) - @FeedLoading.increase() - expect(@scope.isLoading()).toBe(true) - - - it 'should make autopagin available', => - expect(@scope.isAutoPaging()).toBe(false) - @AutoPageLoading.increase() - expect(@scope.isAutoPaging()).toBe(true) - - - it 'should return the feedtitle', => - item = {id: 3, faviconLink: null, url: 'hi', title: 'heheh'} - @FeedModel.add(item) - - expect(@scope.getFeedTitle(3)).toBe(item.title) - - - it 'should return no value if feedtitle is not found', => - expect(@scope.getFeedTitle(3)).toBe('') - - - it 'should return no value if relative date gets no value', => - expect(@scope.getRelativeDate()).toBe('') - - - it 'should set an item read on readItem broadcast', => - item1 = {id: 4, guidHash: 'abc', feedId: 3} - @ItemModel.add(item1) - item1.setUnread() - - expect(item1.isRead()).toBe(false) - @scope.$broadcast 'readItem', 4 - - expect(item1.isRead()).toBe(true) - - - it 'should not autopage if there are no items', => - @persistence.getItems = jasmine.createSpy('getItems') - @scope.$broadcast 'autoPage' - expect(@persistence.getItems).not.toHaveBeenCalled() - - - it 'should autoPage with the lowest Item Id', => - @NewestItem.handle(25) - - @persistence.getItems = jasmine.createSpy('getItems') - item1 = {id: 4, guidHash: 'abc', feedId: 3} - @ItemModel.add(item1) - - item1 = {id: 3, guidHash: 'abcd', feedId: 3} - @ItemModel.add(item1) - - item1 = {id: 6, guidHash: 'abce', feedId: 1} - @ItemModel.add(item1) - - @scope.$broadcast 'autoPage' - expect(@persistence.getItems).toHaveBeenCalledWith( - @FeedType.Folder, 3, 3, jasmine.any(Function) - ) - - - it 'should not prevent autopaging if there are no items', => - @scope.$broadcast 'autoPage' - @persistence.getItems = jasmine.createSpy('getItems') - - item1 = {id: 3, guidHash: 'abcd', feedId: 3} - @ItemModel.add(item1) - - @scope.$broadcast 'autoPage' - expect(@persistence.getItems).toHaveBeenCalledWith( - @FeedType.Folder, 3, 3, jasmine.any(Function) - ) - - - it 'should not send multiple autopage requests at once', => - @persistence.getItems = jasmine.createSpy('getItems') - item1 = {id: 3, guidHash: 'abcd', feedId: 3} - @ItemModel.add(item1) - - @scope.$broadcast 'autoPage' - - item1 = {id: 2, guidHash: 'abcd', feedId: 3} - @ItemModel.add(item1) - - @scope.$broadcast 'autoPage' - - expect(@persistence.getItems).not.toHaveBeenCalledWith( - @FeedType.Folder, 2, 3, jasmine.any(Function) - ) - - - it 'should allow another autopaging request if the last one finished', => - @NewestItem.handle(25) - @persistence.getItems = jasmine.createSpy('getItems') - @persistence.getItems.andCallFake (type, id, offset, - onSuccess) -> - onSuccess() - - item1 = {id: 3, guidHash: 'abcd', feedId: 3} - @ItemModel.add(item1) - - @scope.$broadcast 'autoPage' - - item1 = {id: 2, guidHash: 'abcd', feedId: 3} - @ItemModel.add(item1) - - @scope.$broadcast 'autoPage' - - expect(@persistence.getItems.callCount).toBe(2) - - - it 'should set refresh to true when pull to refresh is activated', => - @ItemBusinessLayer.loadNew = -> - - @scope.loadNew() - expect(@scope.refresh).toBe(true) - - - it 'should set refresh to false after load next was successful', => - @ItemBusinessLayer.loadNew = jasmine.createSpy('loadNew') - @ItemBusinessLayer.loadNew.andCallFake (callback) -> - callback() - - @scope.loadNew() - expect(@scope.refresh).toBe(false) - - - it 'should bind the compact object', => - expect(@scope.isCompactView()).toBe(false) - @Compact.handle(true) - expect(@scope.isCompactView()).toBe(true) - diff --git a/js/tests/controllers/settingscontrollerSpec.coffee b/js/tests/controllers/settingscontrollerSpec.coffee deleted file mode 100644 index bdf1f2bc2..000000000 --- a/js/tests/controllers/settingscontrollerSpec.coffee +++ /dev/null @@ -1,101 +0,0 @@ -### - -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/>. - -### - - -describe 'SettingsController', -> - - beforeEach module 'News' - - beforeEach module ($provide) => - @persistence = {} - $provide.value 'Persistence', @persistence - return - - beforeEach inject ($controller, @ShowAll, @Compact) => - @scope = {} - @replace = - '$scope': @scope - 'FolderBusinessLayer': - import: jasmine.createSpy('import') - 'FeedBusinessLayer': - importArticles: jasmine.createSpy('import') - 'Compact': @Compact - @controller = $controller('SettingsController', @replace) - - - it 'should make FeedBl available', => - expect(@scope.feedBl).toBe(@FeedBl) - - - it 'should show an error if the xml import failed', => - xml = 'test' - @replace.FolderBusinessLayer.import.andCallFake -> - throw new Error() - - @scope.import(xml) - - expect(@replace.FolderBusinessLayer.import).toHaveBeenCalledWith(xml) - expect(@scope.error).toBe(true) - - - it 'should set showall to true if importing', => - xml = 'test' - - @scope.import(xml) - - expect(@ShowAll.getShowAll()).toBe(true) - - - it 'should set loading to true if importing json', => - json = "[\"test\"]" - - @scope.importArticles(json) - expect(@scope.loading).toBe(true) - - - it 'should show an error if the json import failed', => - json = 'test' - - @scope.importArticles(json) - - expect(@scope.jsonError).toBe(true) - - - it 'should import json', => - json = "{\"test\": \"abc\"}" - - @scope.importArticles(json) - - expected = JSON.parse(json) - expect(@replace.FeedBusinessLayer.importArticles).toHaveBeenCalledWith( - expected, jasmine.any(Function) - ) - - - it 'should set the compact view', => - @persistence.userSettingsSetCompact = jasmine.createSpy('compact') - - @Compact.handle(false) - @scope.setCompactView() - - expect(@persistence.userSettingsSetCompact).toHaveBeenCalledWith(true) - expect(@scope.isCompactView()).toBe(true)
\ No newline at end of file diff --git a/js/tests/directives/clickfocusSpec.coffee b/js/tests/directives/clickfocusSpec.coffee deleted file mode 100644 index 6c2c79b43..000000000 --- a/js/tests/directives/clickfocusSpec.coffee +++ /dev/null @@ -1,73 +0,0 @@ -### - -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/>. - -### - -describe 'ocClickFocus', -> - - beforeEach module 'News' - - - beforeEach inject ($rootScope, $compile, @$timeout) => - @$rootScope = $rootScope - @$compile = $compile - @host = $('<div id="host"></div>') - $('body').append(@host) - $.fx.off = true - - - it 'should focus element', => - elm = '<a href="#" ' + - 'oc-click-focus="{selector: \'#shouldfocus\'}" ' + - 'id="clicker"' + - 'onclick="this.href=\'hi\'">test</a>' + - '<div><input id="shouldfocus" type="text" /></div>' - @elm = angular.element(elm) - scope = @$rootScope - @$compile(@elm)(scope) - scope.$digest() - @host.append(@elm) - - $(@host).find('#clicker').trigger 'click' - focused = document.activeElement == $(@host).find('#shouldfocus').get(0) - expect(focused).toBe(true) - - - it 'should execute the function when a timeout is being used', => - elm = '<a href="#" ' + - 'oc-click-focus="{selector: \'#shouldfocus\', ' + - 'timeout: 3000}" ' + - 'id="clicker"' + - 'onclick="this.href=\'hi\'">test</a>' + - '<div><input id="shouldfocus" type="text" /></div>' - @elm = angular.element(elm) - scope = @$rootScope - @$compile(@elm)(scope) - scope.$digest() - @host.append(@elm) - - $(@host).find('#clicker').trigger 'click' - @$timeout.flush() - focused = document.activeElement == $(@host).find('#shouldfocus').get(0) - expect(focused).toBe(true) - - - afterEach => - @host.remove()
\ No newline at end of file diff --git a/js/tests/directives/clickslidetoggleSpec.coffee b/js/tests/directives/clickslidetoggleSpec.coffee deleted file mode 100644 index 0af13ee4e..000000000 --- a/js/tests/directives/clickslidetoggleSpec.coffee +++ /dev/null @@ -1,128 +0,0 @@ -### - -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/>. - -### - -describe 'ocClickSlideToggle', -> - - beforeEach module 'News' - - - beforeEach inject ($rootScope, $compile) => - @$rootScope = $rootScope - @$compile = $compile - @host = $('<div id="host"></div>') - $('body').append(@host) - $.fx.off = true - - - @setOptions = (options) => - if angular.isDefined(options.selector) - json = JSON.stringify(options) - optionsString = json.replace(/\"/g, '\'') - else - optionsString = "" - - elm = '<div>' + - '<div style="display: none;" id="a" ' + - 'oc-click-slide-toggle="' + optionsString + '"></div>' + - '<div style="display: none;" id="b"></div>' + - '<div style="display: none;" id="c"></div>' + - '</div>' - - @elm = angular.element(elm) - scope = @$root |