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