Skip to content

Commit fac02ab

Browse files
committed
Update unit test
1 parent b541d14 commit fac02ab

File tree

5 files changed

+147
-217
lines changed

5 files changed

+147
-217
lines changed

tests/GitExtension.spec.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ describe('IGitExtension', () => {
6767
return Promise.resolve(response);
6868
});
6969

70-
const app = {
71-
commands: {
72-
hasCommand: jest.fn().mockReturnValue(true)
73-
},
74-
docRegistry: {
75-
getFileTypesForPath: jest.fn().mockReturnValue([])
76-
}
77-
};
78-
model = new GitExtension(fakeRoot, app as any, docmanager as any);
70+
model = new GitExtension(fakeRoot, docmanager as any);
7971
});
8072

8173
describe('#pathRepository', () => {

tests/commands.spec.tsx

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
import { JupyterFrontEnd } from '@jupyterlab/application';
2+
import { showDialog } from '@jupyterlab/apputils';
3+
import { CommandRegistry } from '@lumino/commands';
14
import 'jest';
5+
import { addCommands, CommandIDs } from '../src/commandsAndMenu';
26
import * as git from '../src/git';
37
import { GitExtension } from '../src/model';
4-
import { IGitExtension } from '../src/tokens';
5-
6-
import { CommandIDs, addCommands } from '../src/commandsAndMenu';
7-
import { CommandRegistry } from '@lumino/commands';
8-
import { JupyterFrontEnd } from '@jupyterlab/application';
8+
import { Git } from '../src/tokens';
99

1010
jest.mock('../src/git');
11+
jest.mock('@jupyterlab/apputils');
1112

1213
describe('git-commands', () => {
1314
const mockGit = git as jest.Mocked<typeof git>;
1415
let commands: CommandRegistry;
15-
let model: IGitExtension;
16+
let model: GitExtension;
1617
let mockResponses: {
1718
[url: string]: {
1819
body?: (request: Object) => string;
@@ -74,7 +75,7 @@ describe('git-commands', () => {
7475
shell: null as any
7576
};
7677
model = new GitExtension(app as any);
77-
addCommands(app as JupyterFrontEnd, model, null, null);
78+
addCommands(app as JupyterFrontEnd, model, null, null, null);
7879
});
7980

8081
describe('git:add-remote', () => {
@@ -125,4 +126,62 @@ describe('git-commands', () => {
125126
});
126127
});
127128
});
129+
130+
describe('git:context-discard', () => {
131+
['staged', 'partially-staged', 'unstaged', 'untracked'].forEach(status => {
132+
[' ', 'M', 'A'].forEach(x => {
133+
it(`status:${status} - x:${x} may reset and/or checkout`, async () => {
134+
const mockDialog = showDialog as jest.MockedFunction<
135+
typeof showDialog
136+
>;
137+
mockDialog.mockResolvedValue({
138+
button: {
139+
accept: true,
140+
caption: '',
141+
className: '',
142+
displayType: 'default',
143+
iconClass: '',
144+
iconLabel: '',
145+
label: ''
146+
},
147+
value: undefined
148+
});
149+
const spyReset = jest.spyOn(model, 'reset');
150+
spyReset.mockResolvedValueOnce(undefined);
151+
const spyCheckout = jest.spyOn(model, 'checkout');
152+
spyCheckout.mockResolvedValueOnce(undefined);
153+
154+
const path = 'file/path.ext';
155+
model.pathRepository = '/path/to/repo';
156+
await model.ready;
157+
158+
await commands.execute(CommandIDs.gitFileDiscard, {
159+
x,
160+
y: ' ',
161+
from: 'from',
162+
to: path,
163+
status: status as Git.Status,
164+
is_binary: false
165+
});
166+
167+
if (status === 'staged' || status === 'partially-staged') {
168+
expect(spyReset).toHaveBeenCalledWith(path);
169+
} else if (status === 'unstaged') {
170+
expect(spyReset).not.toHaveBeenCalled();
171+
expect(spyCheckout).toHaveBeenCalledWith({ filename: path });
172+
} else if (status === 'partially-staged') {
173+
expect(spyReset).toHaveBeenCalledWith(path);
174+
if (x !== 'A') {
175+
expect(spyCheckout).toHaveBeenCalledWith({ filename: path });
176+
} else {
177+
expect(spyCheckout).not.toHaveBeenCalled();
178+
}
179+
}
180+
181+
spyReset.mockRestore();
182+
spyCheckout.mockRestore();
183+
});
184+
});
185+
});
186+
});
128187
});

tests/test-components/FileList.spec.tsx

Lines changed: 0 additions & 146 deletions
This file was deleted.

tests/test-components/GitPanel.spec.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('GitPanel', () => {
7272
describe('#commitStagedFiles()', () => {
7373
const props: IGitPanelProps = {
7474
model: null,
75-
renderMime: null,
75+
commands: null,
7676
settings: null,
7777
filebrowser: null
7878
};
@@ -83,12 +83,7 @@ describe('GitPanel', () => {
8383
const mock = git as jest.Mocked<typeof git>;
8484
mock.httpGitRequest.mockImplementation(MockRequest);
8585

86-
const app = {
87-
commands: {
88-
hasCommand: jest.fn().mockReturnValue(true)
89-
}
90-
};
91-
props.model = new GitModel(app as any);
86+
props.model = new GitModel('/server/root');
9287
props.model.pathRepository = '/path/to/repo';
9388

9489
// @ts-ignore

0 commit comments

Comments
 (0)