← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21019: Merge of test setup for shared tracker code

 

Merge authors:
  Mark Polak (markpo)
------------------------------------------------------------
revno: 21019 [merge]
committer: Mark Polak <markpo@xxxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-11-10 21:26:25 +0100
message:
  Merge of test setup for shared tracker code
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.babelrc
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.eslintrc
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/package.json
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/ColumnDisplayController.test.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/MapController.test.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/karma.config.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/tests.webpack.js
modified:
  .bzrignore


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file '.bzrignore'
--- .bzrignore	2015-06-11 18:44:52 +0000
+++ .bzrignore	2015-11-10 19:52:35 +0000
@@ -27,3 +27,5 @@
 ./.travis.yml
 .DS_Store
 dhis-2/projectFilesBackup
+**/dhis-web-commons/javascripts/dhis2/coverage/
+**/dhis-web-commons/javascripts/dhis2/node_modules/

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.babelrc'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.babelrc	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.babelrc	2015-11-10 19:52:35 +0000
@@ -0,0 +1,3 @@
+{
+  "presets": ["es2015"]
+}

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.eslintrc'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.eslintrc	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/.eslintrc	2015-11-10 20:05:24 +0000
@@ -0,0 +1,3 @@
+{
+  "extends": "dhis2"
+}

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/package.json'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/package.json	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/package.json	2015-11-10 20:20:50 +0000
@@ -0,0 +1,48 @@
+{
+  "name": "dhis2-common-tracker-tests",
+  "version": "0.0.1",
+  "description": "Package that takes care of the dependencies to run the tracker tests",
+  "main": "./",
+  "directories": {
+    "test": "test"
+  },
+  "scripts": {
+    "test": "./node_modules/karma-cli/bin/karma start test/karma.config.js --single-run",
+    "test-watch": "./node_modules/karma-cli/bin/karma start test/karma.config.js",
+    "test-cov": "npm test",
+    "posttest-cov": "open ./coverage/chrome/lcov-report/index.html",
+    "lint": "./node_modules/eslint/bin/eslint.js test"
+  },
+  "author": "Mark Polak",
+  "license": "BSD-3-Clause",
+  "dependencies": {
+    "babel-core": "^6.1.2",
+    "babel-loader": "^6.1.0",
+    "chai": "^3.4.1",
+    "karma": "^0.13.15",
+    "karma-chai": "^0.1.0",
+    "karma-chrome-launcher": "^0.2.1",
+    "karma-cli": "^0.1.1",
+    "karma-mocha": "^0.2.0",
+    "karma-sourcemap-loader": "^0.3.6",
+    "karma-webpack": "^1.7.0",
+    "mocha": "^2.3.3",
+    "webpack": "^1.12.3"
+  },
+  "devDependencies": {
+    "angular-mocks": "^1.3.15",
+    "babel-eslint": "^4.1.5",
+    "babel-preset-es2015": "^6.1.2",
+    "eslint": "^1.9.0",
+    "eslint-config-dhis2": "0.0.5",
+    "eslint-plugin-react": "^3.8.0",
+    "karma-coverage": "^0.5.3",
+    "karma-phantomjs-launcher": "^0.2.1",
+    "karma-sinon": "^1.0.4",
+    "karma-sinon-chai": "^1.1.0",
+    "phantomjs": "^1.9.18",
+    "phantomjs-polyfill": "0.0.1",
+    "sinon": "^1.17.2",
+    "sinon-chai": "^2.8.0"
+  }
+}

