- household.cy.ts scindé en preferences.cy.ts (régime/allergies) et household-settings.cy.ts (nom, créer/rejoindre/membres/suppression/ quitter, avec et sans droits admin) - onboarding.cy.ts réordonné (régime → foyer → allergènes), avec les cas skip / créer / rejoindre à l'étape foyer - account.cy.ts: identité, suppression de compte (erreur de mot de passe, succès, annulation) - sidebar.cy.ts: menu Paramètres (3 liens) et menu compte (Mon compte, déconnexion), redirection /foyer → /parametres/foyer - auth.cy.ts/home-planning.cy.ts: adaptés au nouveau menu compte et au premier écran d'onboarding (régime, plus foyer)
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
// 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("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, 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 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");
|
|
});
|
|
|
|
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("/parametres/preferences");
|
|
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("/parametres/preferences");
|
|
cy.contains("label", "Arachides").find("input[type=checkbox]").check();
|
|
|
|
cy.wait("@updateAllergies")
|
|
.its("request.body")
|
|
.should("deep.equal", { allergyIds: [2, 1] });
|
|
cy.contains("Enregistré ✓").should("be.visible");
|
|
});
|
|
});
|