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