=== added directory 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test'
=== added directory 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers'
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/ColumnDisplayController.test.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/ColumnDisplayController.test.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/ColumnDisplayController.test.js	2015-11-10 19:52:35 +0000
@@ -0,0 +1,73 @@
+const {module, inject} = angular.mock;
+const {spy} = sinon;
+
+describe('Tracker Controllers: ColumnDisplayController', () => {
+    let columnDisplayController;
+    let mockScope;
+    let mock$modelInstance;
+
+    beforeEach(module('d2Controllers'));
+    beforeEach(inject(($injector) => {
+        const $controller = $injector.get('$controller');
+
+        mockScope = $injector.get('$rootScope').$new();
+        mock$modelInstance = {
+            close: spy(),
+        };
+
+        columnDisplayController = $controller('ColumnDisplayController', {
+            $scope: mockScope,
+            $modalInstance: mock$modelInstance,
+            hiddenGridColumns: 1,
+            gridColumns: 2,
+        });
+    }));
+
+    it('should be a registered in the module', () => {
+        expect(columnDisplayController).to.not.be.undefined;
+    });
+
+    it('should set the gridColumns onto the $scope', () => {
+        expect(mockScope.gridColumns).to.equal(2);
+    });
+
+    it('should set the hiddenGridColumns onto the $scope', () => {
+        expect(mockScope.hiddenGridColumns).to.equal(1);
+    });
+
+    it('should set a close() method onto the $scope', () => {
+        expect(mockScope.close).to.be.a('function');
+    });
+
+    it('should call close() on the $modalInstance when $scope.close() is called', () => {
+        mockScope.close();
+
+        expect(mock$modelInstance.close).to.be.calledOnce;
+    });
+
+    it('should call close() on the $modalInstance with the number of of gridColumns', () => {
+        mockScope.close();
+
+        expect(mock$modelInstance.close).to.be.calledWith(2);
+    });
+
+    it('should create the showHideColumns method onto the $scope', () => {
+        expect(mockScope.showHideColumns).to.be.a('function');
+    });
+
+    it('should descrease the hiddenGridColumns when the passed column is visible', () => {
+        const column = {show: true};
+
+        mockScope.showHideColumns(column);
+
+        expect(mockScope.hiddenGridColumns).to.equal(0);
+    });
+
+    it('should increase the hiddenGridColumns when the passed column is visible', () => {
+        const column = {show: false};
+
+        mockScope.showHideColumns(column);
+
+        expect(mockScope.hiddenGridColumns).to.equal(2);
+    });
+});

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/MapController.test.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/MapController.test.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/controllers/MapController.test.js	2015-11-10 20:05:24 +0000
@@ -0,0 +1,68 @@
+const {module, inject} = angular.mock;
+const {spy, stub} = sinon;
+
+describe('Tracker Controllers: MapController', () => {
+    let mapController;
+    let mockScope;
+    let mock$modelInstance;
+    let mockCurrentSelection;
+
+    beforeEach(module('d2Controllers'));
+    beforeEach(inject(($injector) => {
+        const $controller = $injector.get('$controller');
+
+        mockScope = $injector.get('$rootScope').$new();
+        mock$modelInstance = {
+            close: spy(),
+        };
+        mockCurrentSelection = {
+            getLocation: stub().returns('theCapturedLocation'),
+        };
+
+        mapController = $controller('MapController', {
+            $scope: mockScope,
+            $modalInstance: mock$modelInstance,
+            CurrentSelection: mockCurrentSelection,
+            DHIS2URL: 'http://localhost:8080/dhis',
+            location: 'theInjectedLocation',
+        });
+    }));
+
+    it('should be a registered in the module', () => {
+        expect(mapController).to.not.be.undefined;
+    });
+
+    it('should create a home() function on the $scope', () => {
+        expect(mockScope.home).to.be.a('function');
+    });
+
+    it('should create a close() function on the scope', () => {
+        expect(mockScope.close).to.be.a('function');
+    });
+
+    it('should create a captureCoordinate function on the scope', () => {
+        expect(mockScope.captureCoordinate).to.be.a('function');
+    });
+
+    it('should set the injected location onto the $scope', () => {
+        expect(mockScope.location).to.equal('theInjectedLocation');
+    });
+
+    it('should call close() on the $modelInstance when calling close() on the $scope', () => {
+        mockScope.close();
+
+        expect(mock$modelInstance.close).to.be.calledOnce;
+    });
+
+    it('should call close on the $modelInstance when calling captureCoordinate on the $scope', () => {
+        mockScope.captureCoordinate();
+
+        expect(mock$modelInstance.close).to.be.calledOnce;
+    });
+
+    it('should set the location on $scope to the location from CurrentLocation.getLocation()', () => {
+        mockScope.captureCoordinate();
+
+        expect(mockScope.location).to.equal('theCapturedLocation');
+    });
+});

