Skip to content

Commit

Permalink
Unable to set email/username on a remote server
Browse files Browse the repository at this point in the history
  • Loading branch information
Jialin Zhang committed May 15, 2024
1 parent 2911c11 commit b27f819
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 b27f819

Please sign in to comment.