- user-preferences.cy.ts: défaut SYSTEM, thème sauvegardé restitué et appliqué au document, autosave sans bouton "Enregistrer" - sidebar.cy.ts: 4 pages de paramètres (libellé "Préférences alimentaires" renommé + nouvelle entrée "Préférences utilisateur") - auth.cy.ts/onboarding.cy.ts: corrige un intercept **/planning/current périmé (route supprimée dans la PR précédente) — masqué jusqu'ici car aucune assertion n'en dépendait directement, mais provoquait un appel réseau non mocké
54 lines
2.1 KiB
TypeScript
54 lines
2.1 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: null,
|
|
dietId: null,
|
|
};
|
|
|
|
describe("User preferences (/parametres/preferences-utilisateur)", () => {
|
|
beforeEach(() => {
|
|
cy.intercept("GET", "**/auth/me", { statusCode: 200, body: authenticatedProfile });
|
|
});
|
|
|
|
it("shows SYSTEM selected by default", () => {
|
|
cy.intercept("GET", "**/preferences", { statusCode: 200, body: { theme: "SYSTEM" } });
|
|
|
|
cy.visit("/parametres/preferences-utilisateur");
|
|
|
|
cy.contains("label", "Système").find("input[type=radio]").should("be.checked");
|
|
cy.contains("label", "Clair").find("input[type=radio]").should("not.be.checked");
|
|
cy.contains("label", "Sombre").find("input[type=radio]").should("not.be.checked");
|
|
// SYSTEM never sets an override — the OS/browser preference decides.
|
|
cy.get("html").should("not.have.attr", "data-theme");
|
|
});
|
|
|
|
it("shows the previously saved theme selected, and applies it to the document", () => {
|
|
cy.intercept("GET", "**/preferences", { statusCode: 200, body: { theme: "DARK" } });
|
|
|
|
cy.visit("/parametres/preferences-utilisateur");
|
|
|
|
cy.contains("label", "Sombre").find("input[type=radio]").should("be.checked");
|
|
cy.get("html").should("have.attr", "data-theme", "dark");
|
|
});
|
|
|
|
it("switching theme autosaves and applies immediately, no explicit save button", () => {
|
|
cy.intercept("GET", "**/preferences", { statusCode: 200, body: { theme: "SYSTEM" } });
|
|
cy.intercept("PATCH", "**/preferences", { statusCode: 200, body: { theme: "LIGHT" } }).as(
|
|
"updatePreferences",
|
|
);
|
|
|
|
cy.visit("/parametres/preferences-utilisateur");
|
|
cy.contains("button", "Enregistrer").should("not.exist");
|
|
|
|
cy.contains("label", "Clair").click();
|
|
|
|
cy.wait("@updatePreferences").its("request.body").should("deep.equal", { theme: "LIGHT" });
|
|
cy.contains("Enregistré ✓").should("be.visible");
|
|
cy.get("html").should("have.attr", "data-theme", "light");
|
|
});
|
|
});
|