Skip to content

Commit

Permalink
Fix linting error
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsailer committed May 15, 2024
1 parent b8dfe80 commit 309235b
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions src/__tests__/test-components/GitPanel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const mockedResponses: {
* @private
* @returns mock settings
*/
function MockSettings(commitAndPush = true, promptUserIdentity = false, simpleStaging = false) {
function MockSettings(
commitAndPush = true,
promptUserIdentity = false,
simpleStaging = false
) {
return {
changed: {
connect: () => true,
Expand Down Expand Up @@ -173,7 +177,9 @@ describe('GitPanel', () => {
};

// @ts-expect-error turn off set status
props.model._setStatus = jest.fn(() => {props.model._statusChanged.emit(props.model._status)});
props.model._setStatus = jest.fn(() => {
props.model._statusChanged.emit(props.model._status);
});

render(<GitPanel {...props} />);
});
Expand Down Expand Up @@ -219,8 +225,10 @@ describe('GitPanel', () => {

mockUtils.showDialog.mockResolvedValue(dialogValue);

await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
await userEvent.click(screen.getAllByRole('button', { name: 'Commit' })[0]);
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
await userEvent.click(
screen.getAllByRole('button', { name: 'Commit' })[0]
);

expect(configSpy).toHaveBeenCalledTimes(1);
expect(configSpy.mock.calls[0]).toHaveLength(0);
Expand Down Expand Up @@ -292,7 +300,7 @@ describe('GitPanel', () => {

describe('GitPanel when pathRepository is empty string', () => {
const trans = nullTranslator.load('jupyterlab_git');

const props: IGitPanelProps = {
model: null as any,
commands: new CommandRegistry(),
Expand All @@ -302,34 +310,34 @@ describe('GitPanel', () => {
} as any,
trans: trans
};

beforeEach(async () => {
jest.restoreAllMocks();

const mock = git as jest.Mocked<typeof git>;
mock.requestAPI.mockImplementation(
mockedRequestAPI(mockedResponses) as any
);

props.model = new GitModel();
props.model.pathRepository = "";
props.model.pathRepository = '';

props.settings = MockSettings() as any;

await props.model.ready;
});

describe('#commitFiles()', () => {
let commitSpy: jest.SpyInstance<Promise<void>>;
let configSpy: jest.SpyInstance<Promise<void | JSONObject>>;

const commitSummary = 'Fix really stupid bug';
const commitDescription = 'This will probably break everything :)';
const commitUser = {
'user.name': 'John Snow',
'user.email': 'john.snow@winteris.com'
};

const mockUtils = apputils as jest.Mocked<typeof apputils>;
const dialogValue: apputils.Dialog.IResult<any> = {
button: {
Expand All @@ -348,7 +356,7 @@ describe('GitPanel', () => {
email: commitUser['user.email']
}
};

/**
* Mock identity look up (GitModel.config)
*/
Expand All @@ -366,11 +374,11 @@ describe('GitPanel', () => {
);
};
};

beforeEach(() => {
configSpy = props.model.config = jest.fn();
commitSpy = props.model.commit = jest.fn();

// @ts-expect-error set a private prop
props.model._status = {
branch: 'master',
Expand All @@ -391,18 +399,20 @@ describe('GitPanel', () => {
};

// @ts-expect-error turn off set status
props.model._setStatus = jest.fn(() => {props.model._statusChanged.emit(props.model._status)});

props.model._setStatus = jest.fn(() => {
props.model._statusChanged.emit(props.model._status);
});

render(<GitPanel {...props} />);
});

it('should prompt for user identity if user.name is not set', async () => {
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);
});
Expand All @@ -411,14 +421,14 @@ describe('GitPanel', () => {
expect(commitSpy).toHaveBeenCalledTimes(1);
expect(commitSpy).toHaveBeenCalledWith(commitSummary, false, null);
});

it('should prompt for user identity if user.email is not set', async () => {
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);
});
Expand All @@ -427,7 +437,7 @@ describe('GitPanel', () => {
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', async () => {
configSpy.mockResolvedValue({ options: {} });
mockUtils.showDialog.mockResolvedValue({
Expand All @@ -438,21 +448,23 @@ describe('GitPanel', () => {
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);
expect(screen.getAllByRole('textbox')[1]).toHaveValue(
commitDescription
);
});
});
});
Expand Down

0 comments on commit 309235b

Please sign in to comment.