Skip to content

Commit

Permalink
Fix failing tests, add share post link tests (#455)
Browse files Browse the repository at this point in the history
* fix failing tests, add share post link tests

* fix tests

* minor fixes

* fix flakiness
  • Loading branch information
Megha-Dev-19 authored Jul 2, 2024
1 parent 51e0291 commit d67f6c7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 30 deletions.
61 changes: 43 additions & 18 deletions playwright-tests/tests/activity.spec.js
Original file line number Diff line number Diff line change
@@ -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,
});
}
};

Expand All @@ -17,15 +20,15 @@ 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 }) => {
await clickAndAssertTab(
page,
"Updates",
"?page=activity&tab=updates",
"Updates Feed",
"Updates",
);
});

Expand All @@ -34,25 +37,20 @@ 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 }) => {
await clickAndAssertTab(
page,
"Feedback",
"?page=activity&tab=feedback",
"Feedback Feed",
"Feedback",
);
});

Expand All @@ -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",
);
});

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -533,8 +526,40 @@ 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.waitForTimeout(1000);
// 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("link", { name: " Share on 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();
Expand Down
12 changes: 8 additions & 4 deletions playwright-tests/tests/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
10 changes: 5 additions & 5 deletions playwright-tests/tests/editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ 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",
location: "anywhere",
};

const expectedTransactionData = {
"anybody.near": {
"saswat_test.testnet": {
project: {
"sample-project": {
"": JSON.stringify(expectedProjectData),
Expand All @@ -140,7 +140,7 @@ test.describe("?page=projects&tab=editor", () => {
},
"builddao.testnet": {
project: {
"anybody.near_project_sample-project": "",
"saswat_test.testnet_project_sample-project": "",
},
},
},
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion playwright-tests/tests/landing-page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
4 changes: 2 additions & 2 deletions playwright-tests/tests/profile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d67f6c7

Please sign in to comment.