Skip to content

Commit fd98d68

Browse files
committed
feat: add tests for git panel branch toggle button
1 parent 0e3ccd0 commit fd98d68

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,76 @@ define(function (require, exports, module) {
509509
await waitForBranchNameDropdown(defaultBranch);
510510
});
511511

512+
function panelBranchName() {
513+
return $gitPanel.find(".git-panel-branch .git-branch-name").text().trim();
514+
}
515+
516+
async function waitForBranchDropdownOpen(open) {
517+
await awaitsFor(()=>{
518+
return $("#git-branch-dropdown").length === (open ? 1 : 0);
519+
}, `branch dropdown to be ${open ? "open" : "closed"}`);
520+
}
521+
522+
async function switchToBranch(branchName) {
523+
$("#git-branch-dropdown-toggle").click();
524+
await waitForBranchDropdownOpen(true);
525+
526+
const $branchLink = $(".switch-branch").filter((index, el) => $(el).text().trim() === branchName);
527+
expect($branchLink.length).toBe(1);
528+
$branchLink.click();
529+
await waitForBranchNameDropdown(branchName);
530+
}
531+
532+
it("should git panel branch button show the current branch and follow switches", async () => {
533+
await showGitPanel();
534+
await waitForBranchNameDropdown(defaultBranch);
535+
await awaitsFor(()=>{
536+
return panelBranchName() === defaultBranch;
537+
}, "panel branch button to show the current branch");
538+
539+
// the panel button mirrors the sidebar indicator and is clickable in a repo
540+
expect($("#git-branch").text().trim()).toContain(panelBranchName());
541+
expect($gitPanel.find(".git-panel-branch").attr("title")).toContain(defaultBranch);
542+
expect($gitPanel.find(".git-panel-branch").hasClass("clickable")).toBeTrue();
543+
544+
await switchToBranch(createdBranch);
545+
await awaitsFor(()=>{
546+
return panelBranchName() === createdBranch;
547+
}, "panel branch button to follow the branch switch");
548+
549+
// switch back so the rest of the specs run on the default branch
550+
await switchToBranch(defaultBranch);
551+
await awaitsFor(()=>{
552+
return panelBranchName() === defaultBranch;
553+
}, "panel branch button to follow the switch back");
554+
});
555+
556+
it("should git panel branch button open the dropdown and move it between anchors", async () => {
557+
await showGitPanel();
558+
await waitForBranchDropdownOpen(false);
559+
560+
// the dropdown opens above the panel button. _positionDropdownAbove is the
561+
// only path that neutralizes the sidebar margin, so the inline margin-left
562+
// tells us which anchor the dropdown is currently attached to
563+
$gitPanel.find(".git-panel-branch").click();
564+
await waitForBranchDropdownOpen(true);
565+
expect($("#git-branch-dropdown")[0].style.marginLeft).toBe("0px");
566+
567+
// clicking the same anchor closes it
568+
$gitPanel.find(".git-panel-branch").click();
569+
await waitForBranchDropdownOpen(false);
570+
571+
// clicking the other anchor moves the dropdown there instead of closing it
572+
$gitPanel.find(".git-panel-branch").click();
573+
await waitForBranchDropdownOpen(true);
574+
$("#git-branch-dropdown-toggle").click();
575+
await waitForBranchDropdownOpen(true);
576+
expect($("#git-branch-dropdown")[0].style.marginLeft).toBe("");
577+
578+
$("#git-branch-dropdown-toggle").click();
579+
await waitForBranchDropdownOpen(false);
580+
});
581+
512582
function workingSetHas(fileName) {
513583
const workingSet = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES);
514584
return workingSet.some((file) => file.fullPath.endsWith("/" + fileName));

0 commit comments

Comments
 (0)