Skip to content

Commit

Permalink
test setup for reproducing #956
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalomonsen committed Oct 12, 2024
1 parent fb86c78 commit 80ef6e5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
72 changes: 55 additions & 17 deletions playwright-tests/tests/proposal/links.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test, { expect } from "@playwright/test";
import { test } from "../../util/multiinstance.js";
import { expect } from "@playwright/test";
import { pauseIfVideoRecording } from "../../testUtils.js";

test.describe("share links", () => {
Expand All @@ -7,10 +8,16 @@ test.describe("share links", () => {
permissions: ["clipboard-read", "clipboard-write"],
},
});
test("copy link button should create a clean URL link", async ({ page }) => {
await page.goto("/devhub.near/widget/app?page=proposal&id=127");
test("copy link button should create a clean URL link", async ({
page,
account,
linksTestProposalId,
}) => {
await page.goto(
`/${account}/widget/app?page=proposal&id=${linksTestProposalId}`
);

await expect(await page.getByText("#127")).toBeVisible();
await expect(await page.getByText(`#${linksTestProposalId}`)).toBeVisible();
const shareLinkButton = await page.getByRole("button", { name: "" });
await shareLinkButton.click();
await page.getByRole("button", { name: "Copy link to proposal" }).click();
Expand All @@ -19,63 +26,94 @@ test.describe("share links", () => {
"navigator.clipboard.readText()"
);
expect(linkUrlFromClipboard).toEqual(
"https://devhub.near.page/proposal/127"
`https://${account}.page/proposal/${linksTestProposalId}`
);
await pauseIfVideoRecording(page);
await page.goto(linkUrlFromClipboard);

await expect(await page.getByText("#127")).toBeVisible({
await expect(await page.getByText(`#${linksTestProposalId}`)).toBeVisible({
timeout: 10000,
});
});

test("share on X should create a clean URL link", async ({
page,
account,
linksTestProposalId,
context,
}) => {
await page.goto("/devhub.near/widget/app?page=proposal&id=127");
await page.goto(
`/${account}/widget/app?page=proposal&id=${linksTestProposalId}`
);

await expect(await page.getByText("#127")).toBeVisible();
await expect(await page.getByText(`#${linksTestProposalId}`)).toBeVisible();
const shareLinkButton = await page.getByRole("button", { name: "" });
await shareLinkButton.click();
const shareOnXLink = await page.getByRole("link", { name: " Share on X" });
const shareOnXUrl = await shareOnXLink.getAttribute("href");
await expect(shareOnXUrl).toEqual(
"https://x.com/intent/post?text=Check+out+this+proposal+on+%40NEARProtocol%0A%23NEAR+%23BOS%0Ahttps%3A%2F%2Fdevhub.near.page%2Fproposal%2F127"
`https://x.com/intent/post?text=Check+out+this+proposal+on+%40NEARProtocol%0A%23NEAR+%23BOS%0Ahttps%3A%2F%2F${account}.page%2Fproposal%2F${linksTestProposalId}`
);
await shareOnXLink.click();
const twitterPage = await context.waitForEvent("page");
await twitterPage.waitForURL(shareOnXUrl);
});

test("comment links should scroll into view", async ({ page }) => {
test("comment links should scroll into view", async ({
page,
account,
linksTestProposalId,
linksTestCommentAuthorId,
linksTestCommentBlockHeight,
}) => {
test.setTimeout(60000);
await page.goto(
"/devhub.near/widget/app?page=proposal&id=127&accountId=theori.near&blockHeight=121684702"
`/${account}/widget/app?page=proposal&id=${linksTestProposalId}&accountId=${linksTestCommentAuthorId}&blockHeight=${linksTestCommentBlockHeight}`
);
const viewer = await page.locator("near-social-viewer");
const commentElement = await viewer.locator("css=div#theorinear121684702");
const commentElement = await viewer.locator(
`css=div#${linksTestCommentAuthorId.replaceAll(
/[^0-9a-z]/g,
""
)}${linksTestCommentBlockHeight}`
);
await expect(commentElement).toBeVisible({ timeout: 30000 });
await expect(commentElement).toBeInViewport({ timeout: 30000 });
});

test("copying comment links should have clean URLs", async ({ page }) => {
test("copying comment links should have clean URLs", async ({
page,
account,
linksTestProposalId,
linksTestCommentAuthorId,
linksTestCommentBlockHeight,
}) => {
await page.goto(
"/devhub.near/widget/app?page=proposal&id=127&accountId=theori.near&blockHeight=121684702"
`/${account}/widget/app?page=proposal&id=${linksTestProposalId}&accountId=${linksTestCommentAuthorId}&blockHeight=${linksTestCommentBlockHeight}`
);
const viewer = await page.locator("near-social-viewer");
const commentElement = await viewer.locator("css=div#theorinear121684702");
const commentElement = await viewer.locator(
`css=div#${linksTestCommentAuthorId.replaceAll(
/[^0-9a-z]/g,
""
)}${linksTestCommentBlockHeight}`
);
await expect(commentElement).toBeVisible({ timeout: 20000 });
await page
.locator("#theorinear121684702")
.locator(
`#${linksTestCommentAuthorId.replaceAll(
/[^0-9a-z]/g,
""
)}${linksTestCommentBlockHeight}`
)
.getByLabel("Copy URL to clipboard")
.click();

const linkUrlFromClipboard = await page.evaluate(
"navigator.clipboard.readText()"
);
expect(linkUrlFromClipboard).toEqual(
"https://devhub.near.page/proposal/127?accountId=theori.near&blockHeight=121684702"
`https://${account}.page/proposal/${linksTestProposalId}?accountId=${linksTestCommentAuthorId}&blockHeight=${linksTestCommentBlockHeight}`
);
await pauseIfVideoRecording(page);
await page.goto(linkUrlFromClipboard);
Expand Down
10 changes: 2 additions & 8 deletions playwright-tests/tests/proposal/proposals.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test as base, expect } from "@playwright/test";
import { expect } from "@playwright/test";
import { test } from "../../util/multiinstance.js";
import { pauseIfVideoRecording } from "../../testUtils.js";
import { setCacheValue, setDontAskAgainCacheValues } from "../../util/cache.js";
import {
Expand All @@ -8,13 +9,6 @@ import {
} from "../../util/transaction.js";
import { MOCK_RPC_URL, mockRpcRequest } from "../../util/rpcmock.js";

const test = base.extend({
// Define an option and provide a default value.
// We can later override it in the config.
account: ["devhub.near", { option: true }],
proposalAuthorAccountId: ["megha19.near", { option: true }],
});

test.afterEach(
async ({ page }) => await page.unrouteAll({ behavior: "ignoreErrors" })
);
Expand Down
11 changes: 11 additions & 0 deletions playwright-tests/util/multiinstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test as base, expect } from "@playwright/test";

export const test = base.extend({
// Define an option and provide a default value.
// We can later override it in the config.
account: ["devhub.near", { option: true }],
proposalAuthorAccountId: ["megha19.near", { option: true }],
linksTestProposalId: [1, { option: true }],
linksTestCommentAuthorId: ["theori.near", { option: true }],
linksTestCommentBlockHeight: [121684702, { option: true }],
});
6 changes: 6 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export default defineConfig({
use: {
...devices["Desktop Chrome"],
account: "infrastructure-committee.near",
linksTestProposalId: 1,
linksTestCommentAuthorId: "as2.near",
linksTestCommentBlockHeight: 124005661,
},
},
{
Expand All @@ -72,6 +75,9 @@ export default defineConfig({
baseURL: "http://localhost:8080",
account: "devhub.near",
proposalAuthorAccountId: "megha19.near",
linksTestProposalId: 127,
linksTestCommentAuthorId: "theori.near",
linksTestCommentBlockHeight: 121684702,
},
},
],
Expand Down

0 comments on commit 80ef6e5

Please sign in to comment.