diff --git a/src/__tests__/test-components/GitPanel.spec.tsx b/src/__tests__/test-components/GitPanel.spec.tsx index 4d264a5f..43a009a1 100644 --- a/src/__tests__/test-components/GitPanel.spec.tsx +++ b/src/__tests__/test-components/GitPanel.spec.tsx @@ -274,6 +274,72 @@ describe('GitPanel', () => { expect(commitSpy).toHaveBeenCalledWith(commitSummary, false, null); }); + it('should prompt for user identity if user.name is not set when pathRepository is empty string', async () => { + props.model.pathRepository = ''; + renderResult.rerender(); + + configSpy.mockImplementation(mockConfigImplementation('user.email')); + mockUtils.showDialog.mockResolvedValue(dialogValue); + + await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary); + await userEvent.click(screen.getByRole('button', { name: 'Commit' })); + + await waitFor(() => { + expect(configSpy).toHaveBeenCalledTimes(2); + }); + expect(configSpy.mock.calls[0]).toHaveLength(0); + expect(configSpy.mock.calls[1]).toEqual([commitUser]); + expect(commitSpy).toHaveBeenCalledTimes(1); + expect(commitSpy).toHaveBeenCalledWith(commitSummary, false, null); + }); + + it('should prompt for user identity if user.email is not set when pathRepository is empty string', async () => { + props.model.pathRepository = ''; + renderResult.rerender(); + configSpy.mockImplementation(mockConfigImplementation('user.name')); + mockUtils.showDialog.mockResolvedValue(dialogValue); + + await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary); + await userEvent.click(screen.getByRole('button', { name: 'Commit' })); + + await waitFor(() => { + expect(configSpy).toHaveBeenCalledTimes(2); + }); + expect(configSpy.mock.calls[0]).toHaveLength(0); + expect(configSpy.mock.calls[1]).toEqual([commitUser]); + expect(commitSpy).toHaveBeenCalledTimes(1); + expect(commitSpy).toHaveBeenCalledWith(commitSummary, false, null); + }); + + it('should not commit if no user identity is set and the user rejects the dialog when pathRepository is empty string', async () => { + props.model.pathRepository = ''; + renderResult.rerender(); + configSpy.mockResolvedValue({ options: {} }); + mockUtils.showDialog.mockResolvedValue({ + button: { + ...dialogValue.button, + accept: false + }, + isChecked: null, + value: null + }); + + await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary); + await userEvent.type( + screen.getAllByRole('textbox')[1], + commitDescription + ); + await userEvent.click(screen.getByRole('button', { name: 'Commit' })); + + await waitFor(() => expect(configSpy).toHaveBeenCalledTimes(1)); + expect(configSpy).toHaveBeenCalledWith(); + expect(commitSpy).not.toHaveBeenCalled(); + + // Should not erase commit message + expect(screen.getAllByRole('textbox')[0]).toHaveValue(commitSummary); + expect(screen.getAllByRole('textbox')[1]).toHaveValue(commitDescription); + }); + it('should not commit if no user identity is set and the user rejects the dialog', async () => { configSpy.mockResolvedValue({ options: {} }); mockUtils.showDialog.mockResolvedValue({ diff --git a/src/components/GitPanel.tsx b/src/components/GitPanel.tsx index 2acb17ab..184a35a2 100644 --- a/src/components/GitPanel.tsx +++ b/src/components/GitPanel.tsx @@ -842,7 +842,7 @@ export class GitPanel extends React.Component { * @param path - repository path */ private async _hasIdentity(path: string | null): Promise { - if (!path) { + if (path === null) { return null; }