// Mocks the API via cy.intercept — this job doesn't run a live backend (see // .github/workflows/ci.yml); apps/api's own Mocha suite covers real API // behavior against a real database. // // The autosave journeys (regime, allergies) moved to preferences.feature — // this file now only covers the page's initial display. const authenticatedProfile = { id: 1, firstName: "Alice", lastName: "Martin", email: "alice@example.com", tokenVersion: 0, houseId: 1, dietId: 2, }; describe("Dietary preferences (/parametres/preferences) — hot saving", () => { beforeEach(() => { cy.intercept("GET", "**/auth/me", { statusCode: 200, body: authenticatedProfile }); cy.intercept("GET", "**/reference/diets", { statusCode: 200, body: [ { id: 1, key: "omnivore" }, { id: 2, key: "vegetarian" }, ], }); cy.intercept("GET", "**/reference/allergies", { statusCode: 200, body: [ { id: 1, key: "peanuts", kind: "ALLERGY" }, { id: 2, key: "gluten", kind: "INTOLERANCE" }, ], }); cy.intercept("GET", "**/profile/allergies", { statusCode: 200, body: [2] }); // The page also loads the reference ingredient list + the profile's // disliked-ingredients selection for `DislikedIngredientsField` — added // alongside `getDiets`/`getAllergies` in the same `Promise.all` (see // PreferencesPage.tsx), so both need mocking here too or that `Promise.all` // rejects and the whole page renders its error state instead of the form, // taking `#diet`/the allergy checkboxes down with it. cy.intercept("GET", "**/reference/ingredients", { statusCode: 200, body: [] }); cy.intercept("GET", "**/profile/disliked-ingredients", { statusCode: 200, body: [] }); }); it("loads the current regime, and shows allergies/intolerances as two groups", () => { cy.visit("/parametres/preferences"); cy.get("#diet").should("have.value", "2"); cy.contains("legend", "Allergies").should("be.visible"); cy.contains("legend", "Intolérances").should("be.visible"); cy.contains("label", "Gluten").find("input[type=checkbox]").should("be.checked"); cy.contains("label", "Arachides").find("input[type=checkbox]").should("not.be.checked"); }); it("has no explicit save button anywhere on the page", () => { cy.visit("/parametres/preferences"); cy.contains("button", "Enregistrer").should("not.exist"); }); });