-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
Copy pathroute-home.js
109 lines (94 loc) · 3.5 KB
/
route-home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
const assert = require('assert');
const _ = require('lodash');
const sinon = require('sinon');
const inquirer = require('inquirer');
const Router = require('../lib/router');
const helpers = require('./helpers');
describe('home route', () => {
beforeEach(async function () {
this.sandbox = sinon.createSandbox();
this.env = await helpers.fakeEnv();
this.router = new Router(this.env, this.insight);
this.router.registerRoute('home', require('../lib/routes/home'));
this.runRoute = sinon.stub().returns(Promise.resolve());
this.router.registerRoute('run', this.runRoute);
this.helpRoute = sinon.stub().returns(Promise.resolve());
this.router.registerRoute('help', this.helpRoute);
this.installRoute = sinon.stub().returns(Promise.resolve());
this.router.registerRoute('install', this.installRoute);
this.updateRoute = sinon.stub().returns(Promise.resolve());
this.router.registerRoute('update', this.updateRoute);
});
afterEach(function () {
this.sandbox.restore();
});
it('allow going to help', function () {
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: 'help'}));
return this.router.navigate('home').then(() => {
sinon.assert.calledOnce(this.helpRoute);
});
});
it('allow going to install', function () {
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: 'install'}));
return this.router.navigate('home').then(() => {
sinon.assert.calledOnce(this.installRoute);
});
});
it('does not display update options if no generators is installed', function () {
this.router.generator = [];
this.sandbox.stub(inquirer, 'prompt').callsFake(prompts => {
assert.strictEqual(_.map(prompts[0].choices, 'value').includes('update'), false);
return Promise.resolve({whatNext: 'exit'});
});
return this.router.navigate('home');
});
it('show update menu option if there is installed generators', function () {
this.router.generators = [{
namespace: 'unicorn:app',
appGenerator: true,
prettyName: 'unicorn',
updateAvailable: false
}];
this.sandbox.stub(inquirer, 'prompt').callsFake(prompts => {
assert(_.map(prompts[0].choices, 'value').includes('update'));
return Promise.resolve({whatNext: 'update'});
});
return this.router.navigate('home').then(() => {
sinon.assert.calledOnce(this.updateRoute);
});
});
it('list runnable generators', function () {
this.router.generators = [{
namespace: 'unicorn:app',
appGenerator: true,
prettyName: 'unicorn',
updateAvailable: false
}];
this.sandbox.stub(inquirer, 'prompt').callsFake(prompts => {
assert.strictEqual(prompts[0].choices[1].value.generator, 'unicorn:app');
return Promise.resolve({
whatNext: {
method: 'run',
generator: 'unicorn:app'
}
});
});
return this.router.navigate('home').then(() => {
sinon.assert.calledWith(this.runRoute, this.router, 'unicorn:app');
});
});
it('show update available message behind generator name', function () {
this.router.generators = [{
namespace: 'unicorn:app',
appGenerator: true,
prettyName: 'unicorn',
updateAvailable: true
}];
this.sandbox.stub(inquirer, 'prompt').callsFake(prompts => {
assert(prompts[0].choices[1].name.includes('♥ Update Available!'));
return Promise.resolve({whatNext: 'exit'});
});
return this.router.navigate('home');
});
});