summaryrefslogtreecommitdiffstats
path: root/js/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-22 16:05:45 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-22 16:05:45 +0200
commitb9099435cb6535db835d25361e7b706b85744b20 (patch)
tree2a681b1f9ff0de9780f1f4a785be8378d7f577ab /js/tests
parentac5c8f5f4faae74c034a5cfd1e7f85ca26815bc5 (diff)
add undo for feed and folder deletion, fix #56
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/services/businesslayer/feedbusinesslayerSpec.coffee8
-rw-r--r--js/tests/services/businesslayer/folderbusinesslayerSpec.coffee6
-rw-r--r--js/tests/services/undoqueueSpec.coffee59
3 files changed, 69 insertions, 4 deletions
diff --git a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee
index 2bb37c023..4f7e8f8b3 100644
--- a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee
+++ b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee
@@ -44,16 +44,20 @@ describe 'FeedBusinessLayer', ->
beforeEach inject (@FeedBusinessLayer, @FeedModel, @ItemModel, @FeedType,
- @ShowAll, @ActiveFeed, @_ExistsError) =>
+ @ShowAll, @ActiveFeed, @_ExistsError, @$timeout) =>
@ShowAll.setShowAll(false)
@ActiveFeed.handle({type: @FeedType.Folder, id:0})
it 'should delete feeds', =>
- @FeedModel.removeById = jasmine.createSpy('remove')
+ @FeedModel.removeById = jasmine.createSpy('remove').andCallFake ->
+ return {id: 3, title: 'test'}
@persistence.deleteFeed = jasmine.createSpy('deletequery')
@FeedBusinessLayer.delete(3)
expect(@FeedModel.removeById).toHaveBeenCalledWith(3)
+
+ @$timeout.flush()
+
expect(@persistence.deleteFeed).toHaveBeenCalledWith(3)
diff --git a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee
index f0241979f..7179218c2 100644
--- a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee
+++ b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee
@@ -39,15 +39,17 @@ describe 'FolderBusinessLayer', ->
beforeEach inject (@FolderBusinessLayer, @FolderModel, @FeedModel, @ShowAll,
- @ActiveFeed, @FeedType, @_ExistsError) =>
+ @ActiveFeed, @FeedType, @_ExistsError, @$timeout) =>
@ShowAll.setShowAll(false)
@ActiveFeed.handle({type: @FeedType.Feed, id:0})
it 'should delete folders', =>
- @FolderModel.removeById = jasmine.createSpy('remove')
+ @FolderModel.removeById = jasmine.createSpy('remove').andCallFake ->
+ return {id: 3, name: 'test'}
@persistence.deleteFolder = jasmine.createSpy('deletequery')
@FolderBusinessLayer.delete(3)
+ @$timeout.flush()
expect(@FolderModel.removeById).toHaveBeenCalledWith(3)
expect(@persistence.deleteFolder).toHaveBeenCalledWith(3)
diff --git a/js/tests/services/undoqueueSpec.coffee b/js/tests/services/undoqueueSpec.coffee
new file mode 100644
index 000000000..dcb95e9fd
--- /dev/null
+++ b/js/tests/services/undoqueueSpec.coffee
@@ -0,0 +1,59 @@
+###
+
+ownCloud - App Framework
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.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 'UndoQueue', ->
+
+ beforeEach module 'News'
+
+
+ beforeEach inject (@UndoQueue, @$timeout, @$rootScope) =>
+ @queue = @UndoQueue
+
+
+ it 'should execute a callback', =>
+ executed = false
+ callback = ->
+ executed = true
+
+ @queue.add('hi', callback, 3000)
+
+ @$timeout.flush()
+
+ expect(executed).toBe(true)
+
+
+ it 'should execute a task when a new one is added', =>
+ executed = 0
+ undone = 0
+ callback = ->
+ executed += 1
+
+ undoCallback = ->
+ undone += 1
+
+ @queue.add('hi', callback, 3000, undoCallback)
+ @queue.add('hi', callback, 3000, undoCallback)
+
+ expect(executed).toBe(1)
+ expect(undone).toBe(0)
+
+