Skip to content

Commit

Permalink
much more improved and consistent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Dec 24, 2023
1 parent d0a1a97 commit e2e821f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
5 changes: 3 additions & 2 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */
import { test as baseTest } from "@playwright/test";
import { test as baseTest, expect } from "@playwright/test";
import path from "path";
import dotenv from "dotenv";
dotenv.config();
Expand Down Expand Up @@ -31,7 +31,8 @@ export const test = baseTest.extend<{}, { workerStorageState: string }>({
]);
// Wait until the page receives the cookies.
// Reload to get user info
await page.reload();
await page.goto("localhost:4173/profile");
await expect(page.getByRole("main")).toContainText("Hello Test user");
// End of authentication steps.

await page.context().storageState({ path: fileName });
Expand Down
57 changes: 11 additions & 46 deletions tests/mesocycles/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,12 @@ test("should successfully create a mesocycle", async ({ page }) => {
);
await expect(page.getByTestId("exercise1-target-muscle-group")).toContainText("Chest");

// Copy from 1st Upper workout
// Copy from 1st Upper workout to 2nd Upper workout
await page.getByRole("button", { name: "Copy" }).click();
await page.getByLabel("Upper").nth(1).check();
await page.getByRole("button", { name: "Paste" }).click();
// Add 2nd exercise in 2nd Upper workout
await page.getByRole("button", { name: "+ Add exercise" }).click();
await page.getByLabel("Exercise name").fill("Upper Exercise 2");
await page.getByLabel("Target muscle").selectOption("Back");
await page.getByLabel("Sets").fill("4");
await page.getByPlaceholder("From").fill("10");
await page.getByPlaceholder("To").fill("15");
await page.getByPlaceholder("Note").click();
await page.getByPlaceholder("Note").fill("Upper 2 note");
await page.getByRole("button", { name: "Add exercise", exact: true }).click();

// Check entered details of 2nd exercise in UI
await expect(page.getByTestId("exercise2-note")).toContainText("Upper 2 note");
await expect(page.getByTestId("exercise2-name")).toContainText("Upper Exercise 2");
await expect(page.getByTestId("exercise2-sets-and-rep-range")).toContainText(
"4 sets of 10 to 15 reps"
);
await expect(page.getByTestId("exercise2-target-muscle-group")).toContainText("Back");

// Add 1st exercise
// Add 1st exercise to Lower1
await page.getByLabel("Lower").first().check();
await page.getByRole("button", { name: "+ Add exercise" }).click();
await page.getByLabel("Exercise name").fill("Lower Exercise 1");
Expand All @@ -83,35 +65,12 @@ test("should successfully create a mesocycle", async ({ page }) => {
await page.getByPlaceholder("To").fill("10");
await page.getByRole("button", { name: "Add exercise", exact: true }).click();

// Add 2nd exercise
await page.getByRole("button", { name: "+ Add exercise" }).click();
await page.getByLabel("Exercise name").fill("Lower Exercise 2");
await page.getByLabel("Target muscle").selectOption("Hamstrings");
await page.getByLabel("Sets").fill("2");
await page.getByPlaceholder("From").fill("10");
await page.getByPlaceholder("To").fill("20");
await page.getByRole("button", { name: "Add exercise", exact: true }).click();

// Throw error when submitting without having at least 1 exercise in each workout
await page.getByRole("button", { name: "Next" }).click();
await expect(page.locator("#Error")).toContainText(
"✕ Error Add at least one exercise in each workout. Missing in: Lower"
);
await page.locator("#Error").getByRole("button", { name: "✕" }).click();

// Copy from Lower1 to Lower2
await page.getByRole("button", { name: "Copy" }).click();
await page.getByLabel("Lower").nth(1).check();
await page.getByRole("button", { name: "Paste" }).click();
await page.getByRole("button", { name: "Next" }).click();

// Add 'Chest' specialization
await page.getByLabel("Mesocycle caloric state").selectOption("-1");
await page.getByLabel("Specialization").check();
await page.locator("#specialize-muscle-group").selectOption("Chest");
await page.getByRole("button", { name: "Add" }).click();
await expect(page.locator("#specialization-form")).toContainText("Chest");

// Create the mesocycle
await page.getByRole("button", { name: "Create mesocycle" }).click();
await expect(page.locator("#Success")).toContainText("✕ Success Mesocycle created successfully");
Expand All @@ -121,12 +80,13 @@ test("should successfully create a mesocycle", async ({ page }) => {
test("should show the created mesocycle", async ({ page }) => {
await page.getByTestId("mesocycle-card").filter({ hasText: randomMesocycleName }).click();

await expect(page.getByTestId("mesocycle-caloric-state")).toContainText("Hypo-caloric (Deficit)");
await expect(page.getByTestId("mesocycle-caloric-state")).toContainText(
"Iso-caloric (Maintenance)"
);
await expect(page.getByTestId("mesocycle-split")).toContainText(
"D1 Upper D2 Lower D3 Rest D4 Upper D5 Lower D6 Rest D7 Rest"
);

await expect(page.getByTestId("mesocycle-specializations")).toContainText("Chest");
await expect(page.getByTestId("mesocycle-start-RIR")).toContainText("2 RIR");
await expect(page.getByTestId("mesocycle-duration")).toContainText("12 cycles");
});
Expand All @@ -136,5 +96,10 @@ test("delete the created mesocycle", async ({ page }) => {
await page.getByRole("button", { name: "Delete", exact: true }).click();
await page.getByRole("button", { name: "Yes, delete" }).click();
await page.locator('[id="Deleted\\ successfully"]').getByTestId("close-modal-button").click();
await expect(page.getByRole("main")).toContainText("No mesocycle created");
});

test("check if mesocycle deleted", async ({ page }) => {
await expect(
page.getByTestId("mesocycle-card").filter({ hasText: randomMesocycleName })
).not.toBeVisible();
});
14 changes: 12 additions & 2 deletions tests/mesocycles/edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ test("create a sample mesocycle using API", async ({ page }) => {
headers: { "content-type": "application/json" }
});
expect(createTemplateResponse.ok()).toBe(true);
await page.reload();
});

test("check if sample mesocycle created", async ({ page }) => {
await expect(
page.getByTestId("mesocycle-card").filter({ hasText: mesocycleTemplate.name })
).toBeVisible();
});

test("edit the sample mesocycle", async ({ page }) => {
await page.getByTestId("mesocycle-card").filter({ hasText: mesocycleTemplate.name }).click();
await page.waitForURL(/viewTemplate/);

await page.getByRole("link", { name: "Edit" }).click();
await page.waitForURL(/editTemplate/);
await expect(page.locator("input[id='mesocycle-name']")).toHaveValue(mesocycleTemplate.name);
await expect(page.locator("input[id='mesocycle-duration']")).toHaveValue(
getTotalDuration(mesocycleTemplate.RIRProgression).toString()
Expand Down Expand Up @@ -78,5 +83,10 @@ test("delete the sample mesocycle", async ({ page }) => {
await page.getByRole("button", { name: "Delete", exact: true }).click();
await page.getByRole("button", { name: "Yes, delete" }).click();
await page.locator('[id="Deleted\\ successfully"]').getByTestId("close-modal-button").click();
await expect(page.getByRole("main")).toContainText("No mesocycle created");
});

test("check if sample mesocycle deleted", async ({ page }) => {
await expect(
page.getByTestId("mesocycle-card").filter({ hasText: editedMesocycleName })
).not.toBeVisible();
});

0 comments on commit e2e821f

Please sign in to comment.