summaryrefslogtreecommitdiffstats
path: root/js/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-08 22:19:19 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-08 22:19:19 +0200
commit68f5a01dc692e9bf6c0a60e584d1600adcae3a62 (patch)
tree372b2366855b96a7b724c426c7c5ae0241e933f1 /js/tests
parenta9b34deefd67e08a79ddefb0e1f980f6a6c1249d (diff)
port javascript from appframework
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/directives/clickfocusSpec.coffee73
-rw-r--r--js/tests/directives/clickslidetoggleSpec.coffee128
-rw-r--r--js/tests/directives/draggableSpec.coffee43
-rw-r--r--js/tests/directives/forwardclickSpec.coffee71
-rw-r--r--js/tests/directives/tooltipSpec.coffee49
-rw-r--r--js/tests/services/loadingSpec.coffee54
-rw-r--r--js/tests/services/modelSpec.coffee219
-rw-r--r--js/tests/services/notificationSpec.coffee33
-rw-r--r--js/tests/services/notimplementederrorSpec.coffee35
-rw-r--r--js/tests/services/ocSpec.coffee32
-rw-r--r--js/tests/services/publisherSpec.coffee69
-rw-r--r--js/tests/services/queries/biggerthanSpec.coffee80
-rw-r--r--js/tests/services/queries/biggerthanequalSpec.coffee80
-rw-r--r--js/tests/services/queries/containsSpec.coffee86
-rw-r--r--js/tests/services/queries/doesnotcontainSpec.coffee89
-rw-r--r--js/tests/services/queries/equalSpec.coffee83
-rw-r--r--js/tests/services/queries/lessthanSpec.coffee80
-rw-r--r--js/tests/services/queries/lessthanequalSpec.coffee80
-rw-r--r--js/tests/services/queries/maximumSpec.coffee63
-rw-r--r--js/tests/services/queries/minimumSpec.coffee64
-rw-r--r--js/tests/services/queries/querySpec.coffee68
-rw-r--r--js/tests/services/queries/unequalSpec.coffee88
-rw-r--r--js/tests/services/requestSpec.coffee273
-rw-r--r--js/tests/services/routerSpec.coffee33
-rw-r--r--js/tests/stubs/modules.js2
25 files changed, 1974 insertions, 1 deletions
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/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()).toContain(@data2)
+ expect(@model.getAll().length).toBe(2)
+
+
+ it 'should clear the data on clear', =>
+ @model.clear()
+
+ expect(@model.size()).toBe(0)
+ expect(@model.getById(1)).toBe(undefined)
+ expect(@model.getById(2)).toBe(undefined)
+
+
+ it 'should support filters', =>
+ filterMock =
+ exec: jasmine.createSpy()
+ hashCode: ->
+ return 'a'
+
+ @model.get(filterMock)
+
+ expect(filterMock.exec).toHaveBeenCalledWith(@model.getAll())
+
+
+ it 'should cache filters', =>
+ filterMock1 =
+ exec: jasmine.createSpy('1').andReturn('value')
+ hashCode: ->
+ return 'a'
+
+ filterMock2 =
+ exec: jasmine.createSpy('2').andReturn('value')
+ hashCode: ->
+ return 'a'
+
+ @model.get(filterMock1)
+ @model.get(filterMock2)
+
+ expect(filterMock1.exec).toHaveBeenCalledWith(@model.getAll())
+ expect(filterMock2.exec).not.toHaveBeenCalled()
+
+
+ @testClearCache = (callback) =>
+ filterMock1 =
+ exec: jasmine.createSpy().andReturn('value')
+ hashCode: ->
+ return 'a'
+
+ filterMock2 =
+ exec: jasmine.createSpy().andReturn('value')
+ hashCode: ->
+ return 'a'
+
+ @model.get(filterMock1)
+ callback()
+ @model.get(filterMock2)
+
+ return [
+ filterMock1
+ filterMock2
+ ]
+
+
+ it 'should clear the cache on add', =>
+ mocks = @testClearCache =>
+ @model.add({id: 4})
+ expect(mocks[0].exec).toHaveBeenCalled()
+ expect(mocks[1].exec).toHaveBeenCalled()
+
+
+ it 'should clear the cache on update', =>
+ mocks = @testClearCache =>
+ @model.update({id: 1})
+
+ expect(mocks[0].exec).toHaveBeenCalled()
+ expect(mocks[1].exec).toHaveBeenCalled()
+
+
+ it 'should clear the cache on add', =>
+ mocks = @testClearCache =>
+ @model.removeById(1)
+
+ expect(mocks[0].exec).toHaveBeenCalled()
+ expect(mocks[1].exec).toHaveBeenCalled()
+
+
+ it 'should not clear the cache on remove when false passed as 2nd param', =>
+ mocks = @testClearCache =>
+ @model.removeById(1, false)
+
+ expect(mocks[0].exec).toHaveBeenCalled()
+ expect(mocks[1].exec).not.toHaveBeenCalled()
+
+
+ it 'should not clear the cache on update when false passed as 2nd param', =>
+ mocks = @testClearCache =>
+ @model.update({id: 1}, false)
+
+ expect(mocks[0].exec).toHaveBeenCalled()
+ expect(mocks[1].exec).not.toHaveBeenCalled()
+
+
+ it 'should not clear the cache on add when false passed as 2nd param', =>
+ mocks = @testClearCache =>
+ @model.add({id: 4}, false)
+
+ expect(mocks[0].exec).toHaveBeenCalled()
+ expect(mocks[1].exec).not.toHaveBeenCalled()
diff --git a/js/tests/services/notificationSpec.coffee b/js/tests/services/notificationSpec.coffee
new file mode 100644
index 000000000..ecca3d849
--- /dev/null
+++ b/js/tests/services/notificationSpec.coffee
@@ -0,0 +1,33 @@
+###
+
+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 'Notification', ->
+
+ beforeEach module 'News'
+
+ beforeEach =>
+ inject (Notification) =>
+ @notification = Notification
+
+
+ it 'should have a defined router', =>
+ expect(@notification).toBeDefined()
diff --git a/js/tests/services/notimplementederrorSpec.coffee b/js/tests/services/notimplementederrorSpec.coffee
new file mode 100644
index 000000000..539f7e0c7
--- /dev/null
+++ b/js/tests/services/notimplementederrorSpec.coffee
@@ -0,0 +1,35 @@
+###
+
+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 '_NotImplementedError', ->
+
+
+ beforeEach module 'News'
+
+ beforeEach inject (_NotImplementedError) =>
+ @error = _NotImplementedError
+
+
+ it 'should set a message', =>
+ msg = 'message'
+
+ expect(new @error(msg).getMessage()).toBe(msg)
diff --git a/js/tests/services/ocSpec.coffee b/js/tests/services/ocSpec.coffee
new file mode 100644
index 000000000..9c5886128
--- /dev/null
+++ b/js/tests/services/ocSpec.coffee
@@ -0,0 +1,32 @@
+###
+
+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 'Utils', ->
+
+ beforeEach module 'News'
+
+ beforeEach =>
+ inject (@Utils) =>
+
+
+ it 'should have defined utils', =>
+ expect(@Utils).toBeDefined()
diff --git a/js/tests/services/publisherSpec.coffee b/js/tests/services/publisherSpec.coffee
new file mode 100644
index 000000000..0f9627cf4
--- /dev/null
+++ b/js/tests/services/publisherSpec.coffee
@@ -0,0 +1,69 @@
+###
+
+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 '_Publisher', ->
+
+ beforeEach module 'News'
+
+ beforeEach =>
+ @modelMock =
+ handle: jasmine.createSpy()
+
+ beforeEach =>
+ inject (_Publisher) =>
+ @publisher = new _Publisher()
+
+
+ it 'should publish data to subscribed model', =>
+ data =
+ hi: 'test'
+
+ @publisher.subscribeObjectTo @modelMock, 'test'
+ @publisher.publishDataTo data, 'test'
+
+ expect(@modelMock.handle).toHaveBeenCalledWith(data)
+
+
+ it 'should publish not to unsubscribed model', =>
+ data =
+ hi: 'test'
+
+ @publisher.subscribeObjectTo @modelMock, 'test1'
+ @publisher.publishDataTo data, 'test'
+
+ expect(@modelMock.handle).not.toHaveBeenCalledWith(data)
+
+
+ it 'should publish data to multiple subscribed models', =>
+ data =
+ hi: 'test'
+ data2 =
+ base: 'john'
+ @modelMock2 =
+ handle: jasmine.createSpy()
+
+ @publisher.subscribeObjectTo @modelMock, 'test'
+ @publisher.subscribeObjectTo @modelMock2, 'test'
+ @publisher.publishDataTo data, 'test'
+
+ expect(@modelMock.handle).toHaveBeenCalledWith(data)
+ expect(@mode