Skip to content

Commit

Permalink
Adding Unit Tests
Browse files Browse the repository at this point in the history
Unit tests for Angular 1.5 Component refernce app.
  • Loading branch information
DOwen55 committed Mar 14, 2017
1 parent 6a4a318 commit 1c81d5e
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 3 deletions.
Expand Up @@ -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}}
Expand All @@ -28,7 +30,7 @@ module fruit15.fruitItemDetail {
}

export class FruitItemDetailController {
private testableProperty: string = 'Test property';
public testableProperty: string = 'Test property';

constructor() {}
}
Expand Down
Expand Up @@ -26,6 +26,7 @@ module fruit15.fruitList {
}

export class FruitListController {
public testableProperty: string = 'Test property';
private gridModel: uiGrid.IGridOptions = {};
private isLoaderBusy: boolean = true;

Expand Down
1 change: 1 addition & 0 deletions ng-rosetta/fruit15/app/js/components/home/home.ts
Expand Up @@ -20,6 +20,7 @@ module fruit15.home {
}

class HomeController {
public testableProperty: string = 'Test property';
private userName: string;
private password: string;

Expand Down
1 change: 1 addition & 0 deletions ng-rosetta/fruit15/test/karma.conf.js
Expand Up @@ -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',
Expand Down
@@ -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');
});

});
@@ -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');
});

});
25 changes: 25 additions & 0 deletions 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');
});

});
@@ -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 () {
Expand Down
@@ -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 () {
Expand Down
@@ -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 () {
Expand Down

0 comments on commit 1c81d5e

Please sign in to comment.