import { type DataTable, Given, Then, When } from "@badeball/cypress-cucumber-preprocessor"; Given("the current planning is empty", () => { cy.intercept("GET", /\/planning\?/, { statusCode: 200, body: null }).as("getPlanning"); }); Given("the current planning includes:", (dataTable: DataTable) => { const items = dataTable.hashes().map((row, index) => ({ id: index + 1, weekDay: row.day, meal: row.meal, recipe: { id: index + 1, name: row.recipe }, })); cy.intercept("GET", /\/planning\?/, { statusCode: 200, body: { id: 1, startDate: "2026-08-17T00:00:00.000Z", finishDate: "2026-08-23T00:00:00.000Z", items, }, }); }); Given("the current planning request fails", () => { cy.intercept("GET", /\/planning\?/, { statusCode: 500, body: { code: 5000, message: "boom" }, }); }); Then("the planning request should have been made for the week of {string}", (date: string) => { cy.wait("@getPlanning").its("request.url").should("include", `date=${date}`); }); Then("the grid should have {int} empty slots", (count: number) => { cy.get(".add-recipe-btn").should("have.length", count); }); Then("no recipe chips should be shown", () => { cy.get(".recipe-chip").should("not.exist"); }); Then("the day column {string} should be visible", (day: string) => { cy.contains("th", day).should("be.visible"); }); Then("the recipe chip {string} should be visible", (name: string) => { cy.contains(".recipe-chip", name).should("be.visible"); }); Then("today's column should show the date {string}", (day: string) => { cy.contains("th.today .day-date", day).should("be.visible"); }); When("I click the next week arrow", () => { cy.get(".week-nav__arrow").last().click(); }); When("I click the previous week arrow", () => { cy.get(".week-nav__arrow").first().click(); }); When("I open the week calendar", () => { cy.contains("button", "Semaine du").click(); }); Then("the calendar popover should be visible", () => { cy.get(".calendar-popover").should("be.visible"); }); Then("the calendar popover should be closed", () => { cy.get(".calendar-popover").should("not.exist"); }); When("I pick day {int} in the calendar", (day: number) => { cy.get(".calendar-grid__day") .contains(new RegExp(`^${day}$`)) .click(); }); Then("the nav link {string} should be active", (text: string) => { cy.contains("nav a", text).should("have.class", "active"); }); Then("the nav link {string} should not be active", (text: string) => { cy.contains("nav a", text).should("not.have.class", "active"); }); When("I click the nav link {string}", (text: string) => { cy.contains("nav a", text).click(); });