/ tests / e2e / repo / commit.spec.ts
commit.spec.ts
  1  import {
  2    aliceRemote,
  3    bobHead,
  4    expect,
  5    shortBobHead,
  6    sourceBrowsingUrl,
  7    test,
  8  } from "@tests/support/fixtures.js";
  9  import { changeBranch } from "@tests/support/repo";
 10  
 11  const commitUrl = `${sourceBrowsingUrl}/commits/${bobHead}`;
 12  
 13  test("navigation from commit list", async ({ page }) => {
 14    await page.goto(sourceBrowsingUrl);
 15    await changeBranch("bob", `main ${shortBobHead}`, page);
 16  
 17    await page.getByText("Update readme").first().click();
 18    await expect(page).toHaveURL(commitUrl);
 19  });
 20  
 21  test("relative timestamps", async ({ page }) => {
 22    await page.clock.setFixedTime(new Date("December 21 2022 12:00:00"));
 23    await page.goto(commitUrl);
 24    await expect(
 25      page.getByText(`Bob Belcher committed ${shortBobHead}`),
 26    ).toBeVisible();
 27  });
 28  
 29  test("modified file", async ({ page }) => {
 30    await page.goto(commitUrl);
 31  
 32    // Commit header.
 33    {
 34      await expect(page.getByText("Update readme")).toBeVisible();
 35      await expect(page.getByLabel("commit-id")).toHaveText(shortBobHead);
 36    }
 37  
 38    // Diff header.
 39    await expect(
 40      page.getByText("1 file modified with 1 insertion and 4 deletions"),
 41    ).toBeVisible();
 42  
 43    // Diff.
 44    await expect(page.getByText("# Git test repository")).toBeVisible();
 45    await expect(page.getByText("Updated readme")).toBeVisible();
 46  });
 47  
 48  test("created file", async ({ page }) => {
 49    await page.goto(
 50      `${sourceBrowsingUrl}/remotes/${aliceRemote.substring(
 51        8,
 52      )}/commits/d87e27e38e244fb3346cb9e4df064c080d97647a`,
 53    );
 54    await expect(
 55      page.getByText("1 file added with 1 insertion and 0 deletions"),
 56    ).toBeVisible();
 57    await expect(page.getByText(".hidden added")).toBeVisible();
 58  });
 59  
 60  test("deleted file", async ({ page }) => {
 61    await page.goto(
 62      `${sourceBrowsingUrl}/remotes/${aliceRemote.substring(
 63        8,
 64      )}/commits/0e2db54dfd47d87202809917e2342655d9e76296`,
 65    );
 66    await expect(
 67      page.getByText("1 file deleted with 0 insertions and 1 deletion"),
 68    ).toBeVisible();
 69    await expect(page.getByText(".hidden deleted")).toBeVisible();
 70  });
 71  
 72  test("moved file", async ({ page }) => {
 73    await page.goto(
 74      `${sourceBrowsingUrl}/remotes/${aliceRemote}/commits/f48a1056a5bd02277978f6e8a00517a967546340`,
 75    );
 76    await expect(
 77      page.getByText("moves/111.txt → moves/222.txt moved"),
 78    ).toBeVisible();
 79    await expect(page.getByText("333")).toBeVisible();
 80  });
 81  
 82  test("copied file", async ({ page }) => {
 83    await page.goto(
 84      `${sourceBrowsingUrl}/remotes/${aliceRemote}/commits/f48a1056a5bd02277978f6e8a00517a967546340`,
 85    );
 86    await expect(
 87      page.getByText("copies/aaa.txt → copies/aaa_copy.txt copied"),
 88    ).toBeVisible();
 89  });
 90  
 91  test("binary file detection in diffs", async ({ page }) => {
 92    await page.goto(
 93      `${sourceBrowsingUrl}/commits/335dd6dc89b535a4a31e9422c803199bb6b0a09a`,
 94    );
 95    await expect(page.getByText("Binary file")).toBeVisible();
 96  });
 97  
 98  test("navigation to source tree at specific revision", async ({ page }) => {
 99    await page.goto(
100      `${sourceBrowsingUrl}/commits/0801aceeab500033f8d608778218657bd626ef73`,
101    );
102  
103    // Go to source tree at this revision.
104    await page.getByTitle("View file at this commit").click();
105    const branchSelectorCommitButton = page.getByTitle("Current HEAD").first();
106    await expect(
107      branchSelectorCommitButton.getByText("Add a deeply nested directory tree"),
108    ).toBeVisible();
109    await expect(page).toHaveURL(
110      `${sourceBrowsingUrl}/tree/0801aceeab500033f8d608778218657bd626ef73/deep/directory/hierarchy/is/entirely/possible/in/git/repositories/.gitkeep`,
111    );
112    await expect(branchSelectorCommitButton).toContainText("0801ace");
113    await expect(page.locator(".source-tree >> text=.gitkeep")).toBeVisible();
114    await expect(
115      page
116        .locator(
117          "text=deep/directory/hierarchy/is/entirely/possible/in/git/repositories/",
118        )
119        .nth(1),
120    ).toBeVisible();
121  });