From b27f81978346a2cb256e5f32d04745566f29cab7 Mon Sep 17 00:00:00 2001 From: Jialin Zhang Date: Wed, 15 May 2024 16:20:08 -0700 Subject: [PATCH] Unable to set email/username on a remote server --- .../test-components/GitPanel.spec.tsx | 66 +++++++++++++++++++ src/components/GitPanel.tsx | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/__tests__/test-components/GitPanel.spec.tsx b/src/__tests__/test-components/GitPanel.spec.tsx index 4d264a5fa..43a009a11 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 2acb17ab1..184a35a2c 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; }