=== added directory 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives'
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js	2015-11-10 19:52:35 +0000
@@ -0,0 +1,46 @@
+const {module, inject} = angular.mock;
+const {spy} = sinon;
+
+describe('Directives: d2SetFocus', () => {
+    let mock$scope;
+    let element;
+    let $timeout;
+    let render;
+
+    beforeEach(module('d2Directives'));
+    beforeEach(inject(($injector) => {
+        const $compile = $injector.get('$compile');
+        const $rootScope = $injector.get('$rootScope');
+
+        render = () => {
+            $compile(element)(mock$scope);
+            mock$scope.$digest();
+        };
+
+        $timeout = $injector.get('$timeout');
+        element = angular.element('<input d2-set-focus="true" />');
+        element[0].focus = spy();
+
+        mock$scope = $rootScope.$new();
+        mock$scope.isFocused = false;
+    }));
+
+    it('should render correctly', () => {
+        render();
+
+        $timeout.flush();
+
+        expect(element[0].focus).to.be.calledOnce;
+    });
+
+    it('should not set focus when the property is set to false', () => {
+        element = angular.element('<input d2-set-focus="false" />');
+        element[0].focus = spy();
+
+        render();
+
+        $timeout.flush();
+
+        expect(element[0].focus).to.not.be.called;
+    });
+});

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/karma.config.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/karma.config.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/karma.config.js	2015-11-10 20:20:50 +0000
@@ -0,0 +1,43 @@
+module.exports = function karmaConfigHandler(config) {
+    config.set({
+        browsers: [ 'PhantomJS' ], // run in Headless browser PhantomJS
+        singleRun: false,
+        frameworks: [
+            'mocha', // Test runner
+            'chai',  // Assertion library
+            'sinon', // Mocking library
+            'sinon-chai' // Assertions for mocks and spies
+        ],
+        files: [
+            '../node_modules/phantomjs-polyfill/bind-polyfill.js',
+            '../../angular/angular.js',
+            '../node_modules/angular-mocks/angular-mocks.js',
+            '../dhis2.angular.*.js',
+            'tests.webpack.js', // just load this file
+        ],
+        preprocessors: {
+            'tests.webpack.js': [ 'webpack', 'sourcemap' ], // preprocess with webpack and our sourcemap loader
+            '../dhis2.angular.*.js': ['coverage'],
+        },
+        reporters: [ 'dots', 'coverage' ], // report results in this format
+        coverageReporter: {
+            type: 'lcov',
+            dir: '../coverage',
+            subdir: function simplifyBrowsername(browser) {
+                // normalization process to keep a consistent browser name accross different OS
+                return browser.toLowerCase().split(/[ /-]/)[0];
+            },
+        },
+        webpack: { // kind of a copy of your webpack config
+            devtool: 'inline-source-map', // just do inline source maps instead of the default
+            module: {
+                loaders: [
+                    { test: /\.js$/, loader: 'babel-loader' },
+                ],
+            },
+        },
+        webpackServer: {
+            noInfo: true, // please don't spam the console when running in karma!
+        },
+    });
+};

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/tests.webpack.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/tests.webpack.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/tests.webpack.js	2015-11-10 20:05:24 +0000
@@ -0,0 +1,2 @@
+const context = require.context('./', true, /\.test\.js$/);
+context.keys().forEach(context);