blob: 78ed005c38e51e083b6a3dd76c33333340471a29 [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');
Matteo Scandolo124bbfc2016-05-11 09:03:25 -07008
Matteo Scandolo07dd2762016-05-11 11:52:10 -07009const firstCharTouppercase = string => string.replace(/^./, string[0].toUpperCase())
10
Matteo Scandolo223f9312016-10-28 10:47:21 +020011const ngVersion = '1.5.8';
12const ngXosLibVersion = `1.1.0`;
13
Matteo Scandolo195dde92016-07-25 16:43:16 -070014const bowerDeps = [
Matteo Scandolo223f9312016-10-28 10:47:21 +020015 `"angular": "${ngVersion}"`,
Matteo Scandolo195dde92016-07-25 16:43:16 -070016 'angular-ui-router',
Matteo Scandolo223f9312016-10-28 10:47:21 +020017 `"angular-resource": "${ngVersion}"`,
18 `"angular-cookies": "${ngVersion}"`,
19 `"angular-animate": "${ngVersion}"`,
Matteo Scandolo195dde92016-07-25 16:43:16 -070020 'lodash',
21 'angular-chart.js',
22 'd3',
Matteo Scandolo223f9312016-10-28 10:47:21 +020023 'angular-recursion', // NOTE check if it is still needed
24 `"ng-xos-lib": "opencord/ng-xos-lib#${ngXosLibVersion}"`
Matteo Scandolo195dde92016-07-25 16:43:16 -070025];
Matteo Scandolo07dd2762016-05-11 11:52:10 -070026
27// test values
28const viewName = 'testDashboard';
Matteo Scandoloce6624c2016-05-11 12:10:17 -070029const fileName = firstCharTouppercase(viewName);
Matteo Scandolo07dd2762016-05-11 11:52:10 -070030const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070031
32const getDefaultFiles = () => {
33 return [
Matteo Scandolo07dd2762016-05-11 11:52:10 -070034 '.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 Scandolo124bbfc2016-05-11 09:03:25 -070043};
44
Matteo Scandolo07dd2762016-05-11 11:52:10 -070045const yeomanUserMock = {
46 git: {
47 name: () => 'Test User',
48 email: () => 'test@mail.org'
49 }
Matteo Scandolob70db482016-07-06 10:39:36 -070050};
Matteo Scandolo07dd2762016-05-11 11:52:10 -070051
52mockery.enable({
53 warnOnReplace: false,
54 warnOnUnregistered: false,
55 useCleanCache: true,
56});
57mockery.resetCache();
58mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock);
59
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070060describe('Yeoman XOS generator', function () {
61
Matteo Scandolo07dd2762016-05-11 11:52:10 -070062 beforeEach(() => {
63 });
64
65 before(done => {
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070066 this.generator = helpers
67 .run(require.resolve('../app'))
68 .inDir(testPath)
69 .withOptions({ 'skip-install': true })
70 .withPrompts({
Matteo Scandolo4ac9a0b2016-05-23 15:31:25 -070071 name: viewName
Matteo Scandolo07dd2762016-05-11 11:52:10 -070072 })
73 .on('end', done);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070074 });
75
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070076
Matteo Scandolo07dd2762016-05-11 11:52:10 -070077 it('should generate base files in the correct directory', () => {
78 assert.file(getDefaultFiles());
79 });
80
Matteo Scandolo07dd2762016-05-11 11:52:10 -070081 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 Scandolo124bbfc2016-05-11 09:03:25 -070089 });
90 });
Matteo Scandolo07dd2762016-05-11 11:52:10 -070091
92 it('should set the right module name in all the files', () => {
93 assert.fileContent(`${testPath}src/index.html`, `ng-app="xos.${viewName}"`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -070094 assert.fileContent(`${testPath}src/index.html`, `id="xos${fileName}"`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -070095 assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -070096 assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${fileName}`)
Matteo Scandolo07dd2762016-05-11 11:52:10 -070097 });
98
Matteo Scandoloce6624c2016-05-11 12:10:17 -070099 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 Scandolo195dde92016-07-25 16:43:16 -0700106 assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'vendor/xos${fileName}Vendor.js'`)
Matteo Scandoloce6624c2016-05-11 12:10:17 -0700107 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 Scandolo07dd2762016-05-11 11:52:10 -0700110 });
111
112 after(done => {
113 // deleting the folder used for test
114 rimraf(testPath, {}, done)
115 });
Matteo Scandolo124bbfc2016-05-11 09:03:25 -0700116});