diff options
Diffstat (limited to 'js/tests')
29 files changed, 2004 insertions, 35 deletions
diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee index 13ce1bb44..5f35830cb 100644 --- a/js/tests/controllers/feedcontrollerSpec.coffee +++ b/js/tests/controllers/feedcontrollerSpec.coffee @@ -144,13 +144,11 @@ describe 'FeedController', -> it 'should reset the add folder form and set the created as selected', => @persistence.createFolder = jasmine.createSpy('create') data = - data: - folders: [ - {id: 3, name: 'soba'} - ] - status: 'success' + folders: [ + {id: 3, name: 'soba'} + ] @persistence.createFolder.andCallFake (id, parent, onSuccess) => - @FolderModel.handle(data.data.folders) + @FolderModel.handle(data.folders) onSuccess(data) @scope.addFolder(' Soba') @@ -201,13 +199,12 @@ describe 'FeedController', -> @persistence.getItems = jasmine.createSpy('load') data = - data: - feeds: [ - {id: 3, url: 'http://soba', title: 'hi'} - ] + feeds: [ + {id: 3, url: 'http://soba', title: 'hi'} + ] status: 'success' @persistence.createFeed.andCallFake (id, parent, onSuccess) => - @FeedModel.handle(data.data.feeds) + @FeedModel.handle(data.feeds) onSuccess(data) @scope.addFeed(' Soba') diff --git a/js/tests/directives/clickfocusSpec.coffee b/js/tests/directives/clickfocusSpec.coffee new file mode 100644 index 000000000..6c2c79b43 --- /dev/null +++ b/js/tests/directives/clickfocusSpec.coffee @@ -0,0 +1,73 @@ +### + +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 new file mode 100644 index 000000000..0af13ee4e --- /dev/null +++ b/js/tests/directives/clickslidetoggleSpec.coffee @@ -0,0 +1,128 @@ +### + +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 = @$rootScope + @$compile(@elm)(scope) + scope.$digest() + @host.append(@elm) + + + it 'should not show div hidden divs', => + @setOptions({}) + expect(@elm.find('#a').is(':visible')).toBe(false) + expect(@elm.find('#b').is(':visible')).toBe(false) + expect(@elm.find('#c').is(':visible')).toBe(false) + + + it 'should slide up div on click', => + @setOptions({}) + a = @elm.find('#a') + a.trigger 'click' + + expect(a.is(':visible')).toBe(true) + + + + xit 'should slide up other element if selector is passed', => + # FIXME: run async + options = + selector: '#b' + + @setOptions(options) + + a = @elm.find('#a') + b = @elm.find('#b') + + a.trigger 'click' + expect(b.is(':visible')).toBe(true) + + + xit 'should hide div when other div was clicked', => + # FIXME: run async + options = + selector: '#b' + callback: => + @elm.find('#c').trigger 'click' + expect(@elm.find('#a').is(':animated')).toBe(true) + + @setOptions(options) + @elm.find('#a').trigger 'click' + + + xit 'should not hide current slid up element on click but others', => + # FIXME: run async + called = 0 + callback = => + if called == 2 + @elm.find('#c').trigger 'click' + expect(@elm.find('#b').is(':animated')).toBe(true) + expect(@elm.find('#c').is(':animated')).toBe(false) + else + called += 1 + + options = + selector: '#b' + callback: -> + callback() + @setOptions(options) + + options = + selector: '#c' + callback: -> + callback() + @setOptions(options) + + @elm.find('#a').trigger 'click' + + + + + afterEach => + @host.remove()
\ No newline at end of file diff --git a/js/tests/directives/draggableSpec.coffee b/js/tests/directives/draggableSpec.coffee new file mode 100644 index 000000000..ee5a479a2 --- /dev/null +++ b/js/tests/directives/draggableSpec.coffee @@ -0,0 +1,43 @@ +### + +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 'ocDraggable', -> + + beforeEach module 'News' + + beforeEach inject ($rootScope, $compile) => + @options = + revert: true + + optionsString = JSON.stringify(@options).replace(/\"/g, '\'') + @elm = angular.element('<div oc-draggable="' + optionsString + '"></div>') + scope = $rootScope + $compile(@elm)(scope) + scope.$digest() + + + it 'should bind jquery draggable', => + expect(@elm.is(':ui-draggable')).toBe(true) + + + it 'should bind options if passed', => + expect(@elm.data('ui-draggable').options.revert).toBe(true) diff --git a/js/tests/directives/forwardclickSpec.coffee b/js/tests/directives/forwardclickSpec.coffee new file mode 100644 index 000000000..5f2044b54 --- /dev/null +++ b/js/tests/directives/forwardclickSpec.coffee @@ -0,0 +1,71 @@ +### + +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 'ocForwardClick', -> + + beforeEach module 'News' + + + beforeEach inject ($rootScope, $compile) => + @$rootScope = $rootScope + @$compile = $compile + @host = $('<div id="host"></div>') + $('body').append(@host) + + + @setOptions = (options) => + if angular.isDefined(options.selector) + json = JSON.stringify(options) + optionsString = json.replace(/\"/g, '\'') + else + optionsString = "" + + elm = '<div>' + + '<div id="a" oc-forward-click="' + optionsString + '"></div>' + + '<input onclick="this.value=\'clicked\'" value="not-clicked" ' + + 'type="text" id="b" />' + + '</div>' + + @elm = angular.element(elm) + scope = @$rootScope + @$compile(@elm)(scope) + scope.$digest() + @host.append(@elm) + + + it 'should not forward clicks if no selector is given', => + options = {} + @setOptions(options) + @elm.find('#a').trigger('click') + expect(@elm.find('#b').val()).toBe('not-clicked') + + + it 'should forward click to item if selector is given', => + options = + selector: '#b' + @setOptions(options) + @elm.find('#a').trigger('click') + expect(@elm.find('#b').val()).toBe('clicked') + + + afterEach => + @host.remove()
\ No newline at end of file diff --git a/js/tests/directives/tooltipSpec.coffee b/js/tests/directives/tooltipSpec.coffee new file mode 100644 index 000000000..93c53d3d6 --- /dev/null +++ b/js/tests/directives/tooltipSpec.coffee @@ -0,0 +1,49 @@ +### + +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 'ocTooltip', -> + + beforeEach module 'News' + + + beforeEach inject ($rootScope, $compile) => + @$rootScope = $rootScope + @$compile = $compile + @host = $('<div id="host"></div>') + $('body').append(@host) + $.fx.off = true + + + it 'should bind a normal tooltip element', => + elm = '<a href="#" id="mylink" oc-tooltip>test</a>' + @elm = angular.element(elm) + scope = @$rootScope + @$compile(@elm)(scope) + scope.$digest() + @host.append(@elm) + + link = $(@host).find('#mylink') + expect(link.data('tooltip')).toBeDefined() + + + afterEach => + @host.remove()
\ No newline at end of file diff --git a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee index 1c9168a4d..b18b47006 100644 --- a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee @@ -287,7 +287,7 @@ describe 'FeedBusinessLayer', -> @FeedBusinessLayer.create(' johns ') expect(@persistence.createFeed).toHaveBeenCalledWith('http://johns', 0, - jasmine.any(Function)) + jasmine.any(Function), jasmine.any(Function)) it 'should call the onSuccess function on response status ok', => @@ -295,24 +295,23 @@ describe 'FeedBusinessLayer', -> @persistence.createFeed = jasmine.createSpy('add feed') @persistence.createFeed.andCallFake (folderName, parentId, success) => @response = - status: 'ok' data: 'hi' success(@response) @FeedBusinessLayer.create(' johns ', 0, onSuccess) - expect(onSuccess).toHaveBeenCalledWith(@response.data) + expect(onSuccess).toHaveBeenCalledWith(@response) it 'should call the handle a response error when creating a folder', => onSuccess = jasmine.createSpy('Success') onFailure = jasmine.createSpy('Failure') @persistence.createFeed = jasmine.createSpy('add feed') - @persistence.createFeed.andCallFake (folderName, parentId, success) => + @persistence.createFeed.andCallFake (folderName, parentId, success, + failure) => @response = - status: 'error' msg: 'this is an error' - success(@response) + failure(@response) @FeedBusinessLayer.create(' johns ', 0, onSuccess, onFailure) diff --git a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee index 55914ab4c..1d8431513 100644 --- a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee @@ -216,7 +216,7 @@ describe 'FolderBusinessLayer', -> @FolderBusinessLayer.create(' johns ') expect(@persistence.createFolder).toHaveBeenCalledWith('johns', 0, - jasmine.any(Function)) + jasmine.any(Function), jasmine.any(Function)) it 'should call the onSuccess function on response status ok', => @@ -224,24 +224,23 @@ describe 'FolderBusinessLayer', -> @persistence.createFolder = jasmine.createSpy('add folder') @persistence.createFolder.andCallFake (folderName, parentId, success) => @response = - status: 'ok' data: 'jooo' success(@response) @FolderBusinessLayer.create(' johns ', onSuccess) - expect(onSuccess).toHaveBeenCalledWith(@response.data) + expect(onSuccess).toHaveBeenCalledWith(@response) it 'should call the handle a response error when creating a folder', => onSuccess = jasmine.createSpy('Success') onFailure = jasmine.createSpy('Failure') @persistence.createFolder = jasmine.createSpy('add folder') - @persistence.createFolder.andCallFake (folderName, parentId, success) => + @persistence.createFolder.andCallFake (folderName, parentId, success, + onFailure) => @response = - status: 'error' msg: 'this is an error' - success(@response) + onFailure(@response) @FolderBusinessLayer.create(' johns ', onSuccess, onFailure) @@ -332,7 +331,7 @@ describe 'FolderBusinessLayer', -> @FolderBusinessLayer.import(xml) expect(@persistence.createFolder).toHaveBeenCalledWith('test', 0, - jasmine.any(Function)) + jasmine.any(Function), jasmine.any(Function)) expect(@persistence.createFeed).not.toHaveBeenCalled() @@ -367,17 +366,17 @@ describe 'FolderBusinessLayer', -> expect(@persistence.createFolder).not.toHaveBeenCalled() expect(@persistence.createFeed).toHaveBeenCalledWith( - 'http://worrydream.com/feed.xml', 0, jasmine.any(Function)) + 'http://worrydream.com/feed.xml', 0, jasmine.any(Function), + jasmine.any(Function)) it 'should import nested folders', => @persistence.createFolder = jasmine.createSpy('create folder') @persistence.createFolder.andCallFake (name, parentId, onSuccess) -> data = - data: - folders: [ - {id: 3} - ] + folders: [ + {id: 3} + ] onSuccess(data) @persistence.createFeed = jasmine.createSpy('create feed') @@ -410,9 +409,10 @@ describe 'FolderBusinessLayer', -> @FolderBusinessLayer.import(xml) expect(@persistence.createFolder).toHaveBeenCalledWith('Design', 0, - jasmine.any(Function)) + jasmine.any(Function), jasmine.any(Function)) expect(@persistence.createFeed).toHaveBeenCalledWith( - 'http://worrydream.com/feed.xml', 3, jasmine.any(Function)) + 'http://worrydream.com/feed.xml', 3, jasmine.any(Function), + jasmine.any(Function)) it 'should use an existing folder when importing a folder', => @@ -451,7 +451,8 @@ describe 'FolderBusinessLayer', -> expect(@persistence.createFolder).not.toHaveBeenCalled() expect(@persistence.createFeed).toHaveBeenCalledWith( - 'http://worrydream.com/feed.xml', 2, jasmine.any(Function)) + 'http://worrydream.com/feed.xml', 2, jasmine.any(Function), + jasmine.any(Function)) expect(folder.opened).toBe(true) expect(@persistence.openFolder).toHaveBeenCalled() diff --git a/js/tests/services/loadingSpec.coffee b/js/tests/services/loadingSpec.coffee new file mode 100644 index 000000000..e29e32032 --- /dev/null +++ b/js/tests/services/loadingSpec.coffee @@ -0,0 +1,54 @@ +### + +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 'Loading', -> + + beforeEach module 'News' + + beforeEach inject (_Loading) => + @loading = new _Loading() + + + it 'should have an initial value of 0', => + expect(@loading.getCount()).toBe(0) + + + it 'should increase count when increase is called', => + @loading.increase() + expect(@loading.getCount()).toBe(1) + + + it 'should decrease count when decrease is called', => + @loading.increase() + @loading.increase() + @loading.increase() + @loading.decrease() + expect(@loading.getCount()).toBe(2) + + + it 'should return false when no loading is happening', => + expect(@loading.isLoading()).toBe(false) + + + it 'should return true when loading is happening', => + @loading.increase() + expect(@loading.isLoading()).toBe(true)
\ No newline at end of file diff --git a/js/tests/services/modelSpec.coffee b/js/tests/services/modelSpec.coffee new file mode 100644 index 000000000..6739866b8 --- /dev/null +++ b/js/tests/services/modelSpec.coffee @@ -0,0 +1,219 @@ +### + +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 '_Model', -> + + beforeEach module 'News' + + beforeEach inject (_Model) => + @model = new _Model() + + @data1 = + id: 1 + name: 'john' + mail: 'john.com' + + @data2 = + id: 5 + name: 'frank' + mail: 'frank.de' + + @model.add(@data1) + @model.add(@data2) + + + it 'should return correct size', => + expect(@model.size()).toBe(2) + + + it 'should add data', => + data3 = + id: 4 + name: 'tom' + mail: 'tom.ch' + + @model.add(data3) + + expect(@model.getById(4)).toBe(data3) + + + it 'should increase size when adding data', => + data3 = + id: 4 + + @model.add(data3) + + expect(@model.size()).toBe(3) + + + it 'should update the data if add is called with an existing id', => + data3 = + id: 1 + name: 'tom' + mail: 'tom.ch' + + @model.add(data3) + + data1 = @model.getById(1) + + expect(data1.name).toBe('tom') + expect(data1.mail).toBe('tom.ch') + expect(@model.size()).toBe(2) + + + it 'should decrease size when en entry is deleted', => + @model.removeById(1) + + expect(@model.size()).toBe(1) + + + it 'should remove element when entry is removed', => + @model.removeById(2) + + expect(@model.getById(2)).toBe(undefined) + + + it 'should remove element when entry is removed', => + removed = @model.removeById(1) + + expect(@model.getById(1)).toBe(undefined) + expect(removed.name).toBe('john') + + + it 'should call add when handle is called', => + data = [{ id: 10, name: 'bruce'}] + + @model.handle(data) + + expect(@model.getById(10)).toBe(data[0]) + + + it 'should return all entries on getAll', => + + expect(@model.getAll()).toContain(@data1) + expect(@model.getAll() |