|
| 1 | +import { JupyterFrontEnd } from '@jupyterlab/application'; |
| 2 | +import { showDialog } from '@jupyterlab/apputils'; |
| 3 | +import { CommandRegistry } from '@lumino/commands'; |
1 | 4 | import 'jest';
|
| 5 | +import { addCommands, CommandIDs } from '../src/commandsAndMenu'; |
2 | 6 | import * as git from '../src/git';
|
3 | 7 | 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'; |
9 | 9 |
|
10 | 10 | jest.mock('../src/git');
|
| 11 | +jest.mock('@jupyterlab/apputils'); |
11 | 12 |
|
12 | 13 | describe('git-commands', () => {
|
13 | 14 | const mockGit = git as jest.Mocked<typeof git>;
|
14 | 15 | let commands: CommandRegistry;
|
15 |
| - let model: IGitExtension; |
| 16 | + let model: GitExtension; |
16 | 17 | let mockResponses: {
|
17 | 18 | [url: string]: {
|
18 | 19 | body?: (request: Object) => string;
|
@@ -74,7 +75,7 @@ describe('git-commands', () => {
|
74 | 75 | shell: null as any
|
75 | 76 | };
|
76 | 77 | model = new GitExtension(app as any);
|
77 |
| - addCommands(app as JupyterFrontEnd, model, null, null); |
| 78 | + addCommands(app as JupyterFrontEnd, model, null, null, null); |
78 | 79 | });
|
79 | 80 |
|
80 | 81 | describe('git:add-remote', () => {
|
@@ -125,4 +126,62 @@ describe('git-commands', () => {
|
125 | 126 | });
|
126 | 127 | });
|
127 | 128 | });
|
| 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 | + }); |
128 | 187 | });
|
0 commit comments