Simon Hunt

GUI - Angular:: added angular-mocks.js to tp lib.

- sample code plus sample unit test, and karma configuration file.

Change-Id: I0c5d867913c88e12eacd17934c6f42226b82410f
1 +// Simple controller
2 +
3 +angular.module('notesApp', [])
4 + .controller('ListCtrl', [function () {
5 + var self = this;
6 + self.items = [
7 + {id: 1, label: 'First', done: true},
8 + {id: 2, label: 'Second', done: false}
9 + ];
10 +
11 + self.getDoneClass = function (item) {
12 + return {
13 + finished: item.done,
14 + unfinished: !item.done
15 + };
16 + };
17 + }]);
This diff is collapsed. Click to expand it.
1 +// Karma configuration
2 +// Generated on Tue Dec 09 2014 10:41:03 GMT-0800 (PST)
3 +
4 +module.exports = function(config) {
5 + config.set({
6 +
7 + // base path that will be used to resolve all patterns (eg. files, exclude)
8 + basePath: '',
9 +
10 +
11 + // frameworks to use
12 + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13 + frameworks: ['jasmine'],
14 +
15 +
16 + // list of files / patterns to load in the browser
17 + files: [
18 + '../../main/webapp/tp/angular.min.js',
19 + '../../main/webapp/tp/angular-mocks.js',
20 + '../../main/webapp/_sdh/ng-examples/js/*.js',
21 + '../webapp/_sdh/ng-examples/js/*.js'
22 + ],
23 +
24 +
25 + // list of files to exclude
26 + exclude: [
27 + ],
28 +
29 +
30 + // preprocess matching files before serving them to the browser
31 + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
32 + preprocessors: {
33 + },
34 +
35 +
36 + // test results reporter to use
37 + // possible values: 'dots', 'progress'
38 + // available reporters: https://npmjs.org/browse/keyword/karma-reporter
39 + reporters: ['progress'],
40 +
41 +
42 + // web server port
43 + port: 9876,
44 +
45 +
46 + // enable / disable colors in the output (reporters and logs)
47 + colors: true,
48 +
49 +
50 + // level of logging
51 + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
52 + logLevel: config.LOG_INFO,
53 +
54 +
55 + // enable / disable watching file and executing tests whenever any file changes
56 + autoWatch: true,
57 +
58 +
59 + // start these browsers
60 + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
61 + browsers: ['Chrome'],
62 +
63 +
64 + // Continuous Integration mode
65 + // if true, Karma captures browsers, runs the tests and exits
66 + singleRun: false
67 + });
68 +};
1 +// Jasmine unit tests for ch03-controller.js
2 +
3 +describe('Controller: ListCtrl', function () {
4 + // instantiate a new version of my module before each test
5 + beforeEach(module('notesApp'));
6 +
7 + var ctrl;
8 +
9 + // before each unit test, instantiate a new instance of the controller
10 + beforeEach(inject(function ($controller) {
11 + ctrl = $controller('ListCtrl');
12 + }));
13 +
14 + it('should have items available on load', function () {
15 + expect(ctrl.items).toEqual([
16 + {id: 1, label: 'First', done: true},
17 + {id: 2, label: 'Second', done: false}
18 + ]);
19 + });
20 +
21 + it('should have highlight items based on state', function () {
22 + var item = {id: 1, label: 'First', done: true};
23 +
24 + var actualClass = ctrl.getDoneClass(item);
25 + expect(actualClass.finished).toBeTruthy();
26 + expect(actualClass.unfinished).toBeFalsy();
27 +
28 + item.done = false;
29 +
30 + actualClass = ctrl.getDoneClass(item);
31 + expect(actualClass.finished).toBeFalsy();
32 + expect(actualClass.unfinished).toBeTruthy();
33 + });
34 +
35 +});
...\ No newline at end of file ...\ No newline at end of file