blob: 81ac985d0738d76138705834fdea9dcd7a023e0a [file] [log] [blame]
Matteo Scandolo124bbfc2016-05-11 09:03:25 -07001'use strict';
2
3const path = require('path');
4const helpers = require('yeoman-test');
5const assert = require('yeoman-assert');
Matteo Scandolo07dd2762016-05-11 11:52:10 -07006const rimraf = require('rimraf');
7const mockery = require('mockery');
8const wiredep = require('wiredep');
Matteo Scandolo124bbfc2016-05-11 09:03:25 -07009
Matteo Scandolo07dd2762016-05-11 11:52:10 -070010const firstCharTouppercase = string => string.replace(/^./, string[0].toUpperCase())
11
12// get bower deps installed in ngXosLib
13let bowerDeps = wiredep({
14 cwd: path.join(__dirname, '../../'), // pretending to be in the ngXosLib root
15 exclude: ['Chart.js']
16});
Matteo Scandolodb20d5a2016-05-16 10:31:32 -070017bowerDeps = bowerDeps.js.map(d => {
18 let path = d.match(/bower_components\/([1-9a-zA-Z\-`.]+)\//);
19 if(path){
20 return path[1];
21 }
22});
Matteo Scandolo07dd2762016-05-11 11:52:10 -070023
24// test values
25const viewName = 'testDashboard';
Matteo Scandoloce6624c2016-05-11 12:10:17 -070026const fileName = firstCharTouppercase(viewName);
Matteo Scandolo07dd2762016-05-11 11:52:10 -070027const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070028
29const getDefaultFiles = () => {
30 return [
Matteo Scandolo07dd2762016-05-11 11:52:10 -070031 '.bowerrc',
32 '.eslintrc',
33 '.gitignore',
34 'bower.json',
35 'gulpfile.js',
36 'karma.conf.js',
37 'package.json',
38 'src/index.html',
39 ].map(i => `${testPath}${i}`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070040};
41
Matteo Scandolo07dd2762016-05-11 11:52:10 -070042const yeomanUserMock = {
43 git: {
44 name: () => 'Test User',
45 email: () => 'test@mail.org'
46 }
Matteo Scandolob70db482016-07-06 10:39:36 -070047};
Matteo Scandolo07dd2762016-05-11 11:52:10 -070048
49mockery.enable({
50 warnOnReplace: false,
51 warnOnUnregistered: false,
52 useCleanCache: true,
53});
54mockery.resetCache();
55mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock);
56
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070057describe('Yeoman XOS generator', function () {
58
Matteo Scandolo07dd2762016-05-11 11:52:10 -070059 beforeEach(() => {
60 });
61
62 before(done => {
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070063 this.generator = helpers
64 .run(require.resolve('../app'))
65 .inDir(testPath)
66 .withOptions({ 'skip-install': true })
67 .withPrompts({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070068 name: viewName
Matteo Scandolo07dd2762016-05-11 11:52:10 -070069 })
70 .on('end', done);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070071 });
72
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070073
Matteo Scandolo07dd2762016-05-11 11:52:10 -070074 it('should generate base files in the correct directory', () => {
75 assert.file(getDefaultFiles());
76 });
77
Matteo Scandolo07dd2762016-05-11 11:52:10 -070078 it('should write username in package & bower json', () => {
79 assert.fileContent(`${testPath}package.json`, '"author": "Test User"');
80 assert.fileContent(`${testPath}bower.json`, '"Test User <test@mail.org>"')
81 });
82
83 it('should add all xosLib dependencies in the dev section of bower.json', () => {
84 bowerDeps.forEach(d => {
85 assert.fileContent(`${testPath}bower.json`, d);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070086 });
87 });
Matteo Scandolo07dd2762016-05-11 11:52:10 -070088
89 it('should set the right module name in all the files', () => {
90 assert.fileContent(`${testPath}src/index.html`, `ng-app="xos.${viewName}"`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -070091 assert.fileContent(`${testPath}src/index.html`, `id="xos${fileName}"`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -070092 assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -070093 assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${fileName}`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -070094 });
95
Matteo Scandoloce6624c2016-05-11 12:10:17 -070096 it('should set correct paths in build file', () => {
97 assert.fileContent(`${testPath}gulp/build.js`, `angular.module('xos.${viewName}')`)
98 assert.fileContent(`${testPath}gulp/build.js`, `options.dashboards + 'xos${fileName}.html'`)
99 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`)
100 assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.css'))`)
101 assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.js'))`)
102 assert.fileContent(`${testPath}gulp/build.js`, `module: 'xos.${viewName}'`)
103 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'js/vendor/xos${fileName}Vendor.js'`)
104 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'js/xos${fileName}.js'`)
105 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`)
106 assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}Vendor.js'))`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -0700107 });
108
109 after(done => {
110 // deleting the folder used for test
111 rimraf(testPath, {}, done)
112 });
Matteo Scandolo124bbfc2016-05-11 09:03:25 -0700113});