-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone-handler.helpers.test.ts
More file actions
190 lines (161 loc) · 4.98 KB
/
clone-handler.helpers.test.ts
File metadata and controls
190 lines (161 loc) · 4.98 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { expect } from 'chai';
import { CloneHandler } from '../../../src/core/util/clone-handler';
import { CloneConfig } from '../../../src/types/clone-config';
import sinon from 'sinon';
import inquirer from 'inquirer';
describe('CloneHandler - Helpers', () => {
describe('displayBackOptionMessage', () => {
let handler: CloneHandler;
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
const config: CloneConfig = {
cloneContext: {
command: 'test',
module: 'clone',
email: 'test@example.com',
},
};
handler = new CloneHandler(config);
});
afterEach(() => {
sandbox.restore();
});
it('should display back option message', () => {
const writeStub = sandbox.stub(process.stdout, 'write');
handler.displayBackOptionMessage();
expect(writeStub.calledOnce).to.be.true;
expect(writeStub.firstCall.args[0]).to.include('Press shift & left arrow together to undo');
writeStub.restore();
});
});
describe('setBackKeyPressHandler', () => {
let handler: CloneHandler;
beforeEach(() => {
const config: CloneConfig = {
cloneContext: {
command: 'test',
module: 'clone',
email: 'test@example.com',
},
};
handler = new CloneHandler(config);
});
it('should set back key press handler', () => {
const handlerFn = () => {};
handler.setBackKeyPressHandler(handlerFn);
// Handler is private, so we test indirectly by checking it doesn't throw
expect(handler).to.exist;
});
});
describe('removeBackKeyPressHandler', () => {
let handler: CloneHandler;
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
const config: CloneConfig = {
cloneContext: {
command: 'test',
module: 'clone',
email: 'test@example.com',
},
};
handler = new CloneHandler(config);
});
afterEach(() => {
sandbox.restore();
});
it('should remove back key press handler when handler exists', () => {
const handlerFn = () => {};
handler.setBackKeyPressHandler(handlerFn);
const removeListenerStub = sandbox.stub(process.stdin, 'removeListener');
handler.removeBackKeyPressHandler();
expect(removeListenerStub.calledOnce).to.be.true;
});
it('should not throw when handler does not exist', () => {
expect(() => handler.removeBackKeyPressHandler()).to.not.throw();
});
});
describe('setExectingCommand', () => {
let handler: CloneHandler;
beforeEach(() => {
const config: CloneConfig = {
cloneContext: {
command: 'test',
module: 'clone',
email: 'test@example.com',
},
};
handler = new CloneHandler(config);
});
it('should set executing command to 0 (org)', () => {
handler.setExectingCommand(0);
// Command is private, so we test indirectly
expect(handler).to.exist;
});
it('should set executing command to 1 (stack)', () => {
handler.setExectingCommand(1);
expect(handler).to.exist;
});
it('should set executing command to 2 (branch)', () => {
handler.setExectingCommand(2);
expect(handler).to.exist;
});
it('should set executing command to 3 (stack cancelled)', () => {
handler.setExectingCommand(3);
expect(handler).to.exist;
});
it('should set executing command to 4 (branch cancelled)', () => {
handler.setExectingCommand(4);
expect(handler).to.exist;
});
});
describe('setCreateNewStackPrompt', () => {
let handler: CloneHandler;
beforeEach(() => {
const config: CloneConfig = {
cloneContext: {
command: 'test',
module: 'clone',
email: 'test@example.com',
},
};
handler = new CloneHandler(config);
});
it('should set create new stack prompt', () => {
const prompt = [{ type: 'confirm', name: 'test' }];
handler.setCreateNewStackPrompt(prompt);
// Prompt is private, so we test indirectly
expect(handler).to.exist;
});
});
describe('setClient', () => {
let handler: CloneHandler;
beforeEach(() => {
const config: CloneConfig = {
cloneContext: {
command: 'test',
module: 'clone',
email: 'test@example.com',
},
};
handler = new CloneHandler(config);
});
it('should set client with valid client object', () => {
const mockClient = {
stack: () => {},
organization: () => {},
};
handler.setClient(mockClient as any);
expect(handler).to.exist;
});
it('should handle null client', () => {
handler.setClient(null as any);
expect(handler).to.exist;
});
it('should handle undefined client', () => {
handler.setClient(undefined as any);
expect(handler).to.exist;
});
});
});