-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
Copy pathroute-clear-config.js
100 lines (91 loc) · 3.09 KB
/
route-clear-config.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
'use strict';
const assert = require('assert');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
const _ = require('lodash');
const inquirer = require('inquirer');
const Router = require('../lib/router');
describe('clear config route', () => {
beforeEach(function () {
this.sandbox = sinon.createSandbox();
this.globalConfig = {
remove: sinon.stub(),
removeAll: sinon.stub(),
getAll() {
return {
'generator-phoenix': {},
'generator-unicorn': {}
};
}
};
const conf = {
get() {
return {
unicorn: 20,
phoenix: 10
};
}
};
this.homeRoute = sinon.stub().returns(Promise.resolve());
this.router = new Router(sinon.stub(), conf);
this.router.registerRoute('home', this.homeRoute);
const clearConfig = proxyquire('../lib/routes/clear-config', {
'../utils/global-config': this.globalConfig
});
this.router.registerRoute('clearConfig', clearConfig);
this.router.generators = {
'generator-unicorn': {
name: 'generator-unicorn',
prettyName: 'Unicorn',
namespace: 'unicorn:app'
},
'generator-foo': {
name: 'generator-foo',
prettyName: 'Foo',
namespace: 'foo:app'
}
};
});
afterEach(function () {
this.sandbox.restore();
});
it('allow returning home', function () {
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: 'home'}));
return this.router.navigate('clearConfig').then(() => {
sinon.assert.calledOnce(this.homeRoute);
});
});
it('allows clearing a generator and return user to home screen', function () {
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: 'foo'}));
this.router.navigate('clearConfig').then(() => {
sinon.assert.calledOnce(this.globalConfig.remove);
sinon.assert.calledWith(this.globalConfig.remove, 'foo');
sinon.assert.calledOnce(this.homeRoute);
});
});
it('allows clearing all generators and return user to home screen', function () {
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: '*'}));
return this.router.navigate('clearConfig').then(() => {
sinon.assert.calledOnce(this.globalConfig.removeAll);
sinon.assert.calledOnce(this.homeRoute);
});
});
it('shows generator with global config entry', function () {
let choices = [];
this.sandbox.stub(inquirer, 'prompt').callsFake(arg => {
({choices} = arg[0]);
return Promise.resolve({whatNext: 'foo'});
});
return this.router.navigate('clearConfig').then(() => {
// Clear all generators entry is present
assert.ok(_.find(choices, {value: '*'}));
assert.ok(_.find(choices, {value: 'generator-unicorn'}));
assert.ok(_.find(choices, {value: 'generator-phoenix'}));
assert.ok(_.find(choices, {name: 'Unicorn'}));
assert.ok(
_.find(choices, {name: 'phoenix\u001B[31m (not installed anymore)\u001B[39m'}) ||
_.find(choices, {name: 'phoenix (not installed anymore)'})
);
});
});
});