blob: 0db5cfe3d653376d3a1b0a40e6d227fbf2ed6e68 [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});
17bowerDeps = bowerDeps.js.map(d => d.match(/bower_components\/([a-zA-Z\-`.]+)\//)[1]);
18
19// test values
20const viewName = 'testDashboard';
21const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070022
23const getDefaultFiles = () => {
24 return [
Matteo Scandolo07dd2762016-05-11 11:52:10 -070025 '.bowerrc',
26 '.eslintrc',
27 '.gitignore',
28 'bower.json',
29 'gulpfile.js',
30 'karma.conf.js',
31 'package.json',
32 'src/index.html',
33 ].map(i => `${testPath}${i}`);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070034};
35
Matteo Scandolo07dd2762016-05-11 11:52:10 -070036const yeomanUserMock = {
37 git: {
38 name: () => 'Test User',
39 email: () => 'test@mail.org'
40 }
41}
42
43mockery.enable({
44 warnOnReplace: false,
45 warnOnUnregistered: false,
46 useCleanCache: true,
47});
48mockery.resetCache();
49mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock);
50
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070051describe('Yeoman XOS generator', function () {
52
Matteo Scandolo07dd2762016-05-11 11:52:10 -070053 beforeEach(() => {
54 });
55
56 before(done => {
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070057 this.generator = helpers
58 .run(require.resolve('../app'))
59 .inDir(testPath)
60 .withOptions({ 'skip-install': true })
61 .withPrompts({
Matteo Scandolo07dd2762016-05-11 11:52:10 -070062 name: viewName,
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070063 host: 'test-host',
64 token: 'test-token',
65 session: 'test-session'
Matteo Scandolo07dd2762016-05-11 11:52:10 -070066 })
67 .on('end', done);
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070068 });
69
Matteo Scandolo124bbfc2016-05-11 09:03:25 -070070
Matteo Scandolo07dd2762016-05-11 11:52:10 -070071 it('should generate base files in the correct directory', () => {
72 assert.file(getDefaultFiles());
73 });
74
75 it('should create the env file with correct params', () => {
76 assert.fileContent(`${testPath}env/default.js`, 'host: \'test-host\'');
77 assert.fileContent(`${testPath}env/default.js`, 'xoscsrftoken: \'test-token\'');
78 assert.fileContent(`${testPath}env/default.js`, 'xossessionid: \'test-session\'');
79 });
80
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 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}"`)
94 assert.fileContent(`${testPath}src/index.html`, `id="xos${firstCharTouppercase(viewName)}"`)
95 assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`)
96 assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${firstCharTouppercase(viewName)}`)
97 });
98
99 xit('should create a correct gulp build file', () => {
100
101 });
102
103 after(done => {
104 // deleting the folder used for test
105 rimraf(testPath, {}, done)
106 });
Matteo Scandolo124bbfc2016-05-11 09:03:25 -0700107});