Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
Fix copying wrong ids when switching cob listing state
Sebastian Martinez committed 1 year ago
commit 723d188e9e39305408fd74f2b3e4540b12bd4de4
parent f19ecf0
4 files changed +25 -24
modified src/components/Id.svelte
@@ -9,7 +9,6 @@
  import Icon from "./Icon.svelte";

  export let id: string;
-
  export let clipboard: string = id;
  export let shorten: boolean = true;
  export let style: "oid" | "commit" | "none" = "oid";
  export let ariaLabel: string | undefined = undefined;
@@ -26,7 +25,7 @@
  }, 1000);

  async function copy() {
-
    await toClipboard(clipboard);
+
    await toClipboard(id);
    icon = "checkmark";
    tooltip = "Copied to clipboard";
    restoreIcon();
modified src/views/nodes/NodeAddress.svelte
@@ -13,7 +13,7 @@

<div style:word-break="break-word">
  <!--prettier-ignore-->
-
  <Id ariaLabel="node-id" shorten={false} id={clipboard} {clipboard}>
+
  <Id ariaLabel="node-id" shorten={false} id={clipboard}>
    {#if node.config?.externalAddresses.length}
      {truncateId(node.id)}@<wbr />{node.config?.externalAddresses[0]}
    {:else}
modified src/views/nodes/UserAgent.svelte
@@ -30,12 +30,7 @@

<div class="item">
  <div style:white-space="nowrap">User Agent</div>
-
  <Id
-
    ariaLabel="agent"
-
    id={agent}
-
    clipboard={agent}
-
    shorten={false}
-
    style="none">
+
  <Id ariaLabel="agent" id={agent} shorten={false} style="none">
    <div class="agent">
      <div class="txt-overflow">{agent}</div>
    </div>
modified tests/e2e/clipboard.spec.ts
@@ -1,19 +1,11 @@
-
import type { Page } from "@playwright/test";
-

import {
  expect,
  sourceBrowsingUrl,
  sourceBrowsingRid,
  test,
+
  cobUrl,
} from "@tests/support/fixtures.js";

-
async function expectClipboard(content: string, page: Page) {
-
  const clipboardContent = await page.evaluate<string>(
-
    "navigator.clipboard.readText()",
-
  );
-
  expect(clipboardContent).toBe(content);
-
}
-

// We explicitly run all clipboard tests withing the context of a single test
// so that we don't run into race conditions, because there is no way to isolate
// the clipboard in Playwright yet.
@@ -25,6 +17,13 @@ test("copy to clipboard", async ({ page, browserName, context }) => {
    test.skip();
  }

+
  async function expectClipboard(content: string) {
+
    const clipboardContent = await page.evaluate<string>(
+
      "navigator.clipboard.readText()",
+
    );
+
    expect(clipboardContent).toBe(content);
+
  }
+

  await page.goto(sourceBrowsingUrl);

  // Reset system clipboard to a known state.
@@ -33,17 +32,14 @@ test("copy to clipboard", async ({ page, browserName, context }) => {
  // Repo ID.
  {
    await page.getByLabel("repo-id").click();
-
    const clipboardContent = await page.evaluate<string>(
-
      "navigator.clipboard.readText()",
-
    );
-
    expect(clipboardContent).toBe(sourceBrowsingRid);
+
    await expectClipboard(sourceBrowsingRid);
  }

  // `rad clone` URL.
  {
    await page.getByRole("button", { name: "Clone" }).first().click();
    await page.getByText("rad clone").locator(".clipboard").first().click();
-
    await expectClipboard(`rad clone ${sourceBrowsingRid}`, page);
+
    await expectClipboard(`rad clone ${sourceBrowsingRid}`);
  }

  // `git clone` URL.
@@ -55,10 +51,21 @@ test("copy to clipboard", async ({ page, browserName, context }) => {
        "rad:",
        "",
      )}.git source-browsing`,
-
      page,
    );
  }

+
  // After switching the patch or issue listing the `<Id>` components should return new COB ids.
+
  {
+
    await page.goto(`${cobUrl}/patches`);
+
    await page.getByRole("button", { name: "59a0821", exact: true }).click();
+
    await expectClipboard("59a0821edc73630bce540596cffc7854da557365");
+

+
    await page.getByLabel("filter-dropdown").click();
+
    await page.getByRole("button", { name: "Draft" }).click();
+
    await page.getByRole("button", { name: "783d33c", exact: true }).click();
+
    await expectClipboard("783d33c5b14e13234d4d7affa98bd0b52d1b1ea3");
+
  }
+

  // Clear the system clipboard contents so developers don't wonder why there's
  // random stuff in their clipboard after running tests.
  await page.evaluate<string>("navigator.clipboard.writeText('')");