Introduce JS unit tests into VID 35/77435/7
authorgolabek <tomasz.golabek@nokia.com>
Mon, 28 Jan 2019 08:34:48 +0000 (09:34 +0100)
committergolabek <tomasz.golabek@nokia.com>
Fri, 1 Feb 2019 10:05:48 +0000 (11:05 +0100)
maven -> npm -> gulp -> jest frameworks added in a mentioned order.

Change-Id: I1865228973eb31188fb052e8c9629f0ac01e48a7
Issue-ID: VID-391
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
vid-app-common/gulpfile.js [new file with mode: 0644]
vid-app-common/jest.config.js [new file with mode: 0644]
vid-app-common/package.json [new file with mode: 0644]
vid-app-common/pom.xml
vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.js
vid-app-common/src/main/webapp/app/vid/scripts/controller/aaiSubscriberController.test.js [new file with mode: 0644]
vid-app-common/test-config.js [new file with mode: 0644]

diff --git a/vid-app-common/gulpfile.js b/vid-app-common/gulpfile.js
new file mode 100644 (file)
index 0000000..898f84f
--- /dev/null
@@ -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 (file)
index 0000000..e9ca59b
--- /dev/null
@@ -0,0 +1,16 @@
+module.exports = {
+  verbose: true,
+  roots: [
+    "<rootDir>/src/main/webapp/app"
+  ],
+  modulePaths: [
+    "<rootDir>/src/main/webapp/app/vid/external"
+  ],
+  setupFilesAfterEnv: ["<rootDir>/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 (file)
index 0000000..fb8d5d7
--- /dev/null
@@ -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"
+  }
+}
index 7cd30a2..1ea0691 100755 (executable)
@@ -37,6 +37,9 @@
         <kotlin.version>1.3.11</kotlin.version>
         <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
 
+        <eirslett.version>1.6</eirslett.version>
+        <node.version>v6.16.0</node.version>
+
     </properties>
 
 
                 <version>2.2</version>
             </plugin>
 
+            <plugin>
+                <groupId>com.github.eirslett</groupId>
+                <artifactId>frontend-maven-plugin</artifactId>
+                <version>${eirslett.version}</version>
+                <executions>
+                    <execution>
+                        <id>install node and npm</id>
+                        <goals>
+                            <goal>install-node-and-npm</goal>
+                        </goals>
+                        <phase>generate-resources</phase>
+                        <configuration>
+                            <nodeVersion>${node.version}</nodeVersion>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>npm run-script build</id>
+                        <configuration>
+                            <arguments>run-script build</arguments>
+                        </configuration>
+                        <goals>
+                            <goal>npm</goal>
+                        </goals>
+                        <phase>generate-resources</phase>
+                    </execution>
+                </executions>
+            </plugin>
+
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
index bb3acad..3bf05ea 100755 (executable)
@@ -1583,7 +1583,6 @@ appDS2.controller('TreeCtrl', ['$scope', function ($scope) {
         $scope.$broadcast(FIELD.ID.ANGULAR_UI_TREE_EXPANDALL);\r
     };\r
 \r
-\r
 }]);\r
 \r
 \r
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 (file)
index 0000000..4af9a29
--- /dev/null
@@ -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 (file)
index 0000000..32bac38
--- /dev/null
@@ -0,0 +1,4 @@
+require("angular-feature-flags/demo/vendor/angular.min");
+require("angular-mocks");
+
+global.appDS2=angular.module("app", []);