From 2ab1c5834cdf3cd29dd3e7d45e1ea95f928e16a2 Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Sat, 20 Jul 2024 10:40:42 +0200 Subject: [PATCH] Clean URL for community share button, proposal link tests for events committee (#888) * test events committee proposal link sharing * clean URL for community share button fixes #889 * show URL during test --- .devcontainer/devcontainer.json | 2 +- ...continuous-integration-workflow-events.yml | 3 ++ .../widget/devhub/page/community/index.jsx | 8 +--- playwright-tests/testUtils.js | 16 ++++++++ .../tests/community/sharelinks.spec.js | 39 +++++++++++++++++++ 5 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 playwright-tests/tests/community/sharelinks.spec.js diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5348b4ac6..137a6ea80 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ }, "customizations": { "vscode": { - "extensions": ["ms-playwright.playwright"] + "extensions": ["ms-playwright.playwright", "github.vscode-github-actions"] } }, "postCreateCommand": ".devcontainer/post-create.sh" diff --git a/.github/workflows/continuous-integration-workflow-events.yml b/.github/workflows/continuous-integration-workflow-events.yml index 5ddd3bb39..26a500dbc 100644 --- a/.github/workflows/continuous-integration-workflow-events.yml +++ b/.github/workflows/continuous-integration-workflow-events.yml @@ -36,7 +36,10 @@ jobs: npx playwright install - name: Run tests run: | + # The whole proposal folder does not work yet + # INSTANCE=events npx playwright test --project=events playwright-tests/tests/proposal INSTANCE=events npx playwright test --project=events playwright-tests/tests/proposal/comment.spec.js + INSTANCE=events npx playwright test --project=events playwright-tests/tests/proposal/links.spec.js playwright-tests-events: name: Events Committee - Playwright tests runs-on: ubuntu-latest diff --git a/instances/devhub.near/widget/devhub/page/community/index.jsx b/instances/devhub.near/widget/devhub/page/community/index.jsx index b4d3a0764..1675316b6 100644 --- a/instances/devhub.near/widget/devhub/page/community/index.jsx +++ b/instances/devhub.near/widget/devhub/page/community/index.jsx @@ -72,13 +72,7 @@ const tabs = []; const onShareClick = () => clipboard - .writeText( - href({ - gateway: "near.social", - widgetSrc: "${REPL_DEVHUB}/widget/app", - params: { page: "community", handle: community.handle }, - }) - ) + .writeText(`https://${REPL_DEVHUB}.page/community/${community.handle}`) .then(setLinkCopied(true)); let currentTab = tabs.find((it) => normalize(it.title) === tab); diff --git a/playwright-tests/testUtils.js b/playwright-tests/testUtils.js index d0028c4ce..8995a1f1b 100644 --- a/playwright-tests/testUtils.js +++ b/playwright-tests/testUtils.js @@ -1,5 +1,21 @@ import { expect } from "@playwright/test"; +export async function showPageURLInTest(page) { + await page.evaluate(() => { + const urlDiv = document.createElement("div"); + urlDiv.style.position = "fixed"; + urlDiv.style.top = "0"; + urlDiv.style.left = "0"; + urlDiv.style.backgroundColor = "rgba(255, 200, 200, 0.8)"; + urlDiv.style.padding = "5px"; + urlDiv.style.zIndex = "10000"; + urlDiv.style.fontSize = "12px"; + urlDiv.style.fontFamily = "Arial, sans-serif"; + urlDiv.innerText = window.location.href; + document.body.appendChild(urlDiv); + }); +} + export const pauseIfVideoRecording = async (page) => { let isVideoRecorded = (await page.video()) ? true : false; if (isVideoRecorded) { diff --git a/playwright-tests/tests/community/sharelinks.spec.js b/playwright-tests/tests/community/sharelinks.spec.js new file mode 100644 index 000000000..d95b40ac9 --- /dev/null +++ b/playwright-tests/tests/community/sharelinks.spec.js @@ -0,0 +1,39 @@ +import { test, expect } from "@playwright/test"; +import { pauseIfVideoRecording, showPageURLInTest } from "../../testUtils.js"; + +test.describe("share links", () => { + test.use({ + contextOptions: { + permissions: ["clipboard-read", "clipboard-write"], + }, + }); + + test("community share button should create a clean URL", async ({ page }) => { + await page.goto( + "/devhub.near/widget/app?page=community&handle=webassemblymusic" + ); + await showPageURLInTest(page); + + const shareButton = await page.locator("button", { hasText: "Share" }); + await expect(shareButton).toBeVisible(); + + await shareButton.hover(); + await pauseIfVideoRecording(page); + await shareButton.click(); + + const linkUrlFromClipboard = await page.evaluate( + "navigator.clipboard.readText()" + ); + expect(linkUrlFromClipboard).toEqual( + "https://devhub.near.page/community/webassemblymusic" + ); + await pauseIfVideoRecording(page); + await page.goto(linkUrlFromClipboard); + + await showPageURLInTest(page); + await expect(await page.getByText("WebAssembly Music")).toBeVisible({ + timeout: 10000, + }); + await pauseIfVideoRecording(page); + }); +});