diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-13 17:28:07 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-13 17:28:38 +0200 |
commit | 38e4b6d7e973bc99811139066a7a047b4bd76a4c (patch) | |
tree | fb88f63c0a69cc527956715333dddd20d3b94f0b /js/tests/services/bl/folderblSpec.coffee | |
parent | 8df86d1991e25dfaef8623e2f4945c67dbc5f318 (diff) |
implement opml import, fix #23
Diffstat (limited to 'js/tests/services/bl/folderblSpec.coffee')
-rw-r--r-- | js/tests/services/bl/folderblSpec.coffee | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/js/tests/services/bl/folderblSpec.coffee b/js/tests/services/bl/folderblSpec.coffee index 3ca761f7d..ba7e94de5 100644 --- a/js/tests/services/bl/folderblSpec.coffee +++ b/js/tests/services/bl/folderblSpec.coffee @@ -29,6 +29,7 @@ describe 'FolderBl', -> angular.module('News').factory 'Persistence', => @persistence = createFolder: -> + createFeed: -> beforeEach inject (@FolderBl, @FolderModel, @FeedModel, @ShowAll, @ActiveFeed, @FeedType, @_ExistsError) => @@ -220,3 +221,212 @@ describe 'FolderBl', -> expect(@FolderModel.getById(3).opened).toBeTruthy() expect(@persistence.openFolder).toHaveBeenCalledWith(3) + + it 'should not import on empty opml', => + @persistence.createFolder = jasmine.createSpy('create folder') + @persistence.createFeed = jasmine.createSpy('create feed') + + xml = '<?xml version="1.0" ?> + <opml version="1.1"> + <!--Generated by NewsBlur - www.newsblur.com--> + <head> + <title> + NewsBlur Feeds + </title> + <dateCreated> + 2013-03-14 16:44:01.356965 + </dateCreated> + <dateModified> + 2013-03-14 16:44:01.356965 + </dateModified> + </head> + <body> + + </body> + </opml>' + + @FolderBl.import(xml) + + expect(@persistence.createFolder).not.toHaveBeenCalled() + expect(@persistence.createFeed).not.toHaveBeenCalled() + + + it 'should import a folder', => + @persistence.createFolder = jasmine.createSpy('create folder') + @persistence.createFeed = jasmine.createSpy('create feed') + + xml = '<?xml version="1.0" ?> + <opml version="1.1"> + <!--Generated by NewsBlur - www.newsblur.com--> + <head> + <title> + NewsBlur Feeds + </title> + <dateCreated> + 2013-03-14 16:44:01.356965 + </dateCreated> + <dateModified> + 2013-03-14 16:44:01.356965 + </dateModified> + </head> + <body> + <outline text="Design" title="Design" /> + </body> + </opml>' + + @FolderBl.import(xml) + + expect(@persistence.createFolder).toHaveBeenCalledWith('Design', 0, + jasmine.any(Function)) + expect(@persistence.createFeed).not.toHaveBeenCalled() + + + it 'should import a feed', => + @persistence.createFolder = jasmine.createSpy('create folder') + @persistence.createFeed = jasmine.createSpy('create feed') + + xml = '<?xml version="1.0" ?> + <opml version="1.1"> + <!--Generated by NewsBlur - www.newsblur.com--> + <head> + <title> + NewsBlur Feeds + </title> + <dateCreated> + 2013-03-14 16:44:01.356965 + </dateCreated> + <dateModified> + 2013-03-14 16:44:01.356965 + </dateModified> + </head> + <body> + <outline htmlUrl="http://worrydream.com/" text= + "<div>Bret Victor\'s website</div>" + title="<div>Bret Victor\'s website</div>" + type="rss" + version="RSS" xmlUrl="http://worrydream.com/feed.xml"/> + </body> + </opml>' + + @FolderBl.import(xml) + + expect(@persistence.createFolder).not.toHaveBeenCalled() + expect(@persistence.createFeed).toHaveBeenCalledWith( + 'http://worrydream.com/feed.xml', 0, 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} + ] + onSuccess(data) + + @persistence.createFeed = jasmine.createSpy('create feed') + + xml = '<?xml version="1.0" ?> + <opml version="1.1"> + <!--Generated by NewsBlur - www.newsblur.com--> + <head> + <title> + NewsBlur Feeds + </title> + <dateCreated> + 2013-03-14 16:44:01.356965 + </dateCreated> + <dateModified> + 2013-03-14 16:44:01.356965 + </dateModified> + </head> + <body> + <outline text="Design" title="Design"> + <outline htmlUrl="http://worrydream.com/" text= + "<div>Bret Victor\'s website</div>" + title="<div>Bret Victor\'s website</div>" + type="rss" + version="RSS" xmlUrl="http://worrydream.com/feed.xml"/> + </outline> + </body> + </opml>' + + @FolderBl.import(xml) + + expect(@persistence.createFolder).toHaveBeenCalledWith('Design', 0, + jasmine.any(Function)) + expect(@persistence.createFeed).toHaveBeenCalledWith( + 'http://worrydream.com/feed.xml', 3, jasmine.any(Function)) + + + it 'should use an existing folder when importing a folder', => + @persistence.createFolder = jasmine.createSpy('create folder') + @persistence.createFeed = jasmine.createSpy('create feed') + + @FolderModel.add({id: 2, name: 'design'}) + xml = '<?xml version="1.0" ?> + <opml version="1.1"> + <!--Generated by NewsBlur - www.newsblur.com--> + <head> + <title> + NewsBlur Feeds + </title> + <dateCreated> + 2013-03-14 16:44:01.356965 + </dateCreated> + <dateModified> + 2013-03-14 16:44:01.356965 + </dateModified> + </head> + <body> + <outline text="Design" title="Design"> + <outline htmlUrl="http://worrydream.com/" text= + "<div>Bret Victor\'s website</div>" + title="<div>Bret Victor\'s website</div>" + type="rss" + version="RSS" xmlUrl="http://worrydream.com/feed.xml"/> + </outline> + </body> + </opml>' + + @FolderBl.import(xml) + + expect(@persistence.createFolder).not.toHaveBeenCalled() + expect(@persistence.createFeed).toHaveBeenCalledWith( + 'http://worrydream.com/feed.xml', 2, jasmine.any(Function)) + + + it 'should not import a feed if it already exists', => + @persistence.createFolder = jasmine.createSpy('create folder') + @persistence.createFeed = jasmine.createSpy('create feed') + + @FeedModel.add({urlHash: hex_md5('http://worrydream.com/feed.xml')}) + + xml = '<?xml version="1.0" ?> + <opml version="1.1"> + <!--Generated by NewsBlur - www.newsblur.com--> + <head> + <title> + NewsBlur Feeds + </title> + <dateCreated> + 2013-03-14 16:44:01.356965 + </dateCreated> + <dateModified> + 2013-03-14 16:44:01.356965 + </dateModified> + </head> + <body> + <outline htmlUrl="http://worrydream.com/" text= + "<div>Bret Victor\'s website</div>" + title="<div>Bret Victor\'s website</div>" + type="rss" + version="RSS" xmlUrl="http://worrydream.com/feed.xml"/> + </body> + </opml>' + + @FolderBl.import(xml) + + expect(@persistence.createFolder).not.toHaveBeenCalled() + expect(@persistence.createFeed).not.toHaveBeenCalled()
\ No newline at end of file |