From 1c81d5e2e8f601d3d606f065f52817069b43ef14 Mon Sep 17 00:00:00 2001 From: David Owen Date: Tue, 14 Mar 2017 15:54:46 -0700 Subject: [PATCH] Adding Unit Tests Unit tests for Angular 1.5 Component refernce app. --- .../fruit-detail/fruit-detail-component.ts | 8 +++--- .../fruit-list/fruit-list-component.ts | 1 + .../fruit15/app/js/components/home/home.ts | 1 + ng-rosetta/fruit15/test/karma.conf.js | 1 + .../components/fruit-detail.component.spec.js | 25 +++++++++++++++++++ .../components/fruit-list.component.spec.js | 25 +++++++++++++++++++ .../spec/components/home.component.spec.js | 25 +++++++++++++++++++ .../fruit-detail-controller.spec.js | 3 +++ .../components/fruit-list-controller.spec.js | 3 +++ .../spec/components/home-controller.spec.js | 3 +++ 10 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 ng-rosetta/fruit15/test/spec/components/fruit-detail.component.spec.js create mode 100644 ng-rosetta/fruit15/test/spec/components/fruit-list.component.spec.js create mode 100644 ng-rosetta/fruit15/test/spec/components/home.component.spec.js diff --git a/ng-rosetta/fruit15/app/js/components/fruit-detail/fruit-detail-component.ts b/ng-rosetta/fruit15/app/js/components/fruit-detail/fruit-detail-component.ts index 76679c0..e4c6f53 100644 --- a/ng-rosetta/fruit15/app/js/components/fruit-detail/fruit-detail-component.ts +++ b/ng-rosetta/fruit15/app/js/components/fruit-detail/fruit-detail-component.ts @@ -5,16 +5,18 @@ module fruit15.fruitItemDetail { - export class FruitItemDetailComponent implements angular.IComponentOptions { + export class FruitItemDetailComponent implements angular.IComponentOptions { public templateUrl: string; public template: string; public controller: any; public controllerAs: string; public bindings: any; - constructor() { this.templateUrl = 'js/components/fruit-detail/fruit-detail-view.html'; + constructor() { + this.templateUrl = 'js/components/fruit-detail/fruit-detail-view.html'; this.controller = FruitItemDetailController; this.controllerAs = 'ctlr'; + // The bindings property is used to recieve the list resolved in the route's state. // Note that the bindings properties are appended to the component's controller. Therefore, this.bindings = { fruitlist: 'value' }, // becomes this.controller.fruitlist with the appropriate value mapped. Which means it can be bound to on the view like this: {{ctlr.fruitlist}} @@ -28,7 +30,7 @@ module fruit15.fruitItemDetail { } export class FruitItemDetailController { - private testableProperty: string = 'Test property'; + public testableProperty: string = 'Test property'; constructor() {} } diff --git a/ng-rosetta/fruit15/app/js/components/fruit-list/fruit-list-component.ts b/ng-rosetta/fruit15/app/js/components/fruit-list/fruit-list-component.ts index ed78393..784b873 100644 --- a/ng-rosetta/fruit15/app/js/components/fruit-list/fruit-list-component.ts +++ b/ng-rosetta/fruit15/app/js/components/fruit-list/fruit-list-component.ts @@ -26,6 +26,7 @@ module fruit15.fruitList { } export class FruitListController { + public testableProperty: string = 'Test property'; private gridModel: uiGrid.IGridOptions = {}; private isLoaderBusy: boolean = true; diff --git a/ng-rosetta/fruit15/app/js/components/home/home.ts b/ng-rosetta/fruit15/app/js/components/home/home.ts index 44ccdde..4c22ee7 100644 --- a/ng-rosetta/fruit15/app/js/components/home/home.ts +++ b/ng-rosetta/fruit15/app/js/components/home/home.ts @@ -20,6 +20,7 @@ module fruit15.home { } class HomeController { + public testableProperty: string = 'Test property'; private userName: string; private password: string; diff --git a/ng-rosetta/fruit15/test/karma.conf.js b/ng-rosetta/fruit15/test/karma.conf.js index 8e1a50e..35e801d 100644 --- a/ng-rosetta/fruit15/test/karma.conf.js +++ b/ng-rosetta/fruit15/test/karma.conf.js @@ -39,6 +39,7 @@ module.exports = function(config) { 'app/bower_components/angular-dynamic-locale/src/tmhDynamicLocale.js', 'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.js', 'app/bower_components/angular-ui-router/release/angular-ui-router.js', + 'app/bower_components/angular-ui-grid/ui-grid.js', 'app/js/generated/*.js', 'app/js/**/*.html', 'test/spec/**/*.js', diff --git a/ng-rosetta/fruit15/test/spec/components/fruit-detail.component.spec.js b/ng-rosetta/fruit15/test/spec/components/fruit-detail.component.spec.js new file mode 100644 index 0000000..da32b18 --- /dev/null +++ b/ng-rosetta/fruit15/test/spec/components/fruit-detail.component.spec.js @@ -0,0 +1,25 @@ +// This source code is provided under the BSD license and is provided AS IS with no warranty or guarantee of fit for purpose. See the project's LICENSE.MD for details. +// Copyright Thomson Reuters 2017. All rights reserved. + +'use strict'; + +describe('Fruit Detail Controller', function () { + var fruitDetailController; + + // Create an instance of the application module. + beforeEach(module('fruitApp15')); + + // Create an instance of the target component and extract it's controller. + beforeEach(inject(function ($componentController) { + + // Extract an instance of the component's controller class. + fruitDetailController = $componentController('fruitdetailcomponent'); + + })); + + // Tests start here. + it('should contain a testableProperty equal to "Test property"', function () { + expect(fruitDetailController.testableProperty).toBe('Test property'); + }); + +}); \ No newline at end of file diff --git a/ng-rosetta/fruit15/test/spec/components/fruit-list.component.spec.js b/ng-rosetta/fruit15/test/spec/components/fruit-list.component.spec.js new file mode 100644 index 0000000..04ec5a3 --- /dev/null +++ b/ng-rosetta/fruit15/test/spec/components/fruit-list.component.spec.js @@ -0,0 +1,25 @@ +// This source code is provided under the BSD license and is provided AS IS with no warranty or guarantee of fit for purpose. See the project's LICENSE.MD for details. +// Copyright Thomson Reuters 2017. All rights reserved. + +'use strict'; + +describe('Fruit List Controller', function () { + var fruitListController; + + // Create an instance of the application module. + beforeEach(module('fruitApp15')); + + // Create an instance of the target component and extract it's controller. + beforeEach(inject(function ($componentController) { + + // Extract an instance of the component's controller class. + fruitListController = $componentController('fruitlistcomponent'); + + })); + + // Tests start here. + it('should contain a testableProperty equal to "Test property"', function () { + expect(fruitListController.testableProperty).toBe('Test property'); + }); + +}); \ No newline at end of file diff --git a/ng-rosetta/fruit15/test/spec/components/home.component.spec.js b/ng-rosetta/fruit15/test/spec/components/home.component.spec.js new file mode 100644 index 0000000..c5aad1b --- /dev/null +++ b/ng-rosetta/fruit15/test/spec/components/home.component.spec.js @@ -0,0 +1,25 @@ +// This source code is provided under the BSD license and is provided AS IS with no warranty or guarantee of fit for purpose. See the project's LICENSE.MD for details. +// Copyright Thomson Reuters 2017. All rights reserved. + +'use strict'; + +describe('Home Controller', function () { + var homeController; + + // Create an instance of the application module. + beforeEach(module('fruitApp15')); + + // Create an instance of the target component and extract it's controller. + beforeEach(inject(function ($componentController) { + + // Extract an instance of the component's controller class. + homeController = $componentController('homecomponent'); + + })); + + // Tests start here. + it('should contain a testableProperty equal to "Test property"', function () { + expect(homeController.testableProperty).toBe('Test property'); + }); + +}); \ No newline at end of file diff --git a/ng-rosetta/fruit1x/test/spec/components/fruit-detail-controller.spec.js b/ng-rosetta/fruit1x/test/spec/components/fruit-detail-controller.spec.js index 82798af..ff315fd 100644 --- a/ng-rosetta/fruit1x/test/spec/components/fruit-detail-controller.spec.js +++ b/ng-rosetta/fruit1x/test/spec/components/fruit-detail-controller.spec.js @@ -1,3 +1,6 @@ +// This source code is provided under the BSD license and is provided AS IS with no warranty or guarantee of fit for purpose. See the project's LICENSE.MD for details. +// Copyright Thomson Reuters 2017. All rights reserved. + 'use strict'; describe('fruitDetailController', function () { diff --git a/ng-rosetta/fruit1x/test/spec/components/fruit-list-controller.spec.js b/ng-rosetta/fruit1x/test/spec/components/fruit-list-controller.spec.js index 2fce265..51cfba8 100644 --- a/ng-rosetta/fruit1x/test/spec/components/fruit-list-controller.spec.js +++ b/ng-rosetta/fruit1x/test/spec/components/fruit-list-controller.spec.js @@ -1,3 +1,6 @@ +// This source code is provided under the BSD license and is provided AS IS with no warranty or guarantee of fit for purpose. See the project's LICENSE.MD for details. +// Copyright Thomson Reuters 2017. All rights reserved. + 'use strict'; describe('fruitListController', function () { diff --git a/ng-rosetta/fruit1x/test/spec/components/home-controller.spec.js b/ng-rosetta/fruit1x/test/spec/components/home-controller.spec.js index 8109a8d..dccb06b 100644 --- a/ng-rosetta/fruit1x/test/spec/components/home-controller.spec.js +++ b/ng-rosetta/fruit1x/test/spec/components/home-controller.spec.js @@ -1,3 +1,6 @@ +// This source code is provided under the BSD license and is provided AS IS with no warranty or guarantee of fit for purpose. See the project's LICENSE.MD for details. +// Copyright Thomson Reuters 2017. All rights reserved. + 'use strict'; describe('homeController', function () {