Skip to content

Commit

Permalink
added an edit mesocycle test
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Dec 22, 2023
1 parent 8ffa0ed commit 94e2b99
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/mesocycles/edit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { randomUUID } from "crypto";
import { test, expect } from "../fixtures";
import { getTotalDuration } from "$lib/util/MesocycleTemplate";

test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:4173/mesocycles");
});

const mesocycleTemplate: MesocycleTemplate = {
name: randomUUID(),
caloricBalance: 0,
startRIR: 3,
RIRProgression: [
{ specificRIR: 3, cycles: 4 },
{ specificRIR: 2, cycles: 3 },
{ specificRIR: 1, cycles: 2 },
{ specificRIR: 0, cycles: 1 }
],
exerciseSplit: [
{
name: "Upper",
exercises: [
{
name: "Upper exercise 1",
sets: 3,
targetMuscleGroup: "Chest",
repRangeStart: 10,
repRangeEnd: 20,
weightType: "Weighted"
}
]
},
null
]
};

test("create a sample mesocycle using API", async ({ page }) => {
const createTemplateResponse = await page.request.post("/api/mesocycles/createTemplate", {
data: { mesocycleTemplate },
headers: { "content-type": "application/json" }
});
expect(createTemplateResponse.ok()).toBe(true);
});

test("edit the sample mesocycle", async ({ page }) => {
await page.goto("/mesocycles");
await expect(page.getByRole("main")).toContainText(mesocycleTemplate.name);
await page.getByRole("link", { name: mesocycleTemplate.name }).click();

await page.getByRole("link", { name: "Edit" }).click();
await expect(page.locator("input[id='mesocycle-name']")).toHaveValue(mesocycleTemplate.name);
await expect(page.locator("input[id='mesocycle-duration']")).toHaveValue(
getTotalDuration(mesocycleTemplate.RIRProgression).toString()
);

const newMesocycleName = randomUUID();
await page.locator("input[id='mesocycle-name']").fill(newMesocycleName);
await page.getByRole("button", { name: "Next" }).click();
await page.getByRole("button", { name: "Next" }).click();
await page.getByRole("button", { name: "Next" }).click();
await page.getByRole("button", { name: "Update mesocycle" }).click();
await page.locator("#Success").getByTestId("close-modal-button").click();

await expect(page.getByRole("main")).not.toContainText(mesocycleTemplate.name);
await expect(page.getByRole("main")).toContainText(newMesocycleName);
});

0 comments on commit 94e2b99

Please sign in to comment.