diff options
Diffstat (limited to 'js/tests/unit/service')
-rw-r--r-- | js/tests/unit/service/FeedResourceSpec.js | 52 | ||||
-rw-r--r-- | js/tests/unit/service/FolderResourceSpec.js | 35 | ||||
-rw-r--r-- | js/tests/unit/service/ItemResourceSpec.js | 37 | ||||
-rw-r--r-- | js/tests/unit/service/LoadingSpec.js | 6 | ||||
-rw-r--r-- | js/tests/unit/service/PublisherSpec.js | 17 | ||||
-rw-r--r-- | js/tests/unit/service/ResourceSpec.js | 48 | ||||
-rw-r--r-- | js/tests/unit/service/SettingsResourceSpec.js | 48 |
7 files changed, 125 insertions, 118 deletions
diff --git a/js/tests/unit/service/FeedResourceSpec.js b/js/tests/unit/service/FeedResourceSpec.js index d7473cb70..839ae650d 100644 --- a/js/tests/unit/service/FeedResourceSpec.js +++ b/js/tests/unit/service/FeedResourceSpec.js @@ -7,18 +7,23 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('FeedResource', () => { +describe('FeedResource', function () { 'use strict'; - let resource, + var resource, http; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.value('BASE_URL', 'base'); })); + afterEach(function () { + http.verifyNoOutstandingExpectation(); + http.verifyNoOutstandingRequest(); + }); - beforeEach(inject((FeedResource, $httpBackend) => { + + beforeEach(inject(function (FeedResource, $httpBackend) { resource = FeedResource; http = $httpBackend; FeedResource.receive([ @@ -28,14 +33,14 @@ describe('FeedResource', () => { ]); })); - it('should mark all read', inject((FeedResource) => { + it('should mark all read', inject(function (FeedResource) { FeedResource.markRead(); expect(FeedResource.getUnreadCount()).toBe(0); })); - it('should mark a feed read', inject((FeedResource) => { + it('should mark a feed read', inject(function (FeedResource) { FeedResource.markFeedRead(1); @@ -43,14 +48,14 @@ describe('FeedResource', () => { })); - it('should mark an item read', inject((FeedResource) => { + it('should mark an item read', inject(function (FeedResource) { FeedResource.markItemOfFeedRead(1); expect(FeedResource.get('ye').unreadCount).toBe(44); })); - it('should mark an item unread', inject((FeedResource) => { + it('should mark an item unread', inject(function (FeedResource) { FeedResource.markItemOfFeedUnread(1); @@ -58,16 +63,16 @@ describe('FeedResource', () => { })); - it('should get all of folder', inject((FeedResource) => { + it('should get all of folder', inject(function (FeedResource) { - let folders = FeedResource.getByFolderId(3); + var folders = FeedResource.getByFolderId(3); expect(folders.length).toBe(2); })); - it('should cache unreadcount', inject((FeedResource) => { + it('should cache unreadcount', inject(function (FeedResource) { expect(FeedResource.getUnreadCount()).toBe(70); FeedResource.markItemOfFeedRead(3); @@ -84,7 +89,7 @@ describe('FeedResource', () => { })); - it('should cache folder unreadcount', inject((FeedResource) => { + it('should cache folder unreadcount', inject(function (FeedResource) { expect(FeedResource.getFolderUnreadCount(3)).toBe(45); FeedResource.markItemOfFeedRead(3); @@ -101,14 +106,14 @@ describe('FeedResource', () => { })); - it('should cache unreadcount', inject((FeedResource) => { + it('should cache unreadcount', inject(function (FeedResource) { FeedResource.markItemsOfFeedsRead([1, 2]); expect(FeedResource.getUnreadCount()).toBe(68); })); - it ('should delete a feed', inject((FeedResource) => { + it ('should delete a feed', inject(function (FeedResource) { http.expectDELETE('base/feeds/1').respond(200, {}); FeedResource.delete('ye'); @@ -119,7 +124,7 @@ describe('FeedResource', () => { })); - it ('should rename a feed', inject((FeedResource) => { + it ('should rename a feed', inject(function (FeedResource) { http.expectPOST('base/feeds/3/rename', { feedTitle: 'heho' }).respond(200, {}); @@ -132,7 +137,7 @@ describe('FeedResource', () => { })); - it ('should move a feed', inject((FeedResource) => { + it ('should move a feed', inject(function (FeedResource) { http.expectPOST('base/feeds/3/move', { parentFolderId: 5 }).respond(200, {}); @@ -145,7 +150,7 @@ describe('FeedResource', () => { })); - it ('should create a feed', inject((FeedResource) => { + it ('should create a feed', inject(function (FeedResource) { http.expectPOST('base/feeds', { parentFolderId: 5, url: 'hey', @@ -160,7 +165,8 @@ describe('FeedResource', () => { })); - it ('should not create a feed if it exists', inject((FeedResource) => { + it ('should not create a feed if it exists', inject(function ( + FeedResource) { http.expectPOST('base/feeds', { parentFolderId: 5, url: 'ye', @@ -175,7 +181,7 @@ describe('FeedResource', () => { })); - it ('should undo a delete folder', inject((FeedResource) => { + it ('should undo a delete folder', inject(function (FeedResource) { http.expectDELETE('base/feeds/1').respond(200, {}); FeedResource.delete('ye'); @@ -193,12 +199,4 @@ describe('FeedResource', () => { })); - - - afterEach(() => { - http.verifyNoOutstandingExpectation(); - http.verifyNoOutstandingRequest(); - }); - - }); diff --git a/js/tests/unit/service/FolderResourceSpec.js b/js/tests/unit/service/FolderResourceSpec.js index db8312232..01858bbc6 100644 --- a/js/tests/unit/service/FolderResourceSpec.js +++ b/js/tests/unit/service/FolderResourceSpec.js @@ -7,18 +7,23 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('FolderResource', () => { +describe('FolderResource', function () { 'use strict'; - let resource, + var resource, http; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.value('BASE_URL', 'base'); })); + afterEach(function () { + http.verifyNoOutstandingExpectation(); + http.verifyNoOutstandingRequest(); + }); - beforeEach(inject((FolderResource, $httpBackend) => { + + beforeEach(inject(function (FolderResource, $httpBackend) { resource = FolderResource; http = $httpBackend; FolderResource.receive([ @@ -29,7 +34,7 @@ describe('FolderResource', () => { })); - it ('should delete a folder', inject((FolderResource) => { + it ('should delete a folder', inject(function (FolderResource) { http.expectDELETE('base/folders/1').respond(200, {}); FolderResource.delete('ye'); @@ -40,7 +45,7 @@ describe('FolderResource', () => { })); - it ('should rename a folder', inject((FolderResource) => { + it ('should rename a folder', inject(function (FolderResource) { http.expectPOST('base/folders/1/rename', { folderName: 'HEHO' }).respond(200, {}); @@ -53,7 +58,8 @@ describe('FolderResource', () => { })); - it ('should not rename a folder if it exists', inject((FolderResource) => { + it ('should not rename a folder if it exists', inject(function ( + FolderResource) { http.expectPOST('base/folders/1/rename', { folderName: 'SYE' }).respond(200, {}); @@ -66,7 +72,7 @@ describe('FolderResource', () => { })); - it ('should open a folder', inject((FolderResource) => { + it ('should open a folder', inject(function (FolderResource) { http.expectPOST('base/folders/3/open', { folderId: 3, open: false, @@ -80,7 +86,7 @@ describe('FolderResource', () => { })); - it ('should create a folder', inject((FolderResource) => { + it ('should create a folder', inject(function (FolderResource) { http.expectPOST('base/folders', { folderName: 'HEY' }).respond(200, {}); @@ -93,7 +99,8 @@ describe('FolderResource', () => { })); - it ('should not create a folder if it exists', inject((FolderResource) => { + it ('should not create a folder if it exists', inject(function ( + FolderResource) { http.expectPOST('base/folders', { folderName: 'SYE' }).respond(200, {}); @@ -106,7 +113,7 @@ describe('FolderResource', () => { })); - it ('should undo a delete folder', inject((FolderResource) => { + it ('should undo a delete folder', inject(function (FolderResource) { http.expectDELETE('base/folders/1').respond(200, {}); FolderResource.delete('ye'); @@ -124,10 +131,4 @@ describe('FolderResource', () => { })); - afterEach(() => { - http.verifyNoOutstandingExpectation(); - http.verifyNoOutstandingRequest(); - }); - - }); diff --git a/js/tests/unit/service/ItemResourceSpec.js b/js/tests/unit/service/ItemResourceSpec.js index f93d92caa..6e32fc5bd 100644 --- a/js/tests/unit/service/ItemResourceSpec.js +++ b/js/tests/unit/service/ItemResourceSpec.js @@ -7,36 +7,41 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('ItemResource', () => { +describe('ItemResource', function () { 'use strict'; - let http; + var http; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.value('BASE_URL', 'base'); $provide.constant('ITEM_BATCH_SIZE', 5); })); - beforeEach(inject(($httpBackend) => { + beforeEach(inject(function ($httpBackend) { http = $httpBackend; })); + afterEach(function () { + http.verifyNoOutstandingExpectation(); + http.verifyNoOutstandingRequest(); + }); - it('should receive the newestItemId', inject((ItemResource) => { + + it('should receive the newestItemId', inject(function (ItemResource) { ItemResource.receive(3, 'newestItemId'); expect(ItemResource.getNewestItemId()).toBe(3); })); - it('should receive the newestItemId', inject((ItemResource) => { + it('should receive the newestItemId', inject(function (ItemResource) { ItemResource.receive(2, 'starred'); expect(ItemResource.getStarredCount()).toBe(2); })); - it ('should mark item as read', inject((ItemResource) => { + it ('should mark item as read', inject(function (ItemResource) { http.expectPOST('base/items/3/read', {isRead: true}).respond(200, {}); ItemResource.receive([ @@ -60,7 +65,7 @@ describe('ItemResource', () => { })); - it ('should mark multiple item as read', inject((ItemResource) => { + it ('should mark multiple item as read', inject(function (ItemResource) { http.expectPOST('base/items/read/multiple', { itemIds: [3, 4] }).respond(200, {}); @@ -88,7 +93,7 @@ describe('ItemResource', () => { - it ('should star item', inject((ItemResource) => { + it ('should star item', inject(function (ItemResource) { http.expectPOST('base/items/4/a/star', {isStarred: true}) .respond(200, {}); @@ -115,7 +120,7 @@ describe('ItemResource', () => { })); - it ('should mark feed as read', inject((ItemResource) => { + it ('should mark feed as read', inject(function (ItemResource) { http.expectPOST('base/feeds/4/read').respond(200, {}); ItemResource.receive([ @@ -145,7 +150,7 @@ describe('ItemResource', () => { })); - it ('should mark all as read', inject((ItemResource) => { + it ('should mark all as read', inject(function (ItemResource) { http.expectPOST('base/items/read').respond(200, {}); ItemResource.receive([ @@ -176,7 +181,7 @@ describe('ItemResource', () => { })); - it ('toggle star', inject((ItemResource) => { + it ('toggle star', inject(function (ItemResource) { ItemResource.receive([ { id: 3, @@ -198,7 +203,7 @@ describe('ItemResource', () => { })); - it ('should auto page', inject((ItemResource) => { + it ('should auto page', inject(function (ItemResource) { http.expectGET('base/items?id=4&limit=5&offset=3&type=3') .respond(200, {}); @@ -226,10 +231,4 @@ describe('ItemResource', () => { })); - afterEach(() => { - http.verifyNoOutstandingExpectation(); - http.verifyNoOutstandingRequest(); - }); - - });
\ No newline at end of file diff --git a/js/tests/unit/service/LoadingSpec.js b/js/tests/unit/service/LoadingSpec.js index be654641c..2033f33cc 100644 --- a/js/tests/unit/service/LoadingSpec.js +++ b/js/tests/unit/service/LoadingSpec.js @@ -7,18 +7,18 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('Loading', () => { +describe('Loading', function () { 'use strict'; beforeEach(module('News')); - it('should be not load by default', inject((Loading) => { + it('should be not load by default', inject(function (Loading) { expect(Loading.isLoading('global')).toBe(false); expect(Loading.isLoading('content')).toBe(false); expect(Loading.isLoading('autopaging')).toBe(false); })); - it('should set loading', inject((Loading) => { + it('should set loading', inject(function (Loading) { Loading.setLoading('global', true); expect(Loading.isLoading('global')).toBe(true); })); diff --git a/js/tests/unit/service/PublisherSpec.js b/js/tests/unit/service/PublisherSpec.js index 38efa9398..3bd846107 100644 --- a/js/tests/unit/service/PublisherSpec.js +++ b/js/tests/unit/service/PublisherSpec.js @@ -7,17 +7,18 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('Publisher', () => { +describe('Publisher', function () { 'use strict'; beforeEach(module('News')); - it('should should publish on all possible channels', inject((Publisher) => { - let obj = { + it('should should publish on all possible channels', + inject(function (Publisher) { + var obj = { receive: jasmine.createSpy('receive') }; - Publisher.subscribe(obj).toChannels('test'); + Publisher.subscribe(obj).toChannels(['test']); Publisher.publishAll({ test: 'tom' @@ -27,12 +28,13 @@ describe('Publisher', () => { })); - it('should should publish on all possible channels', inject((Publisher) => { + it('should should publish on all possible channels', + inject(function (Publisher) { var obj = { receive: jasmine.createSpy('receive') }; - Publisher.subscribe(obj).toChannels('test', 'tiny'); + Publisher.subscribe(obj).toChannels(['test', 'tiny']); Publisher.publishAll({ tiny: 'tom' @@ -42,7 +44,8 @@ describe('Publisher', () => { })); - it('should not broadcast not subscribed channels', inject((Publisher) => { + it('should not broadcast not subscribed channels', + inject(function (Publisher) { Publisher.publishAll({ test: 'tom' }); diff --git a/js/tests/unit/service/ResourceSpec.js b/js/tests/unit/service/ResourceSpec.js index b1b8ed054..23831613d 100644 --- a/js/tests/unit/service/ResourceSpec.js +++ b/js/tests/unit/service/ResourceSpec.js @@ -7,26 +7,26 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('Resource', () => { +describe('Resource', function () { 'use strict'; - let childResource; + var childResource; beforeEach(module('News')); - beforeEach(inject((Resource, $http) => { - class ChildResource extends Resource { - constructor ($http) { - super($http, 'base'); - } - } + beforeEach(inject(function (Resource, $http) { + var ChildResource = function ($http) { + Resource.call(this, $http, 'base'); + }; + + ChildResource.prototype = Object.create(Resource.prototype); childResource = new ChildResource($http); })); - it('should receive an object', () => { - let objects = [ + it('should receive an object', function () { + var objects = [ { id: 2 }, @@ -41,8 +41,8 @@ describe('Resource', () => { }); - it('should add an object', () => { - let object = { + it('should add an object', function () { + var object = { id: 3, name: 'test' }; @@ -52,14 +52,14 @@ describe('Resource', () => { }); - it('should overwrite an object if it already exists', () => { - let object1 = { + it('should overwrite an object if it already exists', function () { + var object1 = { id: 3, name: 'test', test: 'ho' }; - let object2 = { + var object2 = { id: 3, name: 'test2' }; @@ -73,14 +73,14 @@ describe('Resource', () => { }); - it('should delete a Resource', () => { - let object1 = { + it('should delete a Resource', function () { + var object1 = { id: 3, name: 'test', test: 'ho' }; - let object2 = { + var object2 = { id: 4, name: 'test2' }; @@ -96,14 +96,14 @@ describe('Resource', () => { }); - it('should clear all models', () => { - let object1 = { + it('should clear all models', function () { + var object1 = { id: 3, name: 'test', test: 'ho' }; - let object2 = { + var object2 = { id: 4, name: 'test2' }; @@ -119,14 +119,14 @@ describe('Resource', () => { }); - it('should get all models', () => { - let object1 = { + it('should get all models', function () { + var object1 = { id: 3, name: 'test', test: 'ho' }; - let object2 = { + var object2 = { id: 4, name: 'test2' }; diff --git a/js/tests/unit/service/SettingsResourceSpec.js b/js/tests/unit/service/SettingsResourceSpec.js index 68399707a..a13ed2cec 100644 --- a/js/tests/unit/service/SettingsResourceSpec.js +++ b/js/tests/unit/service/SettingsResourceSpec.js @@ -7,21 +7,27 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -describe('SettingsResource', () => { +describe('SettingsResource', function () { 'use strict'; - let http; + var http; - beforeEach(module('News', ($provide) => { + beforeEach(module('News', function ($provide) { $provide.value('BASE_URL', 'base'); })); - beforeEach(inject(($httpBackend) => { + beforeEach(inject(function ($httpBackend) { http = $httpBackend; })); + afterEach(function () { + http.verifyNoOutstandingExpectation(); + http.verifyNoOutstandingRequest(); + }); - it('should receive default SettingsResource', inject((SettingsResource) => { + + it('should receive default SettingsResource', inject( + function (SettingsResource) { SettingsResource.receive({ 'showAll': true }); @@ -30,8 +36,14 @@ describe('SettingsResource', () => { })); - it('should set values', inject((SettingsResource) => { - http.expectPOST('base/settings', {showAll: true}).respond(200, {}); + it('should set values', inject(function (SettingsResource) { + http.expectPUT('base/settings', { + 'language':'en', + 'showAll':true, + 'compact':false, + 'oldestFirst':false, + 'preventReadOnScroll':false + }).respond(200, {}); SettingsResource.set('showAll', true); @@ -41,14 +53,8 @@ describe('SettingsResource', () => { })); - afterEach(() => { - http.verifyNoOutstandingExpectation(); - http.verifyNoOutstandingRequest(); - }); - - - it('should set language codes', inject((SettingsResource) => { - let codes = [ + it('should set language codes', inject(function (SettingsResource) { + var codes = [ 'ar-ma', 'ar', 'bg', 'ca', 'cs', 'cv', 'da', 'de', 'el', 'en-ca', 'en-gb', 'eo', 'es', 'et', 'eu', 'fi', 'fr-ca', 'fr', 'gl', 'he', 'hu', 'id', 'is', 'it', 'ja', 'ka', 'ko', 'lv', 'ms-my', 'nb', 'ne', @@ -56,16 +62,16 @@ describe('SettingsResource', () => { 'tzm-la', 'tzm', 'uk', 'zh-cn', 'zh-tw', 'hi' ]; - for (let code of codes) { + codes.forEach(function (code) { SettingsResource.receive({ language: code }); expect(SettingsResource.get('language')).toBe(code); - } + }); })); - it('should set default language codes', inject((SettingsResource) => { + it('should set default language codes', inject(function (SettingsResource) { SettingsResource.receive({ language: 'abc' }); @@ -73,7 +79,7 @@ describe('SettingsResource', () => { })); - it('should fix broken language codes', inject((SettingsResource) => { + it('should fix broken language codes', inject(function (SettingsResource) { SettingsResource.receive({ language: 'EN_CA' }); @@ -81,8 +87,8 @@ describe('SettingsResource', () => { })); - it('should fall back to more general language code', inject(( - SettingsResource) => { + it('should fall back to more general language code', inject(function ( + SettingsResource) { SettingsResource.receive({ language: 'EN_US' |