Skip to content

Commit d67f6c7

Browse files
authored
Fix failing tests, add share post link tests (#455)
* fix failing tests, add share post link tests * fix tests * minor fixes * fix flakiness
1 parent 51e0291 commit d67f6c7

File tree

6 files changed

+60
-30
lines changed

6 files changed

+60
-30
lines changed

playwright-tests/tests/activity.spec.js

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { expect, test } from "@playwright/test";
22
import { ROOT_SRC } from "../util/constants";
33
import path from "path";
4+
45
const clickAndAssertTab = async (page, tabName, urlFragment, textToAssert) => {
56
await page.getByRole("button", { name: tabName }).click();
67
expect(page.url()).toContain(urlFragment);
78
await page.waitForTimeout(1000);
89
if (textToAssert) {
9-
expect(page.getByText(textToAssert, { exact: true })).toBeVisible();
10+
await expect(page.getByText(textToAssert).nth(0)).toBeVisible({
11+
timeout: 10000,
12+
});
1013
}
1114
};
1215

@@ -17,15 +20,15 @@ test.describe("All tabs must be visible and redirected to respective pages", ()
1720
});
1821

1922
test("All Feed", async ({ page }) => {
20-
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed");
23+
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All");
2124
});
2225

2326
test("Updates", async ({ page }) => {
2427
await clickAndAssertTab(
2528
page,
2629
"Updates",
2730
"?page=activity&tab=updates",
28-
"Updates Feed",
31+
"Updates",
2932
);
3033
});
3134

@@ -34,25 +37,20 @@ test.describe("All tabs must be visible and redirected to respective pages", ()
3437
page,
3538
"Question",
3639
"?page=activity&tab=question",
37-
"Question Feed",
40+
"Question",
3841
);
3942
});
4043

4144
test("Idea", async ({ page }) => {
42-
await clickAndAssertTab(
43-
page,
44-
"Idea",
45-
"?page=activity&tab=idea",
46-
"Idea Feed",
47-
);
45+
await clickAndAssertTab(page, "Idea", "?page=activity&tab=idea", "Idea");
4846
});
4947

5048
test("Feedback", async ({ page }) => {
5149
await clickAndAssertTab(
5250
page,
5351
"Feedback",
5452
"?page=activity&tab=feedback",
55-
"Feedback Feed",
53+
"Feedback",
5654
);
5755
});
5856

@@ -76,7 +74,7 @@ test.describe("All tabs must be visible and redirected to respective pages", ()
7674
page,
7775
"Request",
7876
"?page=activity&tab=request",
79-
"Request Feed",
77+
"Request",
8078
);
8179
});
8280

@@ -380,7 +378,6 @@ test.describe("User is logged in", () => {
380378
});
381379

