From 50902e1c0550de481fe655c5d560d57da0fe3e12 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 11 Apr 2013 11:20:46 +0200 Subject: fixed foldermodel --- js/tests/services/models/feedmodelSpec.coffee | 58 ++++++++++++++++++----- js/tests/services/models/foldermodelSpec.coffee | 63 +++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 17 deletions(-) (limited to 'js/tests/services/models') diff --git a/js/tests/services/models/feedmodelSpec.coffee b/js/tests/services/models/feedmodelSpec.coffee index c8980d98a..8c2043a39 100644 --- a/js/tests/services/models/feedmodelSpec.coffee +++ b/js/tests/services/models/feedmodelSpec.coffee @@ -48,25 +48,57 @@ describe 'FeedModel', -> expect(@utils.imagePath).toHaveBeenCalledWith('news', 'rss.svg') - it 'should also update items when url is the same', => - @FeedModel.add({id: 2, faviconLink: null, urlHash: 'hi'}) - expect(@FeedModel.size()).toBe(1) + it 'should add feeds without id', => + item = {faviconLink: null, urlHash: 'hi'} + @FeedModel.add(item) - @FeedModel.add({id: 2, faviconLink: null, urlHash: 'hi4'}) + expect(@FeedModel.getByUrlHash('hi')).toBe(item) expect(@FeedModel.size()).toBe(1) - expect(@FeedModel.getById(2).urlHash).toBe('hi4') - @FeedModel.add({id: 3, faviconLink: 'hey', urlHash: 'hi4'}) + + it 'should clear the url hash cache', => + item = {faviconLink: null, urlHash: 'hi'} + @FeedModel.add(item) + @FeedModel.clear() + expect(@FeedModel.getByUrlHash('hi')).toBe(undefined) + expect(@FeedModel.size()).toBe(0) + + + it 'should delete items from the fodername cache', => + item = {id:3, faviconLink: null, urlHash: 'hi'} + @FeedModel.add(item) expect(@FeedModel.size()).toBe(1) - expect(@FeedModel.getById(2)).toBe(undefined) - expect(@FeedModel.getById(3).faviconLink).toBe('hey') + + @FeedModel.removeById(3) + expect(@FeedModel.getByUrlHash('hi')).toBe(undefined) + expect(@FeedModel.size()).toBe(0) - it 'should also remove the feed from the urlHash cache when its removed', => - item = {id: 2, faviconLink: null, urlHash: 'hi'} + it 'should update the id if an update comes in with an id', => + item = {faviconLink: null, urlHash: 'hi', test: 'heheh'} @FeedModel.add(item) - expect(@FeedModel.getByUrlHash('hi')).toBe(item) + item = {id: 3, faviconLink: null, urlHash: 'hi', test: 'hoho'} + @FeedModel.add(item) + + item = {id: 4, faviconLink: null, urlHash: 'his'} + @FeedModel.add(item) + + expect(@FeedModel.getByUrlHash('hi').id).toBe(3) + expect(@FeedModel.getById(3).id).toBe(3) + expect(@FeedModel.getById(3).test).toBe('hoho') + expect(@FeedModel.size()).toBe(2) + + + it 'should update normally', => + item = {id: 3, faviconLink: null, urlHash: 'hi', test: 'heheh'} + @FeedModel.add(item) + + item2 = {id: 3, faviconLink: null, urlHash: 'his', test: 'hoho'} + @FeedModel.add(item2) + + expect(@FeedModel.getById(3).id).toBe(3) + expect(@FeedModel.getById(3).test).toBe('hoho') + expect(@FeedModel.size()).toBe(1) + - @FeedModel.removeById(2) - expect(@FeedModel.getByUrlHash('hi')).toBe(undefined) \ No newline at end of file diff --git a/js/tests/services/models/foldermodelSpec.coffee b/js/tests/services/models/foldermodelSpec.coffee index 45714afdd..8c2dd4b71 100644 --- a/js/tests/services/models/foldermodelSpec.coffee +++ b/js/tests/services/models/foldermodelSpec.coffee @@ -32,8 +32,63 @@ describe 'FolderModel', -> expect(@FolderModel instanceof @_Model).toBeTruthy() - it 'should allow to search for foldernames', => - @FolderModel.add({id: 3, name: 'hi'}) + it 'should add folders without id but name if they dont exist yet', => + item = {name: 'Hi'} + @FolderModel.add(item) + expect(@FolderModel.getByName('hi')).toBe(item) + expect(@FolderModel.size()).toBe(1) - expect(@FolderModel.nameExists('hi')).toBeTruthy() - expect(@FolderModel.nameExists('dhi')).toBeFalsy() \ No newline at end of file + + it 'should clear the fodername cache', => + item = {name: 'Hi'} + @FolderModel.add(item) + @FolderModel.clear() + expect(@FolderModel.getByName('hi')).toBe(undefined) + expect(@FolderModel.size()).toBe(0) + + + it 'should delete items from the fodername cache', => + item = {id: 3, name: 'Hi'} + @FolderModel.add(item) + @FolderModel.removeById(3) + expect(@FolderModel.getByName('hi')).toBe(undefined) + expect(@FolderModel.size()).toBe(0) + + + it 'should update by foldername', => + item = {name: 'Hi'} + @FolderModel.add(item) + + item2 = {name: 'hi', test: 'hoho'} + @FolderModel.add(item2) + + expect(@FolderModel.getByName('hi').test).toBe('hoho') + expect(@FolderModel.size()).toBe(1) + + + it 'should update the id if an update comes in with an id', => + item = {name: 'Tony'} + @FolderModel.add(item) + + item2 = {id: 3, name: 'tony', test: 'hoho'} + @FolderModel.add(item2) + + expect(@FolderModel.getByName('Tony').id).toBe(3) + expect(@FolderModel.getByName('Tony').test).toBe('hoho') + expect(@FolderModel.getById(3).id).toBe(3) + expect(@FolderModel.getById(3).test).toBe('hoho') + expect(@FolderModel.size()).toBe(1) + + + it 'should update normally', => + item = {id: 3, name: 'His'} + @FolderModel.add(item) + + item2 = {id: 3, name: 'hobo', test: 'hoho'} + @FolderModel.add(item2) + + expect(@FolderModel.getByName('His')).toBe(undefined) + expect(@FolderModel.getByName('Hobo').id).toBe(3) + expect(@FolderModel.getByName('Hobo').test).toBe('hoho') + expect(@FolderModel.getById(3).test).toBe('hoho') + expect(@FolderModel.size()).toBe(1) \ No newline at end of file -- cgit v1.2.3