From 1499bdee50ff1687c2c67cc6833a40c85b989bd9 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 <100185149+Megha-Dev-19@users.noreply.github.com> Date: Mon, 1 Jul 2024 22:00:16 +0530 Subject: [PATCH 1/4] fix failing tests, add share post link tests --- playwright-tests/tests/activity.spec.js | 63 ++++++++++++++++++------- playwright.config.js | 1 + 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/playwright-tests/tests/activity.spec.js b/playwright-tests/tests/activity.spec.js index 146f594e..c6a44e6c 100644 --- a/playwright-tests/tests/activity.spec.js +++ b/playwright-tests/tests/activity.spec.js @@ -1,12 +1,15 @@ import { expect, test } from "@playwright/test"; import { ROOT_SRC } from "../util/constants"; import path from "path"; + const clickAndAssertTab = async (page, tabName, urlFragment, textToAssert) => { await page.getByRole("button", { name: tabName }).click(); expect(page.url()).toContain(urlFragment); await page.waitForTimeout(1000); if (textToAssert) { - expect(page.getByText(textToAssert, { exact: true })).toBeVisible(); + await expect(page.getByText(textToAssert).nth(0)).toBeVisible({ + timeout: 10000, + }); } }; @@ -17,7 +20,7 @@ test.describe("All tabs must be visible and redirected to respective pages", () }); test("All Feed", async ({ page }) => { - await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed"); + await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All"); }); test("Updates", async ({ page }) => { @@ -25,7 +28,7 @@ test.describe("All tabs must be visible and redirected to respective pages", () page, "Updates", "?page=activity&tab=updates", - "Updates Feed", + "Updates", ); }); @@ -34,17 +37,12 @@ test.describe("All tabs must be visible and redirected to respective pages", () page, "Question", "?page=activity&tab=question", - "Question Feed", + "Question", ); }); test("Idea", async ({ page }) => { - await clickAndAssertTab( - page, - "Idea", - "?page=activity&tab=idea", - "Idea Feed", - ); + await clickAndAssertTab(page, "Idea", "?page=activity&tab=idea", "Idea"); }); test("Feedback", async ({ page }) => { @@ -52,7 +50,7 @@ test.describe("All tabs must be visible and redirected to respective pages", () page, "Feedback", "?page=activity&tab=feedback", - "Feedback Feed", + "Feedback", ); }); @@ -76,7 +74,7 @@ test.describe("All tabs must be visible and redirected to respective pages", () page, "Request", "?page=activity&tab=request", - "Request Feed", + "Request", ); }); @@ -380,7 +378,6 @@ test.describe("User is logged in", () => { }); test("Edit a post and Save", async ({ page }) => { - await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed"); await page.waitForTimeout(1000); const dropdown = page.locator(".bi.bi-three-dots-vertical").nth(1); await dropdown.click(); @@ -412,7 +409,6 @@ test.describe("User is logged in", () => { }); test("Bookmark a Post", async ({ page }) => { - await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed"); await page.waitForTimeout(1000); const bookmarkIcon = await page.getByTitle("Bookmark").nth(1); await bookmarkIcon.click(); @@ -446,7 +442,6 @@ test.describe("User is logged in", () => { expect(transactionObj).toMatchObject(expectedTransactionData); }); test("Like a Post", async ({ page }) => { - await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed"); await page.waitForTimeout(1000); const likeIcon = await page.getByTitle("Like").nth(1); await page.waitForTimeout(1000); @@ -471,7 +466,6 @@ test.describe("User is logged in", () => { expect(transactionObj).toMatchObject(expectedTransactionData); }); test("Repost a Post", async ({ page }) => { - await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed"); await page.waitForTimeout(1000); const repostIcon = await page.getByTitle("Repost").nth(1); await page.waitForTimeout(1000); @@ -502,7 +496,6 @@ test.describe("User is logged in", () => { }); test("Comment on a post", async ({ page }) => { - await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed"); await page.waitForTimeout(1000); const commentIcon = await page.getByTitle("Comment").nth(1); await page.waitForTimeout(1000); @@ -533,8 +526,42 @@ test.describe("User is logged in", () => { }; expect(transactionObj).toMatchObject(expectedTransactionData); }); + + test.describe("All tabs must be visible and redirected to respective pages", () => { + test.beforeEach(async ({ page }) => { + await page.waitForTimeout(1000); + const shareBtn = await page.getByTitle("Share").nth(1); + await shareBtn.click(); + }); + + test("should copy post link to clipboard", async ({ page }) => { + await page.getByRole("button", { name: "Copy link to post" }).click(); + await page.waitForTimeout(1000); + const handle = await page.evaluateHandle(() => + navigator.clipboard.readText(), + ); + expect((await handle.jsonValue()).includes("MainPage.N.Post.Page")); + }); + + test("should share post link via email", async ({ page }) => { + await page.getByRole("button", { name: "Share by email" }).click(); + await page.waitForTimeout(1000); + const handle = await page.evaluateHandle(() => + navigator.clipboard.readText(), + ); + expect((await handle.jsonValue()).includes("MainPage.N.Post.Page")); + }); + + test("should share post link via twitter", async ({ page }) => { + const [newPage] = await Promise.all([ + page.waitForEvent("popup"), + page.getByRole("button", { name: "Share by Twitter" }).click(), + ]); + await newPage.waitForLoadState("domcontentloaded"); + expect(newPage.url()).toContain("https://x.com/intent"); + }); + }); test("Convert post into proposal", async ({ page }) => { - await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed"); await page.waitForTimeout(1000); const dropdown = page.locator(".bi.bi-three-dots-vertical").nth(1); await dropdown.click(); diff --git a/playwright.config.js b/playwright.config.js index aee6ac95..ba003e78 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -27,6 +27,7 @@ export default defineConfig({ reporter: "line", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { + permissions: ["clipboard-read"], video: "off", /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ actionTimeout: 0, From 6594336a4b7a20a32c2f7bbab8a7520c697f3461 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 <100185149+Megha-Dev-19@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:39:04 +0530 Subject: [PATCH 2/4] fix tests --- playwright-tests/tests/activity.spec.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/playwright-tests/tests/activity.spec.js b/playwright-tests/tests/activity.spec.js index c6a44e6c..2a6e4aa9 100644 --- a/playwright-tests/tests/activity.spec.js +++ b/playwright-tests/tests/activity.spec.js @@ -544,18 +544,16 @@ test.describe("User is logged in", () => { }); test("should share post link via email", async ({ page }) => { - await page.getByRole("button", { name: "Share by email" }).click(); await page.waitForTimeout(1000); - const handle = await page.evaluateHandle(() => - navigator.clipboard.readText(), - ); - expect((await handle.jsonValue()).includes("MainPage.N.Post.Page")); + // mailto opens email app, couldn't find a way to test opening of that app + const emailLink = page.getByRole("link", { name: " Share by email" }); + await expect(emailLink).toHaveAttribute("href", /^mailto:/); }); test("should share post link via twitter", async ({ page }) => { const [newPage] = await Promise.all([ page.waitForEvent("popup"), - page.getByRole("button", { name: "Share by Twitter" }).click(), + page.getByRole("link", { name: " Share on Twitter" }).click(), ]); await newPage.waitForLoadState("domcontentloaded"); expect(newPage.url()).toContain("https://x.com/intent"); From 6612254050c47424100022974d859c9491cfe095 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 <100185149+Megha-Dev-19@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:00:56 +0530 Subject: [PATCH 3/4] minor fixes --- playwright-tests/tests/auth.spec.js | 12 ++++++++---- playwright-tests/tests/editor.spec.js | 10 +++++----- playwright-tests/tests/profile.spec.js | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/playwright-tests/tests/auth.spec.js b/playwright-tests/tests/auth.spec.js index aef3295b..377861bd 100644 --- a/playwright-tests/tests/auth.spec.js +++ b/playwright-tests/tests/auth.spec.js @@ -30,15 +30,19 @@ test.describe("User is logged in", () => { }); test("To verify that the user is logged in succesfully", async ({ page }) => { - const LoggedInButton = page.getByRole("button", { name: "anybody.near" }); - await expect(LoggedInButton).toHaveText("anybody.near"); + const LoggedInButton = page.getByRole("button", { + name: "saswat_test.testnet", + }); + await expect(LoggedInButton).toHaveText("saswat_test.testnet"); }); test("To verify that the sign out button is visible in the dropdown and when clicked navigates to logout page", async ({ page, }) => { - const LoggedInButton = page.getByRole("button", { name: "anybody.near" }); - await expect(LoggedInButton).toHaveText("anybody.near"); + const LoggedInButton = page.getByRole("button", { + name: "saswat_test.testnet", + }); + await expect(LoggedInButton).toHaveText("saswat_test.testnet"); await LoggedInButton.click(); const dropdownItems = await page.$$(".dropdown-item"); const secondDropdownItem = dropdownItems[1]; diff --git a/playwright-tests/tests/editor.spec.js b/playwright-tests/tests/editor.spec.js index 0fbbead6..404cfcd2 100644 --- a/playwright-tests/tests/editor.spec.js +++ b/playwright-tests/tests/editor.spec.js @@ -105,7 +105,7 @@ test.describe("?page=projects&tab=editor", () => { website: "https://www.samplewebsite.com", }, // End remove - contributors: ["anybody.near", "nobody.near"], + contributors: ["saswat_test.testnet", "nobody.testnet"], tabs: ["overview", "tasks", "activity"], projectAccountId: "anyproject.near", teamSize: "1-10", @@ -113,7 +113,7 @@ test.describe("?page=projects&tab=editor", () => { }; const expectedTransactionData = { - "anybody.near": { + "saswat_test.testnet": { project: { "sample-project": { "": JSON.stringify(expectedProjectData), @@ -140,7 +140,7 @@ test.describe("?page=projects&tab=editor", () => { }, "builddao.testnet": { project: { - "anybody.near_project_sample-project": "", + "saswat_test.testnet_project_sample-project": "", }, }, }, @@ -184,8 +184,8 @@ test.describe("?page=projects&tab=editor", () => { // Contributors await page.getByRole("combobox").nth(0).click(); - await page.getByRole("combobox").nth(0).fill("nobody.near"); - await page.getByLabel("nobody.near").click(); + await page.getByRole("combobox").nth(0).fill("nobody.testnet"); + await page.getByLabel("nobody.testnet").click(); await page.route("**/add", async (route) => { const modifiedResponse = { diff --git a/playwright-tests/tests/profile.spec.js b/playwright-tests/tests/profile.spec.js index 3cb2a716..ec3b77d8 100644 --- a/playwright-tests/tests/profile.spec.js +++ b/playwright-tests/tests/profile.spec.js @@ -15,7 +15,7 @@ test.describe("?page=profile", () => { test("should show profile page if no accountId is passed", async ({ page, }) => { - const profileId = page.getByText("anybody.near").nth(2); + const profileId = page.getByText("saswat_test.testnet").nth(2); await expect(profileId).toBeVisible(); }); @@ -70,7 +70,7 @@ test.describe("?page=profile", () => { await page.getByPlaceholder("website link").fill("Someone.com"); const expectedResult = { - "anybody.near": { + "saswat_test.testnet": { profile: { name: "Someone", description: "Someone", From 7121948a1b5fa2591e18d352b45fe213677ec92d Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 <100185149+Megha-Dev-19@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:05:20 +0530 Subject: [PATCH 4/4] fix flakiness --- playwright-tests/tests/landing-page.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright-tests/tests/landing-page.spec.js b/playwright-tests/tests/landing-page.spec.js index e71bbdb0..080dd346 100644 --- a/playwright-tests/tests/landing-page.spec.js +++ b/playwright-tests/tests/landing-page.spec.js @@ -23,7 +23,7 @@ test.describe("Navbar tabs redirection", () => { await activityTab.click(); expect(page.url()).toContain("?page=activity"); await page.waitForTimeout(1000); - expect(page.getByText("All Feed", { exact: true })).toBeVisible(); + expect(page.getByText("All").nth(0)).toBeVisible(); }); test("Projects", async ({ page }) => { const projectsTab = page.getByRole("link", {