Skip to content

Commit

Permalink
Merge pull request #1324 from jzhang20133/email_username_popup
Browse files Browse the repository at this point in the history
Unable to set email/username on a remote server
  • Loading branch information
Zsailer authored May 16, 2024
2 parents 2911c11 + b27f819 commit d0480eb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions src/__tests__/test-components/GitPanel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<GitPanel {...props} />);

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(<GitPanel {...props} />);
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(<GitPanel {...props} />);
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({
Expand Down
2 changes: 1 addition & 1 deletion src/components/GitPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
* @param path - repository path
*/
private async _hasIdentity(path: string | null): Promise<string | null> {
if (!path) {
if (path === null) {
return null;
}

Expand Down

0 comments on commit d0480eb

Please sign in to comment.