Skip to content

Commit 479d519

Browse files
Jialin ZhangZsailer
authored andcommitted
Fix GitPanel unit tests
1 parent b878c0b commit 479d519

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/__tests__/test-components/GitPanel.spec.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ const mockedResponses: {
4141
* @private
4242
* @returns mock settings
4343
*/
44-
function MockSettings(commitAndPush = true, promptUserIdentity = false) {
44+
function MockSettings(
45+
commitAndPush = true,
46+
promptUserIdentity = false,
47+
simpleStaging = false
48+
) {
4549
return {
4650
changed: {
4751
connect: () => true,
4852
disconnect: () => true
4953
},
5054
composite: {
5155
commitAndPush,
52-
promptUserIdentity
56+
promptUserIdentity,
57+
simpleStaging
5358
}
5459
};
5560
}
@@ -151,8 +156,6 @@ describe('GitPanel', () => {
151156
beforeEach(() => {
152157
configSpy = props.model.config = jest.fn();
153158
commitSpy = props.model.commit = jest.fn();
154-
// @ts-expect-error turn off set status
155-
props.model._setStatus = jest.fn();
156159

157160
// @ts-expect-error set a private prop
158161
props.model._status = {
@@ -173,10 +176,15 @@ describe('GitPanel', () => {
173176
state: 0
174177
};
175178

179+
// @ts-expect-error turn off set status
180+
props.model._setStatus = jest.fn(() => {
181+
props.model._statusChanged.emit(props.model._status);
182+
});
183+
176184
render(<GitPanel {...props} />);
177185
});
178186

179-
it.skip('should commit when commit message is provided', async () => {
187+
it('should commit when commit message is provided', async () => {
180188
configSpy.mockResolvedValue({ options: commitUser });
181189

182190
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
@@ -212,16 +220,15 @@ describe('GitPanel', () => {
212220
expect(commitSpy).not.toHaveBeenCalled();
213221
});
214222

215-
it.skip('should prompt for user identity if explicitly configured', async () => {
223+
it('should prompt for user identity if explicitly configured', async () => {
216224
configSpy.mockResolvedValue({ options: commitUser });
217225

218-
props.settings = MockSettings(false, true) as any;
219-
render(<GitPanel {...props} />);
220-
221226
mockUtils.showDialog.mockResolvedValue(dialogValue);
222227

223228
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
224-
await userEvent.click(screen.getByRole('button', { name: 'Commit' }));
229+
await userEvent.click(
230+
screen.getAllByRole('button', { name: 'Commit' })[0]
231+
);
225232

226233
expect(configSpy).toHaveBeenCalledTimes(1);
227234
expect(configSpy.mock.calls[0]).toHaveLength(0);
@@ -231,7 +238,7 @@ describe('GitPanel', () => {
231238
expect(commitSpy).toHaveBeenCalledWith(commitSummary, false, author);
232239
});
233240

234-
it.skip('should prompt for user identity if user.name is not set', async () => {
241+
it('should prompt for user identity if user.name is not set', async () => {
235242
configSpy.mockImplementation(mockConfigImplementation('user.email'));
236243
mockUtils.showDialog.mockResolvedValue(dialogValue);
237244

@@ -247,7 +254,7 @@ describe('GitPanel', () => {
247254
expect(commitSpy).toHaveBeenCalledWith(commitSummary, false, null);
248255
});
249256

250-
it.skip('should prompt for user identity if user.email is not set', async () => {
257+
it('should prompt for user identity if user.email is not set', async () => {
251258
configSpy.mockImplementation(mockConfigImplementation('user.name'));
252259
mockUtils.showDialog.mockResolvedValue(dialogValue);
253260

@@ -263,7 +270,7 @@ describe('GitPanel', () => {
263270
expect(commitSpy).toHaveBeenCalledWith(commitSummary, false, null);
264271
});
265272

266-
it.skip('should not commit if no user identity is set and the user rejects the dialog', async () => {
273+
it('should not commit if no user identity is set and the user rejects the dialog', async () => {
267274
configSpy.mockResolvedValue({ options: {} });
268275
mockUtils.showDialog.mockResolvedValue({
269276
button: {

0 commit comments

Comments
 (0)