Skip to content

Commit

Permalink
Fix copying wrong ids when switching cob listing state
Browse files Browse the repository at this point in the history
We don't really need the `clipboard` prop.
By switching between stats in patches and issue listings the clipboard
props aren't been recomputed.

Wrote a test that should make sure this doesn't break in the future.
  • Loading branch information
sebastinez authored and rudolfs committed Nov 27, 2024
1 parent f19ecf0 commit 723d188
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/components/Id.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +25,7 @@
}, 1000);
async function copy() {
await toClipboard(clipboard);
await toClipboard(id);
icon = "checkmark";
tooltip = "Copied to clipboard";
restoreIcon();
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/NodeAddress.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 1 addition & 6 deletions src/views/nodes/UserAgent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
37 changes: 22 additions & 15 deletions tests/e2e/clipboard.spec.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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('')");
Expand Down

0 comments on commit 723d188

Please sign in to comment.