Skip to content

Commit

Permalink
edit: create new goal and share that goal in test
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Oct 5, 2024
1 parent e18f286 commit c358394
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 },
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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();
Expand Down
53 changes: 37 additions & 16 deletions playwright/utils/collaboration-feature-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,75 @@ 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}$`) })
.first()
.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<void> {
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<string> {
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();
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit c358394

Please sign in to comment.