blob: 50ec25e8cd7dad41c7e21cfda8264f4e9dbc8d2a [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
Matteo Scandolo195dde92016-07-25 16:43:16 -070012const 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 Scandolo07dd2762016-05-11 11:52:10 -070024
25// test values
26const viewName = 'testDashboard';
Matteo Scandoloce6624c2016-05-11 12:10:17 -070027const fileName = firstCharTouppercase(viewName);
Matteo Scandolo07dd2762016-05-11 11:52:10 -070028const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070029
30const getDefaultFiles = () => {
31 return [
Matteo Scandolo07dd2762016-05-11 11:52:10 -070032 '.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 Scandolo124bbfc2016-05-11 09:03:25 -070041};
42
Matteo Scandolo07dd2762016-05-11 11:52:10 -070043const yeomanUserMock = {
44 git: {
45 name: () => 'Test User',
46 email: () => 'test@mail.org'
47 }
Matteo Scandolob70db482016-07-06 10:39:36 -070048};
Matteo Scandolo07dd2762016-05-11 11:52:10 -070049
50mockery.enable({
51 warnOnReplace: false,
52 warnOnUnregistered: false,
53 useCleanCache: true,
54});
55mockery.resetCache();
56mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock);
57
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070058describe('Yeoman XOS generator', function () {
59
Matteo Scandolo07dd2762016-05-11 11:52:10 -070060 beforeEach(() => {
61 });
62
63 before(done => {
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070064 this.generator = helpers
65 .run(require.resolve('../app'))
66 .inDir(testPath)
67 .withOptions({ 'skip-install': true })
68 .withPrompts({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070069 name: viewName
Matteo Scandolo07dd2762016-05-11 11:52:10 -070070 })
71 .on('end', done);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070072 });
73
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070074
Matteo Scandolo07dd2762016-05-11 11:52:10 -070075 it('should generate base files in the correct directory', () => {
76 assert.file(getDefaultFiles());
77 });
78
Matteo Scandolo07dd2762016-05-11 11:52:10 -070079 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 Scandolo124bbfc2016-05-11 09:03:25 -070087 });
88 });
Matteo Scandolo07dd2762016-05-11 11:52:10 -070089
90 it('should set the right module name in all the files', () => {
91 assert.fileContent(`${testPath}src/index.html`, `ng-app="xos.${viewName}"`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -070092 assert.fileContent(`${testPath}src/index.html`, `id="xos${fileName}"`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -070093 assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -070094 assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${fileName}`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -070095 });
96
Matteo Scandoloce6624c2016-05-11 12:10:17 -070097 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 Scandolo195dde92016-07-25 16:43:16 -0700104 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'vendor/xos${fileName}Vendor.js'`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -0700105 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 Scandolo07dd2762016-05-11 11:52:10 -0700108 });
109
110 after(done => {
111 // deleting the folder used for test
112 rimraf(testPath, {}, done)
113 });
Matteo Scandolo124bbfc2016-05-11 09:03:25 -0700114});