// Mocks the API via cy.intercept — see auth.cy.ts for the rationale. const authenticatedProfile = { id: 1, firstName: "Alice", lastName: "Martin", email: "alice@example.com", tokenVersion: 0, houseId: 1, dietId: 2, }; describe("Household & profile settings (/foyer) — hot saving", () => { beforeEach(() => { cy.intercept("GET", "**/auth/me", { statusCode: 200, body: authenticatedProfile }); cy.intercept("GET", "**/house/current", { statusCode: 200, body: { id: 1, name: "Chez Alice" }, }); cy.intercept("GET", "**/reference/diets", { statusCode: 200, body: [ { id: 1, name: "Omnivore" }, { id: 2, name: "Végétarien" }, ], }); cy.intercept("GET", "**/reference/allergies", { statusCode: 200, body: [ { id: 1, name: "Arachides", kind: "ALLERGY" }, { id: 2, name: "Gluten", kind: "INTOLERANCE" }, ], }); cy.intercept("GET", "**/profile/allergies", { statusCode: 200, body: [2] }); }); it("loads the current household name, regime, and shows allergies/intolerances as two groups", () => { cy.visit("/foyer"); cy.get("#houseName").should("have.value", "Chez Alice"); 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("/foyer"); cy.contains("button", "Enregistrer").should("not.exist"); }); it("autosaves the household name a short pause after typing, no button click", () => { cy.intercept("PATCH", "**/house/current", { statusCode: 200, body: { id: 1, name: "Chez les Martin" }, }).as("renameHouse"); cy.visit("/foyer"); cy.get("#houseName").clear(); cy.get("#houseName").type("Chez les Martin"); cy.wait("@renameHouse").its("request.body").should("deep.equal", { name: "Chez les Martin" }); cy.contains("Enregistré ✓").should("be.visible"); }); it("does not autosave an empty household name — shows a validation message instead", () => { cy.intercept("PATCH", "**/house/current").as("renameHouse"); cy.visit("/foyer"); cy.get("#houseName").clear(); cy.contains("Le nom du foyer est requis").should("be.visible"); cy.get("@renameHouse.all").should("have.length", 0); }); it("autosaves the regime as soon as it's selected", () => { cy.intercept("PATCH", "**/profile/diet", { statusCode: 200, body: { ...authenticatedProfile, dietId: 1 }, }).as("updateDiet"); cy.visit("/foyer"); cy.get("#diet").select("Omnivore"); cy.wait("@updateDiet").its("request.body").should("deep.equal", { dietId: 1 }); }); it("autosaves allergies and intolerances together after checking boxes", () => { cy.intercept("PATCH", "**/profile/allergies", { statusCode: 200, body: [2, 1] }).as( "updateAllergies", ); cy.visit("/foyer"); cy.contains("label", "Arachides").find("input[type=checkbox]").check(); cy.wait("@updateAllergies") .its("request.body") .should("deep.equal", { allergyIds: [2, 1] }); }); });