Skip to content

Commit 1af0b71

Browse files
committed
test: git switch project
1 parent f42f617 commit 1af0b71

File tree

1 file changed

+54
-19
lines changed

1 file changed

+54
-19
lines changed

test/spec/Extn-Git-integ-test.js

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function (require, exports, module) {
2929

3030
let $, __PR, testWindow, ExtensionLoader, Menus, Commands, CommandManager, EditorManager,
3131
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
32-
anotherTestFolder = SpecRunnerUtils.getTestPath("/spec/LowLevelFileIO-test-files");
32+
nonGitReadOnlyTestFolder = SpecRunnerUtils.getTestPath("/spec/LowLevelFileIO-test-files");
3333

3434
let testPathGit;
3535

@@ -78,17 +78,31 @@ define(function (require, exports, module) {
7878
$gitIcon = $("#git-toolbar-icon");
7979
});
8080

81-
it("should only git settings, init and clone commands be enabled in non-git repos", async function () {
82-
await forCommandEnabled(Commands.CMD_GIT_INIT);
83-
await forCommandEnabled(Commands.CMD_GIT_CLONE);
84-
await forCommandEnabled(Commands.CMD_GIT_SETTINGS_COMMAND_ID);
85-
await forCommandEnabled(Commands.CMD_GIT_TOGGLE_PANEL);
81+
async function verifyRepoInNonGitState(isNonGit = true) {
82+
await forCommandEnabled(Commands.CMD_GIT_INIT, isNonGit);
83+
await forCommandEnabled(Commands.CMD_GIT_CLONE, isNonGit);
84+
await forCommandEnabled(Commands.CMD_GIT_SETTINGS_COMMAND_ID, true);
85+
await forCommandEnabled(Commands.CMD_GIT_TOGGLE_PANEL, true);
8686
// others are disabled
87-
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
88-
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
89-
await forCommandEnabled(Commands.CMD_GIT_FETCH, false);
90-
await forCommandEnabled(Commands.CMD_GIT_PULL, false);
91-
await forCommandEnabled(Commands.CMD_GIT_PUSH, false);
87+
await forCommandEnabled(Commands.CMD_GIT_REFRESH, !isNonGit);
88+
await forCommandEnabled(Commands.CMD_GIT_REFRESH, !isNonGit);
89+
await forCommandEnabled(Commands.CMD_GIT_FETCH, !isNonGit);
90+
await forCommandEnabled(Commands.CMD_GIT_PULL, !isNonGit);
91+
await forCommandEnabled(Commands.CMD_GIT_PUSH, !isNonGit);
92+
}
93+
94+
async function verifyNonGitPanelIcons(notGitProject) {
95+
expect($gitPanel.find(".git-init").is(":visible")).toBe(notGitProject);
96+
expect($gitPanel.find(".git-clone").is(":visible")).toBe(notGitProject);
97+
// in non git repos the git buttons are not visible
98+
expect($gitPanel.find(".git-commit").is(":visible")).toBe(!notGitProject);
99+
expect($gitPanel.find(".git-prev-gutter").is(":visible")).toBe(!notGitProject);
100+
expect($gitPanel.find(".git-file-history").is(":visible")).toBe(!notGitProject);
101+
expect($gitPanel.find(".git-right-icons").is(":visible")).toBe(!notGitProject);
102+
}
103+
104+
it("should only git settings, init and clone commands be enabled in non-git repos", async function () {
105+
await verifyRepoInNonGitState();
92106
});
93107

94108
it("Should Git icon be hidden in non-git repo", async function () {
@@ -99,14 +113,7 @@ define(function (require, exports, module) {
99113
await __PR.execCommand(Commands.CMD_GIT_TOGGLE_PANEL);
100114
expect($gitPanel.is(":visible")).toBeTrue();
101115
expect($gitIcon.is(":visible")).toBeTrue();
102-
// verify that only the init and clone button is visible
103-
expect($gitPanel.find(".git-init").is(":visible")).toBeTrue();
104-
expect($gitPanel.find(".git-clone").is(":visible")).toBeTrue();
105-
// in non git repos the git buttons are not visible
106-
expect($gitPanel.find(".git-commit").is(":visible")).toBeFalse();
107-
expect($gitPanel.find(".git-prev-gutter").is(":visible")).toBeFalse();
108-
expect($gitPanel.find(".git-file-history").is(":visible")).toBeFalse();
109-
expect($gitPanel.find(".git-right-icons").is(":visible")).toBeFalse();
116+
await verifyNonGitPanelIcons(true);
110117
});
111118

112119
it("Should be able to initialize git repo", async function () {
@@ -318,6 +325,18 @@ define(function (require, exports, module) {
318325
}, `History viewer to be visible: ${visible}`);
319326
}
320327

328+
async function waitForBranchDropdownVisible(visible) {
329+
await awaitsFor(() => {
330+
return $("#git-branch-dropdown-toggle").is(":visible") === visible;
331+
}, `Branch Dropdown to be visible: ${visible}`);
332+
}
333+
334+
async function waitForGitToolbarIconVisible(visible) {
335+
await awaitsFor(() => {
336+
return $gitIcon.is(":visible") === visible;
337+
}, `Git icon to be visible: ${visible}`);
338+
}
339+
321340
it("should show the history viewer when clicking the first commit row and dismiss it on clicking again", async () => {
322341
const $historyToggleButton = $gitPanel.find(".git-history-toggle");
323342
$historyToggleButton.trigger("click");
@@ -367,6 +386,22 @@ define(function (require, exports, module) {
367386
await waitForHistoryViewerVisible(false);
368387
});
369388

389+
it("should switching to a non-git project hide branch dropdown and move git panel to init state", async () => {
390+
await SpecRunnerUtils.loadProjectInTestWindow(nonGitReadOnlyTestFolder);
391+
await waitForBranchDropdownVisible(false);
392+
await waitForGitToolbarIconVisible(true);
393+
await verifyRepoInNonGitState();
394+
await verifyNonGitPanelIcons(true);
395+
});
396+
397+
it("should switching back to git project show branch dropdown and show git panel controls", async () => {
398+
await SpecRunnerUtils.loadProjectInTestWindow(testPathGit);
399+
await waitForBranchDropdownVisible(true);
400+
await waitForGitToolbarIconVisible(true);
401+
await verifyRepoInNonGitState(false);
402+
await verifyNonGitPanelIcons(false);
403+
});
404+
370405
});
371406

372407
});

0 commit comments

Comments
 (0)