From c358394503d877df9e04d6ca230b8abb16f418e0 Mon Sep 17 00:00:00 2001 From: Vinay Badgujar Date: Sat, 5 Oct 2024 15:22:30 +0530 Subject: [PATCH] edit: create new goal and share that goal in test --- .../goal-collaboration-feature.spec.ts | 24 ++++++--- .../utils/collaboration-feature-utils.ts | 53 +++++++++++++------ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/playwright/tests/collaboration-feature/goal-collaboration-feature.spec.ts b/playwright/tests/collaboration-feature/goal-collaboration-feature.spec.ts index f0371885e..d8a44d4d5 100644 --- a/playwright/tests/collaboration-feature/goal-collaboration-feature.spec.ts +++ b/playwright/tests/collaboration-feature/goal-collaboration-feature.spec.ts @@ -19,7 +19,7 @@ test.describe("Goal Sharing Feature", () => { let userBPage: Page; let userCPage: Page; let invitationLink: string; - let currentGoalTitle: string; + let currentGoalTitle = "Test Goal"; test.beforeAll(async ({ browser }) => { ({ page: userAPage } = await createUserContextAndPage(browser)); @@ -36,6 +36,12 @@ test.describe("Goal Sharing Feature", () => { await userCPage.getByRole("button", { name: "Continue zinzen faq" }).click(); }); + test.afterAll(async () => { + await userAPage.close(); + await userBPage.close(); + await userCPage.close(); + }); + const userCollaborationScenarios = [ { sharer: "A", receiver: "B", sharerPage: () => userAPage, receiverPage: () => userBPage }, { sharer: "B", receiver: "C", sharerPage: () => userBPage, receiverPage: () => userCPage }, @@ -71,10 +77,16 @@ test.describe("Goal Sharing Feature", () => { userCollaborationScenarios.forEach(({ sharer, receiver, sharerPage, receiverPage }) => { test(`from User ${sharer} share invitation to User ${receiver}`, async () => { await goToMyGoalsPageFlow(sharerPage()); - currentGoalTitle = await sharerPage().locator(".goal-title").first().locator("span").innerText(); - invitationLink = await addContact(sharerPage(), receiver, "relId", "relationshipId"); + if (sharer === "A") { + await sharerPage().getByRole("button", { name: "add goal | add feeling | add group", exact: true }).click({}); + + const titleInputContainer = sharerPage().getByPlaceholder("Goal title"); + await titleInputContainer.fill(currentGoalTitle); + await titleInputContainer.press("Enter"); + } + invitationLink = await addContact(sharerPage(), receiver, currentGoalTitle, "relId", "relationshipId"); await goToMyGoalsPageFlow(sharerPage()); - await goToShareGoalModalFlow(sharerPage()); + await goToShareGoalModalFlow(sharerPage(), currentGoalTitle); }); test(`from User ${receiver} accept invitation of User ${sharer}`, async () => { @@ -96,7 +108,7 @@ test.describe("Goal Sharing Feature", () => { }); test(`initiate collaboration between User ${sharer} and User ${receiver}`, async () => { - await collaborateFlow(receiverPage()); + await collaborateFlow(receiverPage(), currentGoalTitle); }); test(`check if collaborated goal is visible in User ${receiver}'s MyGoal`, async () => { @@ -110,7 +122,7 @@ test.describe("Goal Sharing Feature", () => { ({ sharer, receiverFirst, receiverSecond, sharerPage, receiverPageFirst, receiverPageSecond }) => { test(`goal update by ${sharer}: edit goal in User ${sharer}`, async () => { await goToMyGoalsPageFlow(sharerPage()); - await goalActionFlow(sharerPage(), "Edit"); + await goalActionFlow(sharerPage(), "Edit", currentGoalTitle); await sharerPage().locator(".header-title").locator("input").fill(`${currentGoalTitle} edited by ${sharer}`); await sharerPage().locator(".action-btn-container").locator(".action-btn").click(); currentGoalTitle = await sharerPage().locator(".goal-title").first().locator("span").innerText(); diff --git a/playwright/utils/collaboration-feature-utils.ts b/playwright/utils/collaboration-feature-utils.ts index 2fbcce310..af395c99f 100644 --- a/playwright/utils/collaboration-feature-utils.ts +++ b/playwright/utils/collaboration-feature-utils.ts @@ -6,8 +6,21 @@ export async function createUserContextAndPage(browser: Browser) { return { context, page }; } -export async function goalActionFlow(page: Page, action: string) { - await page.locator(".goal-dd-outer").first().click(); +export async function goalActionFlow(page: Page, action: string, goalTitle: string) { + const goalDiv = await page.locator(".user-goal-main").filter({ hasText: new RegExp(`^${goalTitle}$`) }); + console.log(goalDiv); + + // Find the .goal-dd-outer associated with the goal title 'Test Goal' + const goalDropdown = await page + .locator(".user-goal-main") + .filter({ + has: page.locator('.goal-title:has-text("Test Goal")'), + }) + .locator(".goal-dd-outer"); + + // Click the specific .goal-dd-outer + await goalDropdown.click(); + await page .locator("div") .filter({ hasText: new RegExp(`^${action}$`) }) @@ -15,44 +28,53 @@ export async function goalActionFlow(page: Page, action: string) { .click({ force: true }); } -export async function goToShareGoalModalFlow(page: Page) { - await goalActionFlow(page, "Share"); +export async function goToShareGoalModalFlow(page: Page, goalTitle: string) { + await goalActionFlow(page, "Share", goalTitle); } export async function waitForResponseConfirmation( page: Page, urlContains: string, maxRetries: number = 3, - retryDelay: number = 3000, + retryDelay: number = 2000, ): Promise { + let response; for (let attempt = 1; attempt <= maxRetries; attempt++) { try { if (attempt > 1) { - await page.reload(); + page.reload(); } - const response = await page.waitForResponse((res) => res.url().includes(urlContains) && res.status() === 200); + response = await page.waitForResponse((res) => res.url().includes(urlContains) && res.status() === 200, { + timeout: 5000, + }); console.log(`Success on attempt ${attempt}`); - console.log(`Response: ${JSON.stringify(response)}`); - return; + const responseBody = await response.text(); + console.log(`Response status: ${response.status()}`); + console.log(`Response body: ${responseBody}`); + + return; // Exit after success } catch (error) { + console.warn(`Attempt ${attempt} failed. Retrying in ${retryDelay}ms...`); if (attempt === maxRetries) { - console.error(`All ${maxRetries} attempts failed. Last error: ${error.message}`); - throw new Error(`Failed to get response confirmation after ${maxRetries} attempts: ${error.message}`); + console.error(`Failed after ${maxRetries} attempts. Last error: ${error.message}`); + throw new Error(`Failed to get response confirmation: ${error.message}`); } - console.warn(`Attempt ${attempt} failed. Retrying in ${retryDelay}ms...`); + await page.waitForTimeout(retryDelay); } } } + export async function addContact( page: Page, contactName: string, + goalTitle: string, expectedApiResponse1: string, expectedApiResponse2: string, ): Promise { const apiServerUrl = "https://sfk3sq5mfzgfjfy3hytp4tmon40bbjpu.lambda-url.eu-west-1.on.aws/"; - await goToShareGoalModalFlow(page); + await goToShareGoalModalFlow(page, goalTitle); // Add contact flow await page.getByRole("button", { name: "add contact", exact: true }).click(); @@ -67,8 +89,8 @@ export async function addContact( return page.evaluate("navigator.clipboard.readText()"); } -export async function collaborateFlow(page: Page) { - await goalActionFlow(page, "Collaborate"); +export async function collaborateFlow(page: Page, goalTitle: string) { + await goalActionFlow(page, "Collaborate", goalTitle); await page.getByRole("button", { name: "Collaborate on goal" }).click(); } @@ -97,7 +119,6 @@ export async function verifyUpdatedGoal( await Promise.all([ page.waitForResponse((res) => res.status() === 200 && res.url().includes(apiUrlGoal), { timeout: 10000 }), ]); - await page.getByRole("button", { name: "Goals" }).click(); await page.locator(".goal-dd-outer").first().click();