diff --git a/tests/mesocycles/edit.spec.ts b/tests/mesocycles/edit.spec.ts new file mode 100644 index 00000000..fbcfc52e --- /dev/null +++ b/tests/mesocycles/edit.spec.ts @@ -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); +});