Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: git history, project switch integ tests #2066

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/styles/Extn-RecentProjects.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
white-space: nowrap;
padding: 2px 5px;
margin-left: -5px;
max-width: 60%;
.dropdown-arrow {
display: inline-block;
width: 7px;
Expand Down
123 changes: 96 additions & 27 deletions test/spec/Extn-Git-integ-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function (require, exports, module) {

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

let testPathGit;

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

it("should only git settings, init and clone commands be enabled in non-git repos", async function () {
await forCommandEnabled(Commands.CMD_GIT_INIT);
await forCommandEnabled(Commands.CMD_GIT_CLONE);
await forCommandEnabled(Commands.CMD_GIT_SETTINGS_COMMAND_ID);
await forCommandEnabled(Commands.CMD_GIT_TOGGLE_PANEL);
async function verifyRepoInNonGitState(isNonGit = true) {
await forCommandEnabled(Commands.CMD_GIT_INIT, isNonGit);
await forCommandEnabled(Commands.CMD_GIT_CLONE, isNonGit);
await forCommandEnabled(Commands.CMD_GIT_SETTINGS_COMMAND_ID, true);
await forCommandEnabled(Commands.CMD_GIT_TOGGLE_PANEL, true);
// others are disabled
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
await forCommandEnabled(Commands.CMD_GIT_FETCH, false);
await forCommandEnabled(Commands.CMD_GIT_PULL, false);
await forCommandEnabled(Commands.CMD_GIT_PUSH, false);
await forCommandEnabled(Commands.CMD_GIT_REFRESH, !isNonGit);
await forCommandEnabled(Commands.CMD_GIT_REFRESH, !isNonGit);
await forCommandEnabled(Commands.CMD_GIT_FETCH, !isNonGit);
await forCommandEnabled(Commands.CMD_GIT_PULL, !isNonGit);
await forCommandEnabled(Commands.CMD_GIT_PUSH, !isNonGit);
}

async function verifyGitPanelIcons(isGitProject) {
expect($gitPanel.find(".git-init").is(":visible")).toBe(!isGitProject);
expect($gitPanel.find(".git-clone").is(":visible")).toBe(!isGitProject);
// in non git repos the git buttons are not visible
expect($gitPanel.find(".git-commit").is(":visible")).toBe(isGitProject);
expect($gitPanel.find(".git-prev-gutter").is(":visible")).toBe(isGitProject);
expect($gitPanel.find(".git-file-history").is(":visible")).toBe(isGitProject);
expect($gitPanel.find(".git-right-icons").is(":visible")).toBe(isGitProject);
}

it("should only git settings, init and clone commands be enabled in non-git repos", async function () {
await verifyRepoInNonGitState();
});

it("Should Git icon be hidden in non-git repo", async function () {
Expand All @@ -99,14 +113,7 @@ define(function (require, exports, module) {
await __PR.execCommand(Commands.CMD_GIT_TOGGLE_PANEL);
expect($gitPanel.is(":visible")).toBeTrue();
expect($gitIcon.is(":visible")).toBeTrue();
// verify that only the init and clone button is visible
expect($gitPanel.find(".git-init").is(":visible")).toBeTrue();
expect($gitPanel.find(".git-clone").is(":visible")).toBeTrue();
// in non git repos the git buttons are not visible
expect($gitPanel.find(".git-commit").is(":visible")).toBeFalse();
expect($gitPanel.find(".git-prev-gutter").is(":visible")).toBeFalse();
expect($gitPanel.find(".git-file-history").is(":visible")).toBeFalse();
expect($gitPanel.find(".git-right-icons").is(":visible")).toBeFalse();
await verifyGitPanelIcons(false);
});

it("Should be able to initialize git repo", async function () {
Expand Down Expand Up @@ -318,9 +325,24 @@ define(function (require, exports, module) {
}, `History viewer to be visible: ${visible}`);
}

async function testHistoryViewerToggle(commitIndex) {
async function waitForBranchDropdownVisible(visible) {
await awaitsFor(() => {
return $("#git-branch-dropdown-toggle").is(":visible") === visible;
}, `Branch Dropdown to be visible: ${visible}`);
}

async function waitForGitToolbarIconVisible(visible) {
await awaitsFor(() => {
return $gitIcon.is(":visible") === visible;
}, `Git icon to be visible: ${visible}`);
}

it("should show the history viewer when clicking the first commit row and dismiss it on clicking again", async () => {
const $historyToggleButton = $gitPanel.find(".git-history-toggle");
$historyToggleButton.trigger("click");
await waitForHistoryVisible(true); // Ensure the history list is visible
const $historyList = $gitPanel.find("#git-history-list");
const $commitRow = $historyList.find(".history-commit").eq(commitIndex);
const $commitRow = $historyList.find(".history-commit").eq(1);

// Ensure the commit row exists
expect($commitRow.length).toBe(1);
Expand All @@ -338,13 +360,60 @@ define(function (require, exports, module) {
// Click the row again to dismiss the history viewer
$commitRow.trigger("click");
await waitForHistoryViewerVisible(false);
}
});

it("should be able to switch history", async () => {
const $historyList = $gitPanel.find("#git-history-list");

let $commitRow = $historyList.find(".history-commit").eq(1);
$commitRow.trigger("click");
await waitForHistoryViewerVisible(true);

// Verify that the history viewer shows the correct commit
await awaitsFor(() => {
return $("#editor-holder .git").find(".commit-title").text().trim().includes("first commit");
}, `History viewer to have first commit detail`);

$commitRow = $historyList.find(".history-commit").eq(0);
$commitRow.trigger("click");
await waitForHistoryViewerVisible(true);
await awaitsFor(() => {
return $("#editor-holder .git").find(".commit-title").text().trim().includes("second commit");
}, `History viewer to have second commit detail`);

// Click the row again to dismiss the history viewer
$commitRow.trigger("click");
await waitForHistoryViewerVisible(false);
});

it("should switching to a non-git project hide branch dropdown and move git panel to init state", async () => {
await SpecRunnerUtils.loadProjectInTestWindow(nonGitReadOnlyTestFolder);
await waitForBranchDropdownVisible(false);
await waitForGitToolbarIconVisible(true);
await verifyRepoInNonGitState();
await verifyGitPanelIcons(false);
});

it("should switching back to git project show branch dropdown and show git panel controls", async () => {
await SpecRunnerUtils.loadProjectInTestWindow(testPathGit);
await waitForBranchDropdownVisible(true);
await waitForGitToolbarIconVisible(true);
await verifyRepoInNonGitState(false);
await verifyGitPanelIcons(true);
});

it("should switching to a non-git project while git panel hidden hide git toolbar icon", async () => {
await SpecRunnerUtils.loadProjectInTestWindow(nonGitReadOnlyTestFolder);
await __PR.execCommand(Commands.CMD_GIT_TOGGLE_PANEL);
expect($gitPanel.is(":visible")).toBeFalse();

await SpecRunnerUtils.loadProjectInTestWindow(nonGitReadOnlyTestFolder);
await waitForGitToolbarIconVisible(false);

await SpecRunnerUtils.loadProjectInTestWindow(testPathGit);
await waitForGitToolbarIconVisible(true);
await __PR.execCommand(Commands.CMD_GIT_TOGGLE_PANEL);

it("should show the history viewer when clicking the first commit row and dismiss it on clicking again", async () => {
const $historyToggleButton = $gitPanel.find(".git-history-toggle");
$historyToggleButton.trigger("click");
await waitForHistoryVisible(true); // Ensure the history list is visible
await testHistoryViewerToggle(1); // Test for the first commit row
});

});
Expand Down
Loading