Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
Handle CommitTeaser with double colon commit messages
Merged did:key:z6MkkfM3...sVz5 opened 3 years ago

Includes:

  • Add a new plain marked instance
  • Add a new e2e test case for commit messages with double colons

check check-visual check-unit-test check-httpd-api-unit-test check-e2e check-build

👉 Preview 👉 Workflow runs 👉 Branch on GitHub

8 files changed +108 -33 3d13bc03 29d34096
modified src/components/Markdown.svelte
@@ -9,8 +9,7 @@
  import * as modal from "@app/lib/modal";
  import * as router from "@app/lib/router";
  import ErrorModal from "@app/modals/ErrorModal.svelte";
-
  import markdown from "@app/lib/markdown";
-
  import { Renderer } from "@app/lib/markdown";
+
  import { Renderer, markdownWithExtensions } from "@app/lib/markdown";
  import { activeUnloadedRouteStore } from "@app/lib/router";
  import { highlight } from "@app/lib/syntax";
  import {
@@ -93,7 +92,7 @@

  function render(content: string): string {
    return dompurify.sanitize(
-
      markdown.parse(content, {
+
      markdownWithExtensions.parse(content, {
        renderer: new Renderer($activeUnloadedRouteStore, {
          stripEmphasizedStyling: false,
        }),
modified src/lib/markdown.ts
@@ -1,4 +1,4 @@
-
import type { Tokens } from "marked";
+
import type { MarkedExtension, Tokens } from "marked";
import type { Route } from "@app/lib/router";

import dompurify from "dompurify";
@@ -75,9 +75,7 @@ const footnoteMarkedExtension = {
  renderer: (token: Tokens.Generic): string =>
    `<p class="txt-small footnote" id="${footnotePrefix}:${
      token.reference
-
    }"><span class="marker">${
-
      token.reference
-
    }.</span> ${markedInstance.parseInline(
+
    }"><span class="marker">${token.reference}.</span> ${markdownWithExtensions.parseInline(
      token.text,
    )} <a class="txt-tiny ref-arrow no-underline" href="#${referencePrefix}:${
      token.reference
@@ -159,17 +157,21 @@ export class Renderer extends BaseRenderer {
  }
}

-
const markedInstance = new Marked(
-
  katexMarkedExtension({ throwOnError: false }),
-
  markedLinkifyIt({}, { fuzzyLink: false }),
-
  {
+
function markedCustomExtensions(): MarkedExtension {
+
  return {
    extensions: [
      emojisMarkedExtension,
      footnoteMarkedExtension,
      footnoteReferenceMarkedExtension,
      anchorMarkedExtension,
    ],
-
  },
-
);
+
  };
+
}
+

+
export default new Marked();

-
export default markedInstance;
+
export const markdownWithExtensions = new Marked(
+
  katexMarkedExtension({ throwOnError: false }),
+
  markedLinkifyIt({}, { fuzzyLink: false }),
+
  markedCustomExtensions(),
+
);
modified tests/e2e/project.spec.ts
@@ -1,8 +1,12 @@
import {
+
  aliceMainCommitCount,
+
  aliceMainCommitMessage,
  aliceMainHead,
+
  bobMainCommitCount,
  cobUrl,
  expect,
  markdownUrl,
+
  shortAliceHead,
  shortBobHead,
  sourceBrowsingRid,
  sourceBrowsingUrl,
@@ -30,11 +34,15 @@ test("navigate to project", async ({ page }) => {
  {
    await expect(page.getByTitle("Change branch")).toBeVisible();
    await expect(
-
      page.getByRole("button", { name: "4a9f278 Add submodule" }).first(),
+
      page
+
        .getByRole("button", {
+
          name: `${shortAliceHead} ${aliceMainCommitMessage}`,
+
        })
+
        .first(),
    ).toBeVisible();
    await expect(
      page.getByRole("link", {
-
        name: "Commits 7",
+
        name: `Commits ${aliceMainCommitCount}`,
      }),
    ).toBeVisible();
  }
@@ -54,7 +62,9 @@ test("navigate to project", async ({ page }) => {

test("show source tree at specific revision", async ({ page }) => {
  await page.goto(sourceBrowsingUrl);
-
  await page.getByRole("link", { name: "Commits 7" }).click();
+
  await page
+
    .getByRole("link", { name: `Commits ${aliceMainCommitCount}` })
+
    .click();

  await page
    .locator(".teaser", { hasText: "335dd6d" })
@@ -290,11 +300,15 @@ test("peer and branch switching", async ({ page }) => {
    {
      await expect(page.getByTitle("Change branch")).toHaveText("main");
      await expect(
-
        page.getByRole("button", { name: "4a9f278 Add submodule" }).first(),
+
        page
+
          .getByRole("button", {
+
            name: `${shortAliceHead} ${aliceMainCommitMessage}`,
+
          })
+
          .first(),
      ).toBeVisible();
      await expect(
        page.getByRole("link", {
-
          name: "Commits 7",
+
          name: `Commits ${aliceMainCommitCount}`,
        }),
      ).toBeVisible();
    }
@@ -347,7 +361,11 @@ test("peer and branch switching", async ({ page }) => {

    await expect(page.getByTitle("Change branch")).toBeVisible();
    await expect(
-
      page.getByRole("button", { name: "4a9f278 Add submodule" }).first(),
+
      page
+
        .getByRole("button", {
+
          name: `${shortAliceHead} ${aliceMainCommitMessage}`,
+
        })
+
        .first(),
    ).toBeVisible();
    await expect(page.getByText("Git test repository")).toBeVisible();
  }
@@ -369,7 +387,7 @@ test("peer and branch switching", async ({ page }) => {
      ).toBeVisible();
      await expect(
        page.getByRole("link", {
-
          name: "Commits 8",
+
          name: `Commits ${bobMainCommitCount}`,
        }),
      ).toBeVisible();
      await expect(
modified tests/e2e/project/commit.spec.ts
@@ -1,6 +1,7 @@
import {
  aliceRemote,
  bobHead,
+
  bobMainCommitCount,
  expect,
  shortBobHead,
  sourceBrowsingUrl,
@@ -14,7 +15,9 @@ test("navigation from commit list", async ({ page }) => {
  await page.goto(sourceBrowsingUrl);
  await page.getByTitle("Change peer").click();
  await page.getByRole("link", { name: "bob" }).click();
-
  await page.getByRole("link", { name: "Commits 8" }).click();
+
  await page
+
    .getByRole("link", { name: `Commits ${bobMainCommitCount}` })
+
    .click();

  await page.getByText("Update readme").first().click();
  await expect(page).toHaveURL(commitUrl);
modified tests/e2e/project/commits.spec.ts
@@ -1,5 +1,8 @@
import {
+
  aliceMainCommitCount,
+
  aliceMainCommitMessage,
  aliceMainHead,
+
  bobMainCommitCount,
  expect,
  gitOptions,
  shortBobHead,
@@ -11,7 +14,9 @@ import sinon from "sinon";

test("peer and branch switching", async ({ page }) => {
  await page.goto(sourceBrowsingUrl);
-
  await page.getByRole("link", { name: "Commits 7" }).click();
+
  await page
+
    .getByRole("link", { name: `Commits ${aliceMainCommitCount}` })
+
    .click();

  // Alice's peer.
  {
@@ -25,10 +30,12 @@ test("peer and branch switching", async ({ page }) => {
    await expect(page.getByTitle("Change peer")).toHaveText("alice Delegate");

    await expect(page.getByText("Thursday, November 17, 2022")).toBeVisible();
-
    await expect(page.locator(".list .teaser")).toHaveCount(7);
+
    await expect(page.locator(".list .teaser")).toHaveCount(
+
      aliceMainCommitCount,
+
    );

    const latestCommit = page.locator(".teaser").first();
-
    await expect(latestCommit).toContainText("Add submodule");
+
    await expect(latestCommit).toContainText(aliceMainCommitMessage);
    await expect(latestCommit).toContainText(aliceMainHead.substring(0, 7));

    const earliestCommit = page.locator(".teaser").last();
@@ -44,7 +51,7 @@ test("peer and branch switching", async ({ page }) => {
      page.getByRole("button", { name: "feature/branch" }),
    ).toBeVisible();
    await expect(page.getByText("Thursday, November 17, 2022")).toBeVisible();
-
    await expect(page.locator(".list .teaser")).toHaveCount(9);
+
    await expect(page.locator(".list .teaser")).toHaveCount(bobMainCommitCount);

    await page.getByTitle("Change branch").click();
    await page.getByText("orphaned-branch").click();
@@ -85,14 +92,47 @@ test("peer and branch switching", async ({ page }) => {
  }
});

+
test("commit messages with double colon not converted into single colon", async ({
+
  page,
+
}) => {
+
  const commitMessage = "Verify that crate::DoubleColon::should_work()";
+
  const shortCommit = "7babd25";
+
  await page.goto(sourceBrowsingUrl);
+
  await page
+
    .getByRole("link", { name: `Commits ${aliceMainCommitCount}` })
+
    .click();
+

+
  await expect(
+
    page.getByRole("button", {
+
      name: `${shortCommit} ${commitMessage}`,
+
    }),
+
  ).toBeVisible();
+
  await expect(
+
    page.getByRole("link", {
+
      name: commitMessage,
+
      exact: true,
+
    }),
+
  ).toBeVisible();
+

+
  await page
+
    .getByRole("link", {
+
      name: commitMessage,
+
      exact: true,
+
    })
+
    .click();
+
  await expect(page.getByText(commitMessage, { exact: true })).toBeVisible();
+
});
+

test("expand commit message", async ({ page }) => {
  await page.goto(sourceBrowsingUrl);
-
  await page.getByRole("link", { name: "Commits 7" }).click();
+
  await page
+
    .getByRole("link", { name: `Commits ${aliceMainCommitCount}` })
+
    .click();
  const commitToggle = page.getByRole("button", { name: "expand" }).first();

  await commitToggle.click();
  const expandedCommit = page.getByText(
-
    "Signed-off-by: Alice Liddell <alice@radicle.xyz>",
+
    "This shouldn't replace double colons with simple colons",
  );

  await expect(expandedCommit).toBeVisible();
@@ -111,7 +151,9 @@ test("relative timestamps", async ({ page }) => {
  });

  await page.goto(sourceBrowsingUrl);
-
  await page.getByRole("link", { name: "Commits 7" }).click();
+
  await page
+
    .getByRole("link", { name: `Commits ${aliceMainCommitCount}` })
+
    .click();

  await page.getByTitle("Change peer").click();
  await page.getByRole("link", { name: "bob" }).click();
modified tests/e2e/router.ts
@@ -1,4 +1,5 @@
import {
+
  aliceMainCommitCount,
  aliceMainHead,
  aliceRemote,
  expect,
@@ -63,7 +64,10 @@ test.describe("project page navigation", () => {
      .waitFor({ state: "hidden" });
    await expect(page).toHaveURL(projectTreeURL);

-
    await page.getByRole("link", { name: "Commits 7" }).click();
+
    await page
+
      .getByRole("link", { name: `Commits ${aliceMainCommitCount}` })
+
      .click();
+

    await expect(page).toHaveURL(
      `${sourceBrowsingUrl}/history/${aliceMainHead}`,
    );
@@ -86,7 +90,9 @@ test.describe("project page navigation", () => {
    await page.getByText(".hidden").click();
    await expect(page).toHaveURL(`${projectTreeURL}/tree/.hidden`);

-
    await page.getByRole("link", { name: "Commits 7" }).click();
+
    await page
+
      .getByRole("link", { name: `Commits ${aliceMainCommitCount}` })
+
      .click();
    await expect(page).toHaveURL(`${sourceBrowsingUrl}/history`);
  });

modified tests/fixtures/repos/source-browsing.tar.bz2
modified tests/support/fixtures.ts
@@ -599,12 +599,17 @@ export async function createMarkdownFixture(peer: RadiclePeer) {
  );
}

-
export const aliceMainHead = "4a9f278344b795afaef44c0d9effb35c4d794fba";
+
export const aliceMainHead = "7babd25a74eb3752ec24672b5edf0e7ecb4daf24";
+
export const aliceMainCommitMessage =
+
  "Verify that crate::DoubleColon::should_work()";
+
export const aliceMainCommitCount = 8;
export const aliceRemote =
  "did:key:z6MkqGC3nWZhYieEVTVDKW5v588CiGfsDSmRVG9ZwwWTvLSK";
+
export const shortAliceHead = formatCommit(aliceMainHead);
export const bobRemote =
  "did:key:z6Mkg49NtQR2LyYRDCQFK4w1VVHqhypZSSRo7HsyuN7SV7v5";
-
export const bobHead = "79b0b2522c0d406d398cb5b7b381455294e1489f";
+
export const bobHead = "82f570ec909e77c7e1bb764f1429b1e01b1b4a90";
+
export const bobMainCommitCount = 9;
export const shortBobHead = formatCommit(bobHead);
export const sourceBrowsingRid = "rad:z4BwwjPCFNVP27FwVbDFgwVwkjcir";
export const cobRid = "rad:z3fpY7nttPPa6MBnAv2DccHzQJnqe";