-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathmenu.js
102 lines (95 loc) · 2.44 KB
/
menu.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
// Test dependencies are required and exposed in common/bootstrap.js
require('../common/bootstrap');
/*global Menu */
exports['Menu.prompt'] = {
setUp(done) {
this.sandbox = sinon.sandbox.create();
this.logWarn = this.sandbox.stub(log, 'warn');
this.logInfo = this.sandbox.stub(log, 'info');
this.logBasic = this.sandbox.stub(log, 'basic');
done();
},
tearDown(done) {
this.sandbox.restore();
done();
},
selectItem(test) {
test.expect(2);
var a = new TesselSimulator({
type: 'LAN',
name: 'Tessel-A',
authorized: true
});
var b = new TesselSimulator({
type: 'LAN',
name: 'Tessel-B',
serialNumber: '1234'
});
var tessels = [a, b];
var map = {};
this.prompt = this.sandbox.stub(inquirer, 'prompt').callsFake(function(questions, callback) {
// This matches the inquirer.prompt return value. Do not change.
callback({
selected: questions[0].choices[0]
});
});
Menu.prompt({
prompt: {
name: 'selected',
type: 'list',
message: 'Pick one',
choices: tessels.map((tessel, i) => {
map[tessel.name] = i;
return tessel.name;
})
},
translate(answer) {
test.ok(true);
return tessels[map[answer.selected]];
}
}).then((tessel) => {
test.equal(tessel, a);
test.done();
});
},
noSelectedItem(test) {
test.expect(2);
var a = new TesselSimulator({
type: 'LAN',
name: 'Tessel-A',
authorized: true
});
var b = new TesselSimulator({
type: 'LAN',
name: 'Tessel-B',
serialNumber: '1234'
});
var tessels = [a, b];
var map = {};
this.prompt = this.sandbox.stub(inquirer, 'prompt').callsFake(function(questions, callback) {
// This matches the inquirer.prompt return value. Do not change.
// controller.menu adds an "Exit" choice
callback({
selected: questions[0].choices[2]
});
});
Menu.prompt({
prompt: {
name: 'selected',
type: 'list',
message: 'Pick one',
choices: tessels.map((tessel, i) => {
map[tessel.name] = i;
return tessel.name;
})
},
translate(answer) {
test.equal(answer.selected, '\tExit');
return tessels[map[answer.selected]];
}
}).then((tessel) => {
test.equal(tessels.indexOf(tessel), -1);
test.done();
});
}
};