Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
| 21 | const path = require('path'); |
| 22 | const helpers = require('yeoman-test'); |
| 23 | const assert = require('yeoman-assert'); |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 24 | const rimraf = require('rimraf'); |
| 25 | const mockery = require('mockery'); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 26 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 27 | const firstCharTouppercase = string => string.replace(/^./, string[0].toUpperCase()) |
| 28 | |
Matteo Scandolo | 223f931 | 2016-10-28 10:47:21 +0200 | [diff] [blame] | 29 | const ngVersion = '1.5.8'; |
| 30 | const ngXosLibVersion = `1.1.0`; |
| 31 | |
Matteo Scandolo | 195dde9 | 2016-07-25 16:43:16 -0700 | [diff] [blame] | 32 | const bowerDeps = [ |
Matteo Scandolo | 223f931 | 2016-10-28 10:47:21 +0200 | [diff] [blame] | 33 | `"angular": "${ngVersion}"`, |
Matteo Scandolo | 195dde9 | 2016-07-25 16:43:16 -0700 | [diff] [blame] | 34 | 'angular-ui-router', |
Matteo Scandolo | 223f931 | 2016-10-28 10:47:21 +0200 | [diff] [blame] | 35 | `"angular-resource": "${ngVersion}"`, |
| 36 | `"angular-cookies": "${ngVersion}"`, |
| 37 | `"angular-animate": "${ngVersion}"`, |
Matteo Scandolo | 195dde9 | 2016-07-25 16:43:16 -0700 | [diff] [blame] | 38 | 'lodash', |
| 39 | 'angular-chart.js', |
| 40 | 'd3', |
Matteo Scandolo | 223f931 | 2016-10-28 10:47:21 +0200 | [diff] [blame] | 41 | 'angular-recursion', // NOTE check if it is still needed |
| 42 | `"ng-xos-lib": "opencord/ng-xos-lib#${ngXosLibVersion}"` |
Matteo Scandolo | 195dde9 | 2016-07-25 16:43:16 -0700 | [diff] [blame] | 43 | ]; |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 44 | |
| 45 | // test values |
| 46 | const viewName = 'testDashboard'; |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 47 | const fileName = firstCharTouppercase(viewName); |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 48 | const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 49 | |
| 50 | const getDefaultFiles = () => { |
| 51 | return [ |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 52 | '.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 Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 63 | const yeomanUserMock = { |
| 64 | git: { |
| 65 | name: () => 'Test User', |
| 66 | email: () => 'test@mail.org' |
| 67 | } |
Matteo Scandolo | b70db48 | 2016-07-06 10:39:36 -0700 | [diff] [blame] | 68 | }; |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 69 | |
| 70 | mockery.enable({ |
| 71 | warnOnReplace: false, |
| 72 | warnOnUnregistered: false, |
| 73 | useCleanCache: true, |
| 74 | }); |
| 75 | mockery.resetCache(); |
| 76 | mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock); |
| 77 | |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 78 | describe('Yeoman XOS generator', function () { |
| 79 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 80 | beforeEach(() => { |
| 81 | }); |
| 82 | |
| 83 | before(done => { |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 84 | this.generator = helpers |
| 85 | .run(require.resolve('../app')) |
| 86 | .inDir(testPath) |
| 87 | .withOptions({ 'skip-install': true }) |
| 88 | .withPrompts({ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 89 | name: viewName |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 90 | }) |
| 91 | .on('end', done); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 92 | }); |
| 93 | |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 94 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 95 | it('should generate base files in the correct directory', () => { |
| 96 | assert.file(getDefaultFiles()); |
| 97 | }); |
| 98 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 99 | 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 Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 107 | }); |
| 108 | }); |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 109 | |
| 110 | it('should set the right module name in all the files', () => { |
| 111 | assert.fileContent(`${testPath}src/index.html`, `ng-app="xos.${viewName}"`) |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 112 | assert.fileContent(`${testPath}src/index.html`, `id="xos${fileName}"`) |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 113 | assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`) |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 114 | assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${fileName}`) |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 115 | }); |
| 116 | |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 117 | 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 Scandolo | 195dde9 | 2016-07-25 16:43:16 -0700 | [diff] [blame] | 124 | assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'vendor/xos${fileName}Vendor.js'`) |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 125 | 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 Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 128 | }); |
| 129 | |
| 130 | after(done => { |
| 131 | // deleting the folder used for test |
| 132 | rimraf(testPath, {}, done) |
| 133 | }); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 134 | }); |