Skip to content

Commit fbdc390

Browse files
committed
♻️ Reuse gitmob.reload command
When data changes happen the UI needs to be updated and this can be achieved using the reload command vs duplicate calls to the reloadData functions on coAuthorProvider.
1 parent 286a3e1 commit fbdc390

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

src/reload-on-save.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
const vscode = require("vscode");
22
const { CONSTANTS } = require("./constants");
33

4-
function reloadOnSave({ coAuthorProvider }) {
4+
function reloadOnSave() {
55
const { onDidSaveTextDocument } = vscode.workspace;
66

77
onDidSaveTextDocument(async function (textDocument) {
88
if (textDocument.fileName.includes(CONSTANTS.GIT_COAUTHORS_FILE)) {
9-
await coAuthorProvider.coAuthorGroups.reloadData();
10-
coAuthorProvider.reloadData();
9+
await vscode.commands.executeCommand("gitmob.reload");
1110
}
1211
});
1312
}

src/reload-on-save.spec.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ const { reloadOnSave } = require("./reload-on-save");
22
const { CONSTANTS } = require("./constants");
33
const vscode = require("../__mocks__/vscode");
44

5-
const coAuthorProviderStub = {
6-
reloadData: jest.fn(),
7-
coAuthorGroups: {
8-
reloadData: jest.fn(),
9-
},
10-
};
115
const coAuthorTextDocStub = {
126
fileName: `file/Path/to/${CONSTANTS.GIT_COAUTHORS_FILE}`,
137
};
@@ -23,29 +17,27 @@ beforeEach(() => {
2317
});
2418

2519
afterEach(() => {
26-
coAuthorProviderStub.reloadData.mockReset();
27-
coAuthorProviderStub.coAuthorGroups.reloadData.mockReset();
2820
saveTrigger = null;
2921
});
3022

3123
test("Reload co-author list when git-coauthors file saved", async () => {
32-
reloadOnSave({ coAuthorProvider: coAuthorProviderStub });
24+
reloadOnSave();
3325
expect(vscode.workspace.onDidSaveTextDocument).toHaveBeenCalledWith(
3426
expect.any(Function)
3527
);
3628
await saveTrigger(coAuthorTextDocStub);
37-
expect(coAuthorProviderStub.reloadData).toHaveBeenCalledTimes(1);
38-
expect(coAuthorProviderStub.coAuthorGroups.reloadData).toHaveBeenCalledTimes(
39-
1
40-
);
29+
expect(vscode.commands.executeCommand).toHaveBeenCalledTimes(1);
30+
expect(vscode.commands.executeCommand).toHaveBeenCalledWith("gitmob.reload");
4131
});
4232

4333
test("Do NOT reload co-author list when other files are saved", async () => {
44-
reloadOnSave({ coAuthorProvider: coAuthorProviderStub });
34+
reloadOnSave();
4535
expect(vscode.workspace.onDidSaveTextDocument).toHaveBeenCalledWith(
4636
expect.any(Function)
4737
);
4838
await saveTrigger(otherTextDocStub);
49-
expect(coAuthorProviderStub.reloadData).not.toHaveBeenCalled();
50-
expect(coAuthorProviderStub.coAuthorGroups.reloadData).not.toHaveBeenCalled();
39+
expect(vscode.commands.executeCommand).not.toHaveBeenCalled();
40+
expect(vscode.commands.executeCommand).not.toHaveBeenCalledWith(
41+
"gitmob.reload"
42+
);
5143
});

src/setup-git-mob.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ async function bootGitMob(context, gitExt) {
6969

7070
disposables.forEach((dispose) => context.subscriptions.push(dispose));
7171

72-
reloadOnSave({ coAuthorProvider });
72+
reloadOnSave();
7373
soloAfterCommit(coAuthorProvider);
7474

7575
gitExt.onDidChangeUiState(async function () {
7676
if (gitExt.repositories.length === 1) return;
7777
if (this.ui.selected) {
7878
gitExt.selectedRepositoryPath = this.rootUri.path;
7979
updateConfig("processCwd", gitExt.rootPath);
80-
await coAuthorProvider.coAuthorGroups.reloadData();
81-
coAuthorProvider.reloadData();
80+
await vscode.commands.executeCommand("gitmob.reload");
8281
}
8382
});
8483

test/extension.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ describe("GitMob core tests", function () {
143143
);
144144

145145
await vscode.commands.executeCommand("gitmob.reload");
146-
147146
await vscode.commands.executeCommand("gitmob.addCoAuthor", coAuthor);
148147
await wait(200);
149148

0 commit comments

Comments
 (0)