From 0fa67552247b2d29a6ca438c2605b8db2bbdbab7 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 21 May 2014 23:43:28 +0200 Subject: es6 all the things --- js/tests/e2e/main.js | 7 +- js/tests/unit/controller/AppControllerSpec.js | 14 +-- js/tests/unit/controller/ContentControllerSpec.js | 8 +- js/tests/unit/service/ItemResourceSpec.js | 8 +- js/tests/unit/service/LoadingSpec.js | 6 +- js/tests/unit/service/PublisherSpec.js | 10 +- js/tests/unit/service/ResourceSpec.js | 109 ++++++++++------------ js/tests/unit/service/SettingsSpec.js | 6 +- js/tests/unit/stubs/App.js | 15 +++ js/tests/unit/stubs/OC.js | 16 ++++ js/tests/unit/stubs/app.js | 10 -- js/tests/unit/stubs/oc.js | 16 ---- 12 files changed, 108 insertions(+), 117 deletions(-) create mode 100644 js/tests/unit/stubs/App.js create mode 100644 js/tests/unit/stubs/OC.js delete mode 100644 js/tests/unit/stubs/app.js delete mode 100644 js/tests/unit/stubs/oc.js (limited to 'js/tests') diff --git a/js/tests/e2e/main.js b/js/tests/e2e/main.js index b76110c65..247deb47b 100644 --- a/js/tests/e2e/main.js +++ b/js/tests/e2e/main.js @@ -23,12 +23,9 @@ describe('news page', function () { it('should show the first run page', function () { - var firstRun; - - - firstRun = browser.findElement(By.id('first-run')); + let firstRun = browser.findElement(By.id('first-run')); //firstRun.findElement(By.tagName('h1')).then(function (greeting) { - // expect(greeting.getText()).toBe('Welcome to the ownCloud News app!'); + //expect(greeting.getText()).toBe('Welcome to the ownCloud News app!'); //}); expect(firstRun.isDisplayed()).toBe(true); diff --git a/js/tests/unit/controller/AppControllerSpec.js b/js/tests/unit/controller/AppControllerSpec.js index d44d8b0c3..fc5780a40 100644 --- a/js/tests/unit/controller/AppControllerSpec.js +++ b/js/tests/unit/controller/AppControllerSpec.js @@ -7,36 +7,36 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -describe('AppController', function () { +describe('AppController', () => { 'use strict'; - var controller; + let controller; beforeEach(module('News')); - beforeEach(inject(function ($controller) { + beforeEach(inject(($controller) => { controller = $controller('AppController'); })); - it('should expose Loading', inject(function (Loading) { + it('should expose Loading', inject((Loading) => { expect(controller.loading).toBe(Loading); })); - it('should expose set firstrun if no feeds and folders', inject(function () { + it('should expose set firstrun if no feeds and folders', inject(() => { expect(controller.isFirstRun()).toBe(true); })); - it('should expose set firstrun if feeds', inject(function (FeedResource) { + it('should expose set firstrun if feeds', inject((FeedResource) => { FeedResource.add({url: 'test'}); expect(controller.isFirstRun()).toBe(false); })); - it('should expose set firstrun if folders', inject(function (FolderResource) { + it('should expose set firstrun if folders', inject((FolderResource) => { FolderResource.add({name: 'test'}); expect(controller.isFirstRun()).toBe(false); diff --git a/js/tests/unit/controller/ContentControllerSpec.js b/js/tests/unit/controller/ContentControllerSpec.js index c99cb79ab..1dbd3d936 100644 --- a/js/tests/unit/controller/ContentControllerSpec.js +++ b/js/tests/unit/controller/ContentControllerSpec.js @@ -7,19 +7,19 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -describe('ContentController', function () { +describe('ContentController', () => { 'use strict'; beforeEach(module('News')); - it('should publish data to models', inject(function ($controller, Publisher, - FeedResource, ItemResource) { + it('should publish data to models', inject(($controller, Publisher, + FeedResource, ItemResource) => { Publisher.subscribe(ItemResource).toChannels('items'); Publisher.subscribe(FeedResource).toChannels('feeds'); - var controller = $controller('ContentController', { + let controller = $controller('ContentController', { data: { 'items': [ { diff --git a/js/tests/unit/service/ItemResourceSpec.js b/js/tests/unit/service/ItemResourceSpec.js index 9d6c10ae0..acbf0850c 100644 --- a/js/tests/unit/service/ItemResourceSpec.js +++ b/js/tests/unit/service/ItemResourceSpec.js @@ -7,27 +7,27 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -describe('ItemResource', function () { +describe('ItemResource', () => { 'use strict'; beforeEach(module('News')); - it('should receive the newestItemId', inject(function (ItemResource) { + it('should receive the newestItemId', inject((ItemResource) => { ItemResource.receive(3, 'newestItemId'); expect(ItemResource.getNewestItemId()).toBe(3); })); - it('should receive the newestItemId', inject(function (ItemResource) { + it('should receive the newestItemId', inject((ItemResource) => { ItemResource.receive(2, 'starred'); expect(ItemResource.getStarredCount()).toBe(2); })); - it('should receive items', inject(function (ItemResource) { + it('should receive items', inject((ItemResource) => { ItemResource.receive([ { id: 3 diff --git a/js/tests/unit/service/LoadingSpec.js b/js/tests/unit/service/LoadingSpec.js index 2033f33cc..be654641c 100644 --- a/js/tests/unit/service/LoadingSpec.js +++ b/js/tests/unit/service/LoadingSpec.js @@ -7,18 +7,18 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -describe('Loading', function () { +describe('Loading', () => { 'use strict'; beforeEach(module('News')); - it('should be not load by default', inject(function (Loading) { + it('should be not load by default', inject((Loading) => { expect(Loading.isLoading('global')).toBe(false); expect(Loading.isLoading('content')).toBe(false); expect(Loading.isLoading('autopaging')).toBe(false); })); - it('should set loading', inject(function (Loading) { + it('should set loading', inject((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 06cd48c6a..38efa9398 100644 --- a/js/tests/unit/service/PublisherSpec.js +++ b/js/tests/unit/service/PublisherSpec.js @@ -7,13 +7,13 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -describe('Publisher', function () { +describe('Publisher', () => { 'use strict'; beforeEach(module('News')); - it('should should publish on all possible channels', inject(function (Publisher) { - var obj = { + it('should should publish on all possible channels', inject((Publisher) => { + let obj = { receive: jasmine.createSpy('receive') }; @@ -27,7 +27,7 @@ describe('Publisher', function () { })); - it('should should publish on all possible channels', inject(function (Publisher) { + it('should should publish on all possible channels', inject((Publisher) => { var obj = { receive: jasmine.createSpy('receive') }; @@ -42,7 +42,7 @@ describe('Publisher', function () { })); - it('should not broadcast to not subscribed channels', inject(function (Publisher) { + it('should not broadcast not subscribed channels', inject((Publisher) => { Publisher.publishAll({ test: 'tom' }); diff --git a/js/tests/unit/service/ResourceSpec.js b/js/tests/unit/service/ResourceSpec.js index ba877fcd4..ec0b95ed9 100644 --- a/js/tests/unit/service/ResourceSpec.js +++ b/js/tests/unit/service/ResourceSpec.js @@ -7,25 +7,26 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -describe('Resource', function () { +describe('Resource', () => { 'use strict'; - var childModel; + let childResource; beforeEach(module('News')); - beforeEach(inject(function (Resource) { - var ChildModel = function () { - Resource.call(this, 'id'); - }; - ChildModel.prototype = Object.create(Resource.prototype); + beforeEach(inject((Resource, $http) => { + class ChildResource extends Resource { + constructor ($http) { + super('id', $http); + } + } - childModel = new ChildModel(); + childResource = new ChildResource($http); })); - it('should receive an object', function () { - var objects = [ + it('should receive an object', () => { + let objects = [ { id: 2 }, @@ -34,118 +35,106 @@ describe('Resource', function () { } ]; - childModel.receive(objects); + childResource.receive(objects); - expect(childModel.size()).toBe(2); + expect(childResource.size()).toBe(2); }); - it('should add an object', function () { - var object = { + it('should add an object', () => { + let object = { id: 3, name: 'test' }; - childModel.add(object); + childResource.add(object); - expect(childModel.get(3)).toBe(object); + expect(childResource.get(3)).toBe(object); }); - it('should overwrite an object if it already exists', function () { - var object1, - object2; - - object1 = { + it('should overwrite an object if it already exists', () => { + let object1 = { id: 3, name: 'test', test: 'ho' }; - object2 = { + let object2 = { id: 3, name: 'test2' }; - childModel.add(object1); - childModel.add(object2); + childResource.add(object1); + childResource.add(object2); - expect(childModel.get(3).name).toBe('test2'); - expect(childModel.get(3).test).toBe('ho'); - expect(childModel.size()).toBe(1); + expect(childResource.get(3).name).toBe('test2'); + expect(childResource.get(3).test).toBe('ho'); + expect(childResource.size()).toBe(1); }); - it('should delete a Resource', function () { - var object1, - object2; - - object1 = { + it('should delete a Resource', () => { + let object1 = { id: 3, name: 'test', test: 'ho' }; - object2 = { + let object2 = { id: 4, name: 'test2' }; - childModel.add(object1); - childModel.add(object2); + childResource.add(object1); + childResource.add(object2); - childModel.delete(3); + childResource.delete(3); - expect(childModel.get(3)).not.toBeDefined(); - expect(childModel.get(4).name).toBe('test2'); - expect(childModel.size()).toBe(1); + expect(childResource.get(3)).not.toBeDefined(); + expect(childResource.get(4).name).toBe('test2'); + expect(childResource.size()).toBe(1); }); - it('should clear all models', function () { - var object1, - object2; - - object1 = { + it('should clear all models', () => { + let object1 = { id: 3, name: 'test', test: 'ho' }; - object2 = { + let object2 = { id: 4, name: 'test2' }; - childModel.add(object1); - childModel.add(object2); + childResource.add(object1); + childResource.add(object2); - childModel.clear(); + childResource.clear(); - expect(childModel.get(3)).not.toBeDefined(); - expect(childModel.get(4)).not.toBeDefined(); - expect(childModel.size()).toBe(0); + expect(childResource.get(3)).not.toBeDefined(); + expect(childResource.get(4)).not.toBeDefined(); + expect(childResource.size()).toBe(0); }); - it('should get all models', function () { - var object1, - object2; - - object1 = { + it('should get all models', () => { + let object1 = { id: 3, name: 'test', test: 'ho' }; - object2 = { + let object2 = { id: 4, name: 'test2' }; - childModel.add(object1); - childModel.add(object2); + childResource.add(object1); + childResource.add(object2); - expect(childModel.getAll()[1].id).toBe(4); + expect(childResource.getAll()[1].id).toBe(4); }); }); \ No newline at end of file diff --git a/js/tests/unit/service/SettingsSpec.js b/js/tests/unit/service/SettingsSpec.js index 65dc4bf2f..b76251e3a 100644 --- a/js/tests/unit/service/SettingsSpec.js +++ b/js/tests/unit/service/SettingsSpec.js @@ -7,12 +7,12 @@ * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ -describe('Settings', function () { +describe('Settings', () => { 'use strict'; beforeEach(module('News')); - it('should receive default settings', inject(function (Settings) { + it('should receive default settings', inject((Settings) => { Settings.receive({ 'showAll': true }); @@ -21,7 +21,7 @@ describe('Settings', function () { })); - it('should set values', inject(function (Settings) { + it('should set values', inject((Settings) => { Settings.set('showAll', true); expect(Settings.get('showAll')).toBe(true); diff --git a/js/tests/unit/stubs/App.js b/js/tests/unit/stubs/App.js new file mode 100644 index 000000000..dc512f5e1 --- /dev/null +++ b/js/tests/unit/stubs/App.js @@ -0,0 +1,15 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2012, 2014 + */ +window.app = angular.module('News', [ + 'ngRoute', + 'ngSanitize', + 'ngAnimate', + 'ngMock' +]); \ No newline at end of file diff --git a/js/tests/unit/stubs/OC.js b/js/tests/unit/stubs/OC.js new file mode 100644 index 000000000..82622aab5 --- /dev/null +++ b/js/tests/unit/stubs/OC.js @@ -0,0 +1,16 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2012, 2014 + */ +window.OC = { + generateUrl: () => { + 'use strict'; + + return ''; + } +}; \ No newline at end of file diff --git a/js/tests/unit/stubs/app.js b/js/tests/unit/stubs/app.js deleted file mode 100644 index 3cb1b1d3f..000000000 --- a/js/tests/unit/stubs/app.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Bernhard Posselt - * @copyright Bernhard Posselt 2012, 2014 - */ -var app = angular.module('News', ['ngRoute', 'ngSanitize', 'ngAnimate', 'ngMock']); \ No newline at end of file diff --git a/js/tests/unit/stubs/oc.js b/js/tests/unit/stubs/oc.js deleted file mode 100644 index 07ac96491..000000000 --- a/js/tests/unit/stubs/oc.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Bernhard Posselt - * @copyright Bernhard Posselt 2012, 2014 - */ -var OC = { - generateUrl: function () { - 'use strict'; - - return ''; - } -}; \ No newline at end of file -- cgit v1.2.3