Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/SantaClaas/gigit. git client
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243import { expect, test, type Page } from "@playwright/test";
import { linearHistory, reference } from "../fixtures/rows";import { mockTauri, openRepository, sidebarSection } from "./tauri";
const REFERENCES = [ reference("main"), reference("feature/graph"), reference("origin/main", "remoteBranch"), reference("origin/feature/graph", "remoteBranch"), reference("v1.0.0", "tag"), reference("v2.0.0", "tag"), // Machinery, which the sidebar should leave out. reference("stash", "other"),];
test.describe("sidebar", () => { test("says nothing definite before a repository is open", async ({ page }) => { await mockTauri(page, { rows: [], references: REFERENCES, chooseFolder: "/demo" }); await page.goto("/");
const sidebar = page.getByRole("navigation", { name: "Repository" });
await expect(sidebar).toContainText("Branches"); // "None" would be a claim about a repository nothing has read yet. await expect(sidebar).not.toContainText("None"); });
test("fills in once a repository is open", async ({ page }) => { await mockTauri(page, { rows: linearHistory(10), references: REFERENCES, chooseFolder: "/demo", }); await page.goto("/");
await openRepository(page);
// The mocked repository reports HEAD on `main`, which carries its marker. await expect(sidebarSection(page, "Branches")).toHaveText([ "feature/graph", "current branch: main", ]); await expect(sidebarSection(page, "Remotes")).toHaveText([ "origin/feature/graph", "origin/main", ]); await expect(sidebarSection(page, "Tags")).toHaveText(["v1.0.0", "v2.0.0"]); });
test("leaves out refs that are machinery rather than navigation", async ({ page }) => { await mockTauri(page, { rows: linearHistory(10), references: REFERENCES, chooseFolder: "/demo", }); await page.goto("/");
await openRepository(page); await expect(sidebarSection(page, "Branches").first()).toBeVisible();
await expect(page.getByRole("navigation", { name: "Repository" })).not.toContainText("stash"); });
test("counts each section", async ({ page }) => { await mockTauri(page, { rows: linearHistory(10), references: REFERENCES, chooseFolder: "/demo", }); await page.goto("/");
await openRepository(page);
await expect(page.getByRole("heading", { name: "Branches 2" })).toBeVisible(); await expect(page.getByRole("heading", { name: "Remotes 2" })).toBeVisible(); });
test("marks the checked out branch in words", async ({ page }) => { // Colour alone says nothing to a screen reader. await mockTauri(page, { rows: linearHistory(10), references: REFERENCES, chooseFolder: "/demo", }); await page.goto("/");
await openRepository(page);
// The mocked repository reports HEAD on `main`. await expect(sidebarSection(page, "Branches").filter({ hasText: "current branch" })).toHaveText( ["current branch: main"], ); });
test("says a section is empty when the repository really has nothing in it", async ({ page }) => { await mockTauri(page, { rows: linearHistory(10), references: [reference("main")], chooseFolder: "/demo", }); await page.goto("/");
await openRepository(page); await expect(sidebarSection(page, "Branches")).toHaveText(["current branch: main"]);
await expect(page.getByRole("navigation", { name: "Repository" })).toContainText("None"); });
test("copes with a repository that has hundreds of refs", async ({ page }) => { // A busy repository should fill the sidebar rather than break it. const many = Array.from({ length: 400 }, (_, index) => reference(`origin/branch-${index}`, "remoteBranch"), );
await mockTauri(page, { rows: linearHistory(10), references: [reference("main"), ...many], chooseFolder: "/demo", }); await page.goto("/");
await openRepository(page);
await expect(page.getByRole("heading", { name: "Remotes 400" })).toBeVisible(); await expect(sidebarSection(page, "Remotes")).toHaveCount(400); });});
/** Open a repository with a busy set of refs and hand back the filter field. */async function withRefs(page: Page, references = REFERENCES) { await mockTauri(page, { rows: linearHistory(10), references, chooseFolder: "/demo" }); await page.goto("/"); await openRepository(page); await expect(sidebarSection(page, "Branches").first()).toBeVisible();
return page.getByRole("searchbox", { name: "Filter references" });}
test.describe("filtering", () => { test("offers a filter only once there is a repository to filter", async ({ page }) => { await mockTauri(page, { rows: [], references: REFERENCES, chooseFolder: "/demo" }); await page.goto("/");
await expect(page.getByRole("searchbox", { name: "Filter references" })).toBeHidden();
await openRepository(page);
await expect(page.getByRole("searchbox", { name: "Filter references" })).toBeVisible(); });
test("narrows branches, remotes and tags together", async ({ page }) => { const filter = await withRefs(page);
await filter.fill("main");
await expect(sidebarSection(page, "Branches")).toHaveText(["current branch: main"]); await expect(sidebarSection(page, "Remotes")).toHaveText(["origin/main"]); // Nothing in Tags matched, so the section goes rather than saying "None". await expect(page.getByRole("heading", { name: /^Tags/u })).toBeHidden(); });
test("says how much survived, in each section and altogether", async ({ page }) => { const filter = await withRefs(page);
await filter.fill("feature");
await expect(page.getByRole("heading", { name: "Branches 1 of 2" })).toBeVisible(); await expect(page.getByRole("navigation", { name: "Repository" })).toContainText( "2 of 6 match", ); });
test("marks the part of each name that matched", async ({ page }) => { const filter = await withRefs(page);
await filter.fill("graph");
await expect(page.getByRole("navigation", { name: "Repository" }).locator("mark")).toHaveText([ "graph", "graph", ]); });
test("says so once when nothing matches", async ({ page }) => { const filter = await withRefs(page);
await filter.fill("no-such-branch");
await expect(page.getByText("Nothing matches")).toBeVisible(); await expect(page.getByRole("heading", { name: /^Branches/u })).toBeHidden(); });
test("puts everything back when cleared", async ({ page }) => { const filter = await withRefs(page); await filter.fill("main"); await expect(page.getByRole("heading", { name: /^Tags/u })).toBeHidden();
await filter.fill("");
await expect(sidebarSection(page, "Tags")).toHaveText(["v1.0.0", "v2.0.0"]); await expect(page.getByRole("navigation", { name: "Repository" }).locator("mark")).toHaveCount( 0, ); });
test("clears on Escape, in both engines", async ({ page }) => { // Whether a search input clears itself on Escape is left to the browser, // and WebKit and Chromium disagree — so it is handled explicitly. const filter = await withRefs(page); await filter.fill("main");
await filter.press("Escape");
await expect(filter).toHaveValue(""); await expect(sidebarSection(page, "Tags")).toHaveText(["v1.0.0", "v2.0.0"]); });
test("makes a repository with hundreds of refs usable", async ({ page }) => { // The reason this exists: 400 entries is a scroll, 3 is a list. const many = Array.from({ length: 400 }, (_, index) => reference(`origin/branch-${index}`, "remoteBranch"), ); const filter = await withRefs(page, [reference("main"), ...many]); await expect(sidebarSection(page, "Remotes")).toHaveCount(400);
await filter.fill("branch-17");
// branch-17, branch-170 through branch-179. await expect(sidebarSection(page, "Remotes")).toHaveCount(11); });
test("keeps the filter reachable by keyboard alone", async ({ page }) => { const filter = await withRefs(page);
await filter.focus(); await page.keyboard.type("tags");
await expect(filter).toBeFocused(); await expect(filter).toHaveValue("tags"); });});