blob: 54c28b5ad8720fe81cd50a1758800f0e808e68ba [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070019'use strict';
20
21const path = require('path');
22const helpers = require('yeoman-test');
23const assert = require('yeoman-assert');
Matteo Scandolo07dd2762016-05-11 11:52:10 -070024const rimraf = require('rimraf');
25const mockery = require('mockery');
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070026
Matteo Scandolo07dd2762016-05-11 11:52:10 -070027const firstCharTouppercase = string => string.replace(/^./, string[0].toUpperCase())
28
Matteo Scandolo223f9312016-10-28 10:47:21 +020029const ngVersion = '1.5.8';
30const ngXosLibVersion = `1.1.0`;
31
Matteo Scandolo195dde92016-07-25 16:43:16 -070032const bowerDeps = [
Matteo Scandolo223f9312016-10-28 10:47:21 +020033 `"angular": "${ngVersion}"`,
Matteo Scandolo195dde92016-07-25 16:43:16 -070034 'angular-ui-router',
Matteo Scandolo223f9312016-10-28 10:47:21 +020035 `"angular-resource": "${ngVersion}"`,
36 `"angular-cookies": "${ngVersion}"`,
37 `"angular-animate": "${ngVersion}"`,
Matteo Scandolo195dde92016-07-25 16:43:16 -070038 'lodash',
39 'angular-chart.js',
40 'd3',
Matteo Scandolo223f9312016-10-28 10:47:21 +020041 'angular-recursion', // NOTE check if it is still needed
42 `"ng-xos-lib": "opencord/ng-xos-lib#${ngXosLibVersion}"`
Matteo Scandolo195dde92016-07-25 16:43:16 -070043];
Matteo Scandolo07dd2762016-05-11 11:52:10 -070044
45// test values
46const viewName = 'testDashboard';
Matteo Scandoloce6624c2016-05-11 12:10:17 -070047const fileName = firstCharTouppercase(viewName);
Matteo Scandolo07dd2762016-05-11 11:52:10 -070048const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070049
50const getDefaultFiles = () => {
51 return [
Matteo Scandolo07dd2762016-05-11 11:52:10 -070052 '.bowerrc',
53 '.eslintrc',
54 '.gitignore',
55 'bower.json',
56 'gulpfile.js',
57 'karma.conf.js',
58 'package.json',
59 'src/index.html',
60 ].map(i => `${testPath}${i}`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070061};
62
Matteo Scandolo07dd2762016-05-11 11:52:10 -070063const yeomanUserMock = {
64 git: {
65 name: () => 'Test User',
66 email: () => 'test@mail.org'
67 }
Matteo Scandolob70db482016-07-06 10:39:36 -070068};
Matteo Scandolo07dd2762016-05-11 11:52:10 -070069
70mockery.enable({
71 warnOnReplace: false,
72 warnOnUnregistered: false,
73 useCleanCache: true,
74});
75mockery.resetCache();
76mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock);
77
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070078describe('Yeoman XOS generator', function () {
79
Matteo Scandolo07dd2762016-05-11 11:52:10 -070080 beforeEach(() => {
81 });
82
83 before(done => {
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070084 this.generator = helpers
85 .run(require.resolve('../app'))
86 .inDir(testPath)
87 .withOptions({ 'skip-install': true })
88 .withPrompts({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070089 name: viewName
Matteo Scandolo07dd2762016-05-11 11:52:10 -070090 })
91 .on('end', done);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070092 });
93
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070094
Matteo Scandolo07dd2762016-05-11 11:52:10 -070095 it('should generate base files in the correct directory', () => {
96 assert.file(getDefaultFiles());
97 });
98
Matteo Scandolo07dd2762016-05-11 11:52:10 -070099 it('should write username in package & bower json', () => {
100 assert.fileContent(`${testPath}package.json`, '"author": "Test User"');
101 assert.fileContent(`${testPath}bower.json`, '"Test User <test@mail.org>"')
102 });
103
104 it('should add all xosLib dependencies in the dev section of bower.json', () => {
105 bowerDeps.forEach(d => {
106 assert.fileContent(`${testPath}bower.json`, d);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -0700107 });
108 });
Matteo Scandolo07dd2762016-05-11 11:52:10 -0700109
110 it('should set the right module name in all the files', () => {
111 assert.fileContent(`${testPath}src/index.html`, `ng-app="xos.${viewName}"`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -0700112 assert.fileContent(`${testPath}src/index.html`, `id="xos${fileName}"`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -0700113 assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -0700114 assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${fileName}`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -0700115 });
116
Matteo Scandoloce6624c2016-05-11 12:10:17 -0700117 it('should set correct paths in build file', () => {
118 assert.fileContent(`${testPath}gulp/build.js`, `angular.module('xos.${viewName}')`)
119 assert.fileContent(`${testPath}gulp/build.js`, `options.dashboards + 'xos${fileName}.html'`)
120 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`)
121 assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.css'))`)
122 assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.js'))`)
123 assert.fileContent(`${testPath}gulp/build.js`, `module: 'xos.${viewName}'`)
Matteo Scandolo195dde92016-07-25 16:43:16 -0700124 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'vendor/xos${fileName}Vendor.js'`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -0700125 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'js/xos${fileName}.js'`)
126 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`)
127 assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}Vendor.js'))`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -0700128 });
129
130 after(done => {
131 // deleting the folder used for test
132 rimraf(testPath, {}, done)
133 });
Matteo Scandolo124bbfc2016-05-11 09:03:25 -0700134});