-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathquestionsSpec.js
More file actions
163 lines (140 loc) · 5.36 KB
/
Copy pathquestionsSpec.js
File metadata and controls
163 lines (140 loc) · 5.36 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
'use strict';
describe('cz-customizable', function() {
var questions, config;
beforeEach(function() {
questions = require('../questions.js');
config = null;
});
var mockedCz = {
Separator: jasmine.createSpy()
};
var getQuestion = function(number) {
return questions.getQuestions(config, mockedCz)[number - 1];
};
it('should array of questions be returned', function() {
config = {
types: [{ value: 'feat', name: 'feat: my feat' }],
scopes: [{ name: 'myScope' }],
scopeOverrides: {
fix: [{ name: 'fixOverride' }]
},
allowCustomScopes: true,
allowBreakingChanges: ['feat'],
subjectLimit: 20
};
// question 1 - TYPE
expect(getQuestion(1).name).toEqual('type');
expect(getQuestion(1).type).toEqual('list');
expect(getQuestion(1).choices[0]).toEqual({
value: 'feat',
name: 'feat: my feat'
});
// question 2 - SCOPE
expect(getQuestion(2).name).toEqual('scope');
expect(getQuestion(2).choices({})[0]).toEqual({ name: 'myScope' });
expect(getQuestion(2).choices({ type: 'fix' })[0]).toEqual({
name: 'fixOverride'
}); //should override scope
expect(getQuestion(2).when({ type: 'fix' })).toEqual(true);
expect(getQuestion(2).when({ type: 'WIP' })).toEqual(false);
expect(getQuestion(2).when({ type: 'wip' })).toEqual(false);
// question 3 - SCOPE CUSTOM
expect(getQuestion(3).name).toEqual('scope');
expect(getQuestion(3).when({ scope: 'custom' })).toEqual(true);
expect(getQuestion(3).when({ scope: false })).toEqual(false);
expect(getQuestion(3).when({ scope: 'scope' })).toEqual(false);
// question 4 - SUBJECT
expect(getQuestion(4).name).toEqual('subject');
expect(getQuestion(4).type).toEqual('input');
expect(getQuestion(4).message).toMatch(/IMPERATIVE tense description/);
expect(getQuestion(4).validate('good subject')).toEqual(true);
expect(getQuestion(4).validate('bad subject that exceed limit')).toEqual(
'Exceed limit: 20'
);
expect(getQuestion(4).filter('Subject')).toEqual('subject');
// question 5 - BODY
expect(getQuestion(5).name).toEqual('body');
expect(getQuestion(5).type).toEqual('input');
// question 6 - BREAKING CHANGE
expect(getQuestion(6).name).toEqual('breaking');
expect(getQuestion(6).type).toEqual('input');
expect(getQuestion(6).when({ type: 'feat' })).toEqual(true);
expect(getQuestion(6).when({ type: 'fix' })).toEqual(false);
// question 7 - FOOTER
expect(getQuestion(7).name).toEqual('footer');
expect(getQuestion(7).type).toEqual('input');
expect(getQuestion(7).when({ type: 'fix' })).toEqual(true);
expect(getQuestion(7).when({ type: 'WIP' })).toEqual(false);
//question 8, last one, CONFIRM COMMIT OR NOT
expect(getQuestion(9).name).toEqual('confirmCommit');
expect(getQuestion(9).type).toEqual('expand');
var answers = {
confirmCommit: 'yes',
type: 'feat',
scope: 'myScope',
subject: 'create a new cool feature'
};
expect(getQuestion(9).message(answers)).toMatch(
'Are you sure you want to proceed with the commit above?'
);
});
it('default length limit of subject should be 100', function() {
config = {
types: [{ value: 'feat', name: 'feat: my feat' }]
};
expect(getQuestion(4).validate('good subject')).toEqual(true);
expect(
getQuestion(4).validate(
'bad subject that exceed limit bad subject that exceed limitbad subject that exceed limit test test test'
)
).toEqual('Exceed limit: 100');
});
describe('optional fixOverride and allowBreakingChanges', function() {
it('should restrict BREAKING CHANGE question when config property "allowBreakingChanges" specifies array of types', function() {
config = {
types: [{ value: 'feat', name: 'feat: my feat' }],
scopes: [{ name: 'myScope' }],
allowBreakingChanges: ['fix']
};
expect(getQuestion(6).name).toEqual('breaking');
var answers = {
type: 'feat'
};
expect(getQuestion(6).when(answers)).toEqual(false); // not allowed
});
it('should allow BREAKING CHANGE question when config property "allowBreakingChanges" specifies array of types and answer is one of those', function() {
config = {
types: [{ value: 'feat', name: 'feat: my feat' }],
scopes: [{ name: 'myScope' }],
allowBreakingChanges: ['fix', 'feat']
};
expect(getQuestion(6).name).toEqual('breaking');
var answers = {
type: 'feat'
};
expect(getQuestion(6).when(answers)).toEqual(true); // allowed
});
});
describe('Optional scopes', function() {
it('should use scope override', function() {
config = {
types: [{ value: 'feat', name: 'feat: my feat' }],
scopeOverrides: {
feat: [{ name: 'myScope' }]
}
};
// question 2 with
expect(getQuestion(2).name).toEqual('scope');
expect(getQuestion(2).choices({})[0]).toBeUndefined();
expect(getQuestion(2).choices({ type: 'feat' })[0]).toEqual({
name: 'myScope'
}); //should override scope
expect(getQuestion(2).when({ type: 'feat' })).toEqual(true);
(function() {
var answers = { type: 'fix' };
expect(getQuestion(2).when(answers)).toEqual(false);
expect(answers.scope).toEqual('custom');
})();
});
});
});