mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-10-18 19:10:45 +08:00
Keep the browsed file in the source view route
Browsing the file tree only changed component state, so no file view was ever a history entry and back left the repository. The path now travels as a query parameter, since trailing URL segments are already consumed by the revision.
This commit is contained in:
@@ -25,8 +25,13 @@ test("open a relative link in the source view", async ({ page }) => {
|
||||
const url = page.url();
|
||||
await readme.getByRole("link", { name: "the notes" }).click();
|
||||
|
||||
// The link opens the file instead of navigating the app away.
|
||||
// The link opens the file in the source view rather than navigating the
|
||||
// window away, and the file it opened is part of the history.
|
||||
await expect(page.getByText("Notes from a sibling file.")).toBeVisible();
|
||||
expect(page.url()).not.toBe(url);
|
||||
|
||||
await page.goBack();
|
||||
await expect(readme.getByText("Alpha section text.")).toBeVisible();
|
||||
expect(page.url()).toBe(url);
|
||||
});
|
||||
|
||||
@@ -94,6 +99,54 @@ test("bound the reads of recursive includes", async ({ page }) => {
|
||||
expect(blobReads).toBeLessThanOrEqual(260);
|
||||
});
|
||||
|
||||
test("go back from a file opened in the tree", async ({ page }) => {
|
||||
await page.goto("/inbox");
|
||||
await page.getByRole("link", { name: "asciidoc" }).click();
|
||||
|
||||
const readme = page.locator(".asciidoc");
|
||||
await expect(readme.getByText("Alpha section text.")).toBeVisible();
|
||||
const url = page.url();
|
||||
|
||||
await page.getByText("notes.txt", { exact: true }).click();
|
||||
await expect(page.getByText("Notes from a sibling file.")).toBeVisible();
|
||||
await expect(page).toHaveURL(/\?path=notes\.txt/);
|
||||
|
||||
await page.goBack();
|
||||
await expect(readme.getByText("Alpha section text.")).toBeVisible();
|
||||
expect(page.url()).toBe(url);
|
||||
});
|
||||
|
||||
test("show the same path at another revision", async ({ page }) => {
|
||||
await page.goto("/inbox");
|
||||
const commit = page.waitForResponse(
|
||||
response => new URL(response.url()).pathname === "/repo_commit",
|
||||
);
|
||||
await page.getByRole("link", { name: "asciidoc" }).click();
|
||||
const { parents } = (await (await commit).json()) as { parents: string[] };
|
||||
const rid = page.url().match(/\/repos\/(rad:[^/?]+)/)?.[1];
|
||||
|
||||
await page.getByText("notes.txt", { exact: true }).click();
|
||||
await expect(page.getByText("Notes from a sibling file.")).toBeVisible();
|
||||
|
||||
// Follow an in-app link to the same file at the previous commit, so the
|
||||
// view is reused with only the revision changed.
|
||||
await page.evaluate(href => {
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = href;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
}, `/repos/${rid}/home/${parents[0]}?path=notes.txt`);
|
||||
|
||||
await expect(
|
||||
page.getByText("An earlier version of the notes."),
|
||||
).toBeVisible();
|
||||
await expect(page.getByText("Notes from a sibling file.")).toHaveCount(0);
|
||||
|
||||
await page.goBack();
|
||||
await expect(page.getByText("Notes from a sibling file.")).toBeVisible();
|
||||
});
|
||||
|
||||
test("sanitize untrusted markup in an AsciiDoc readme", async ({ page }) => {
|
||||
await page.goto("/inbox");
|
||||
await page.getByRole("link", { name: "asciidoc" }).click();
|
||||
|
||||
@@ -597,6 +597,15 @@ export async function createMarkdownFixture(peer: RadiclePeer) {
|
||||
export async function createAsciidocFixture(peer: RadiclePeer) {
|
||||
const { repoFolder } = await createRepo(peer, { name: "asciidoc" });
|
||||
|
||||
// An older version of a file, so a test can show the same path at two
|
||||
// revisions.
|
||||
await Fs.writeFile(
|
||||
Path.join(repoFolder, "notes.txt"),
|
||||
"An earlier version of the notes.\n",
|
||||
);
|
||||
await peer.git(["add", "."], { cwd: repoFolder });
|
||||
await peer.git(["commit", "-m", "Add notes"], { cwd: repoFolder });
|
||||
|
||||
await Fs.writeFile(
|
||||
Path.join(repoFolder, "README.adoc"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user