From ec4f95457ec430838feeae6da48d0fd011ddffa9 Mon Sep 17 00:00:00 2001 From: golabek Date: Mon, 28 Jan 2019 09:34:48 +0100 Subject: Introduce JS unit tests into VID maven -> npm -> gulp -> jest frameworks added in a mentioned order. Change-Id: I1865228973eb31188fb052e8c9629f0ac01e48a7 Issue-ID: VID-391 Signed-off-by: Tomasz Golabek --- vid-app-common/gulpfile.js | 18 ++++++++++++ vid-app-common/jest.config.js | 16 +++++++++++ vid-app-common/package.json | 28 ++++++++++++++++++ vid-app-common/pom.xml | 31 ++++++++++++++++++++ .../scripts/controller/aaiSubscriberController.js | 1 - .../controller/aaiSubscriberController.test.js | 33 ++++++++++++++++++++++ vid-app-common/test-config.js | 4 +++ 7 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 vid-app-common/gulpfile.js create mode 100644 vid-app-common/jest.config.js create mode 100644 vid-app-common/package.json create mode 100644 vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.test.js create mode 100644 vid-app-common/test-config.js diff --git a/vid-app-common/gulpfile.js b/vid-app-common/gulpfile.js new file mode 100644 index 000000000..898f84fe4 --- /dev/null +++ b/vid-app-common/gulpfile.js @@ -0,0 +1,18 @@ +var gulp = require("gulp"); +var jest = require("jest"); + +// -------------- Run Jest Tests -------------- + +gulp.task("test", function() { + return jest.runCLI({}, ".") + .then((result) => { + if (!result.results.success){ + console.error("Execution of js tests failed with status 1"); + process.exit(1); + } + }); +}); + +// -------------- Default Task -------------- + +gulp.task("default", gulp.parallel(["test"])); \ No newline at end of file diff --git a/vid-app-common/jest.config.js b/vid-app-common/jest.config.js new file mode 100644 index 000000000..e9ca59b11 --- /dev/null +++ b/vid-app-common/jest.config.js @@ -0,0 +1,16 @@ +module.exports = { + verbose: true, + roots: [ + "/src/main/webapp/app" + ], + modulePaths: [ + "/src/main/webapp/app/vid/external" + ], + setupFilesAfterEnv: ["/test-config.js"], + collectCoverage: true, + collectCoverageFrom: [ + "src/**/*.js", + "!**/node_modules/**", + "!**/vendor/**" + ] +}; \ No newline at end of file diff --git a/vid-app-common/package.json b/vid-app-common/package.json new file mode 100644 index 000000000..fb8d5d762 --- /dev/null +++ b/vid-app-common/package.json @@ -0,0 +1,28 @@ +{ + "name": "vid-app-common", + "version": "4.0.0-SNAPSHOT", + "dependencies": { + "angular-bootstrap-multiselect": "^1.1.11", + "angular-feature-flags": "1.6.1", + "angular-moment": "^1.3.0", + "components-bootstrap": "3.3.7", + "glyphicons-only-bootstrap": "^1.0.1", + "lodash": "^4.17.11", + "moment": "^2.24.0", + "ng-file-upload": "^12.2.13" + }, + "scripts": { + "prebuild": "npm install", + "build": "gulp" + }, + "devDependencies": { + "angular-mocks": "1.2.19", + "gulp": "^4.0.0", + "gulp-inject": "^5.0.2", + "gulp-jest": "^4.0.2", + "gulp-uglify": "^3.0.1", + "jest": "^24.0.0", + "jest-mock": "^24.0.0", + "stream-series": "^0.1.1" + } +} diff --git a/vid-app-common/pom.xml b/vid-app-common/pom.xml index 7cd30a21f..1ea069137 100755 --- a/vid-app-common/pom.xml +++ b/vid-app-common/pom.xml @@ -37,6 +37,9 @@ 1.3.11 1.8 + 1.6 + v6.16.0 + @@ -157,6 +160,34 @@ 2.2 + + com.github.eirslett + frontend-maven-plugin + ${eirslett.version} + + + install node and npm + + install-node-and-npm + + generate-resources + + ${node.version} + + + + npm run-script build + + run-script build + + + npm + + generate-resources + + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.js b/vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.js index bb3acad1b..3bf05ea1a 100755 --- a/vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.js @@ -1583,7 +1583,6 @@ appDS2.controller('TreeCtrl', ['$scope', function ($scope) { $scope.$broadcast(FIELD.ID.ANGULAR_UI_TREE_EXPANDALL); }; - }]); diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.test.js new file mode 100644 index 000000000..4af9a2982 --- /dev/null +++ b/vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.test.js @@ -0,0 +1,33 @@ +require('./aaiSubscriberController'); +const jestMock = require('jest-mock'); + +describe('TreeCtrl testing', () => { + let $scope; + beforeEach( + angular.mock.module('app') + ); + + beforeEach(inject(function (_$controller_) { + $scope = {}; + _$controller_('TreeCtrl', { + $scope: $scope + }); + })); + + test('Verify expandAll calls broadcast with expand-all parameter', () => { + // given + const broadcast = jestMock.fn(); + $scope.$broadcast = broadcast; + FIELD = { + ID: { + ANGULAR_UI_TREE_EXPANDALL: "angular-ui-tree:expand-all" + } + }; + // when + $scope.expandAll(); + // then + expect(broadcast).toHaveBeenCalledWith("angular-ui-tree:expand-all"); + }); + +}); + diff --git a/vid-app-common/test-config.js b/vid-app-common/test-config.js new file mode 100644 index 000000000..32bac3873 --- /dev/null +++ b/vid-app-common/test-config.js @@ -0,0 +1,4 @@ +require("angular-feature-flags/demo/vendor/angular.min"); +require("angular-mocks"); + +global.appDS2=angular.module("app", []); -- cgit 1.2.3-korg