382380
test("Edit a post and Save", async ({ page }) => {
383-
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed");
384381
await page.waitForTimeout(1000);
385382
const dropdown = page.locator(".bi.bi-three-dots-vertical").nth(1);
386383
await dropdown.click();
@@ -412,7 +409,6 @@ test.describe("User is logged in", () => {
412409
});
413410

414411
test("Bookmark a Post", async ({ page }) => {
415-
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed");
416412
await page.waitForTimeout(1000);
417413
const bookmarkIcon = await page.getByTitle("Bookmark").nth(1);
418414
await bookmarkIcon.click();
@@ -446,7 +442,6 @@ test.describe("User is logged in", () => {
446442
expect(transactionObj).toMatchObject(expectedTransactionData);
447443
});
448444
test("Like a Post", async ({ page }) => {
449-
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed");
450445
await page.waitForTimeout(1000);
451446
const likeIcon = await page.getByTitle("Like").nth(1);
452447
await page.waitForTimeout(1000);
@@ -471,7 +466,6 @@ test.describe("User is logged in", () => {
471466
expect(transactionObj).toMatchObject(expectedTransactionData);
472467
});
473468
test("Repost a Post", async ({ page }) => {
474-
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed");
475469
await page.waitForTimeout(1000);
476470
const repostIcon = await page.getByTitle("Repost").nth(1);
477471
await page.waitForTimeout(1000);
@@ -502,7 +496,6 @@ test.describe("User is logged in", () => {
502496
});
503497

504498
test("Comment on a post", async ({ page }) => {
505-
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed");
506499
await page.waitForTimeout(1000);
507500
const commentIcon = await page.getByTitle("Comment").nth(1);
508501
await page.waitForTimeout(1000);
@@ -533,8 +526,40 @@ test.describe("User is logged in", () => {
533526
};
534527
expect(transactionObj).toMatchObject(expectedTransactionData);
535528
});
529+
530+
test.describe("All tabs must be visible and redirected to respective pages", () => {
531+
test.beforeEach(async ({ page }) => {
532+
await page.waitForTimeout(1000);
533+
const shareBtn = await page.getByTitle("Share").nth(1);
534+
await shareBtn.click();
535+
});
536+
537+
test("should copy post link to clipboard", async ({ page }) => {
538+
await page.getByRole("button", { name: "Copy link to post" }).click();
539+
await page.waitForTimeout(1000);
540+
const handle = await page.evaluateHandle(() =>
541+
navigator.clipboard.readText(),
542+
);
543+
expect((await handle.jsonValue()).includes("MainPage.N.Post.Page"));
544+
});
545+
546+
test("should share post link via email", async ({ page }) => {
547+
await page.waitForTimeout(1000);
548+
// mailto opens email app, couldn't find a way to test opening of that app
549+
const emailLink = page.getByRole("link", { name: " Share by email" });
550+
await expect(emailLink).toHaveAttribute("href", /^mailto:/);
551+
});
552+
553+
test("should share post link via twitter", async ({ page }) => {
554+
const [newPage] = await Promise.all([
555+
page.waitForEvent("popup"),
556+
page.getByRole("link", { name: " Share on Twitter" }).click(),
557+
]);
558+
await newPage.waitForLoadState("domcontentloaded");
559+
expect(newPage.url()).toContain("https://x.com/intent");
560+
});
561+
});
536562
test("Convert post into proposal", async ({ page }) => {
537-
await clickAndAssertTab(page, "All", "?page=activity&tab=all", "All Feed");
538563
await page.waitForTimeout(1000);
539564
const dropdown = page.locator(".bi.bi-three-dots-vertical").nth(1);
540565
await dropdown.click();

playwright-tests/tests/auth.spec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ test.describe("User is logged in", () => {
3030
});
3131

3232
test("To verify that the user is logged in succesfully", async ({ page }) => {
33-
const LoggedInButton = page.getByRole("button", { name: "anybody.near" });
34-
await expect(LoggedInButton).toHaveText("anybody.near");
33+
const LoggedInButton = page.getByRole("button", {
34+
name: "saswat_test.testnet",
35+
});
36+
await expect(LoggedInButton).toHaveText("saswat_test.testnet");
3537
});
3638

3739
test("To verify that the sign out button is visible in the dropdown and when clicked navigates to logout page", async ({
3840
page,
3941
}) => {
40-
const LoggedInButton = page.getByRole("button", { name: "anybody.near" });
41-
await expect(LoggedInButton).toHaveText("anybody.near");
42+
const LoggedInButton = page.getByRole("button", {
43+
name: "saswat_test.testnet",
44+
});
45+
await expect(LoggedInButton).toHaveText("saswat_test.testnet");
4246
await LoggedInButton.click();
4347
const dropdownItems = await page.$$(".dropdown-item");
4448
const secondDropdownItem = dropdownItems[1];

playwright-tests/tests/editor.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ test.describe("?page=projects&tab=editor", () => {
105105
website: "https://www.samplewebsite.com",
106106
},
107107
// End remove
108-
contributors: ["anybody.near", "nobody.near"],
108+
contributors: ["saswat_test.testnet", "nobody.testnet"],
109109
tabs: ["overview", "tasks", "activity"],
110110
projectAccountId: "anyproject.near",
111111
teamSize: "1-10",
112112
location: "anywhere",
113113
};
114114

115115
const expectedTransactionData = {
116-
"anybody.near": {
116+
"saswat_test.testnet": {
117117
project: {
118118
"sample-project": {
119119
"": JSON.stringify(expectedProjectData),
@@ -140,7 +140,7 @@ test.describe("?page=projects&tab=editor", () => {
140140
},
141141
"builddao.testnet": {
142142
project: {
143-
"anybody.near_project_sample-project": "",
143+
"saswat_test.testnet_project_sample-project": "",
144144
},
145145
},
146146
},
@@ -184,8 +184,8 @@ test.describe("?page=projects&tab=editor", () => {
184184

185185
// Contributors
186186
await page.getByRole("combobox").nth(0).click();
187-
await page.getByRole("combobox").nth(0).fill("nobody.near");
188-
await page.getByLabel("nobody.near").click();
187+
await page.getByRole("combobox").nth(0).fill("nobody.testnet");
188+
await page.getByLabel("nobody.testnet").click();
189189

190190
await page.route("**/add", async (route) => {
191191
const modifiedResponse = {

playwright-tests/tests/landing-page.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test.describe("Navbar tabs redirection", () => {
2323
await activityTab.click();
2424
expect(page.url()).toContain("?page=activity");
2525
await page.waitForTimeout(1000);
26-
expect(page.getByText("All Feed", { exact: true })).toBeVisible();
26+
expect(page.getByText("All").nth(0)).toBeVisible();
2727
});
2828
test("Projects", async ({ page }) => {
2929
const projectsTab = page.getByRole("link", {

playwright-tests/tests/profile.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test.describe("?page=profile", () => {
1515
test("should show profile page if no accountId is passed", async ({
1616
page,
1717
}) => {
18-
const profileId = page.getByText("anybody.near").nth(2);
18+
const profileId = page.getByText("saswat_test.testnet").nth(2);
1919
await expect(profileId).toBeVisible();
2020
});
2121

@@ -70,7 +70,7 @@ test.describe("?page=profile", () => {
7070
await page.getByPlaceholder("website link").fill("Someone.com");
7171

7272
const expectedResult = {
73-
"anybody.near": {
73+
"saswat_test.testnet": {
7474
profile: {
7575
name: "Someone",
7676
description: "Someone",

playwright.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default defineConfig({
2727
reporter: "line",
2828
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2929
use: {
30+
permissions: ["clipboard-read"],
3031
video: "off",
3132
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
3233
actionTimeout: 0,

0 commit comments

Comments
 (0)