Skip to content

Commit

Permalink
Clean URL for community share button, proposal link tests for events …
Browse files Browse the repository at this point in the history
…committee (#888)

* test events committee proposal link sharing

* clean URL for community share button

fixes #889

* show URL during test
  • Loading branch information
petersalomonsen authored Jul 20, 2024
1 parent b48b7ac commit 2ab1c58
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"customizations": {
"vscode": {
"extensions": ["ms-playwright.playwright"]
"extensions": ["ms-playwright.playwright", "github.vscode-github-actions"]
}
},
"postCreateCommand": ".devcontainer/post-create.sh"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration-workflow-events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions instances/devhub.near/widget/devhub/page/community/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions playwright-tests/testUtils.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
39 changes: 39 additions & 0 deletions playwright-tests/tests/community/sharelinks.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 2ab1c58

Please sign in to comment.