summaryrefslogtreecommitdiffstats
path: root/js/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-11 17:55:59 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-11 17:55:59 +0200
commit59f42f80ad4f292ebbb95ec58d95e0503d29711f (patch)
treeb1387b6afb4d67b3a08d99bb006ac99946d9f57d /js/tests
parentadcf13d214a2b1289cc86c116082e0889abb649c (diff)
add a button for people to get out of add folder mode
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/services/bl/folderblSpec.coffee63
1 files changed, 60 insertions, 3 deletions
diff --git a/js/tests/services/bl/folderblSpec.coffee b/js/tests/services/bl/folderblSpec.coffee
index be434582b..189626604 100644
--- a/js/tests/services/bl/folderblSpec.coffee
+++ b/js/tests/services/bl/folderblSpec.coffee
@@ -27,7 +27,8 @@ describe 'FolderBl', ->
beforeEach =>
angular.module('News').factory 'Persistence', =>
- @persistence = {}
+ @persistence =
+ createFolder: ->
beforeEach inject (@FolderBl, @FolderModel, @FeedModel, @ShowAll,
@ActiveFeed, @FeedType, @_ExistsError) =>
@@ -131,8 +132,64 @@ describe 'FolderBl', ->
expect(@FolderBl.getAll()).toContain(item2)
- xit 'should not create a folder if it already exists', =>
+ it 'should not create a folder if it already exists', =>
item1 = {id: 4, open: true, name: 'john'}
@FolderModel.add(item1)
- expect(@FolderBl.create('johns')).toThrow(new @_ExistsError())
+ expect =>
+ @FolderBl.create('john')
+ .toThrow(new @_ExistsError())
+
+ expect =>
+ @FolderBl.create('johns')
+ .not.toThrow(new @_ExistsError())
+
+
+ it 'should not create folders that are empty', =>
+ expect =>
+ @FolderBl.create(' ')
+ .toThrow(new Error())
+
+
+ it 'should create a folder before theres a response from the server', =>
+ @FolderBl.create('johns')
+ expect(@FolderModel.size()).toBe(1)
+
+
+ it 'should make a create folder request', =>
+ @persistence.createFolder = jasmine.createSpy('add folder')
+
+ @FolderBl.create(' johns ')
+ expect(@persistence.createFolder).toHaveBeenCalledWith('johns', 0,
+ jasmine.any(Function))
+
+
+ it 'should call the onSuccess function on response status ok', =>
+ onSuccess = jasmine.createSpy('Success')
+ @persistence.createFolder = jasmine.createSpy('add folder')
+ @persistence.createFolder.andCallFake (folderName, parentId, success) =>
+ response =
+ status: 'ok'
+ success(response)
+
+ @FolderBl.create(' johns ', onSuccess)
+
+ expect(onSuccess).toHaveBeenCalled()
+
+
+ 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) =>
+ @response =
+ status: 'error'
+ msg: 'this is an error'
+ success(@response)
+
+ @FolderBl.create(' johns ', onSuccess, onFailure)
+
+ expect(onSuccess).not.toHaveBeenCalled()
+ expect(onFailure).toHaveBeenCalled()
+
+ expect(@FolderModel.getByName('johns').error).toBe(@response.msg) \ No newline at end of file