import { Given, Then } from "@badeball/cypress-cucumber-preprocessor"; // The page also loads the reference ingredient list + the profile's // disliked-ingredients selection for `DislikedIngredientsField` — added // alongside diets/allergies 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. Given("the dietary preferences reference data is ready", () => { 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] }); cy.intercept("GET", "**/reference/ingredients", { statusCode: 200, body: [] }); cy.intercept("GET", "**/profile/disliked-ingredients", { statusCode: 200, body: [] }); }); // Selecting the diet, updating allergies, and asserting on the diet update // request are shared with onboarding.feature's regime/allergies steps — see // cypress/support/step_definitions/profile-mutations.steps.ts. Then( "the allergies update request should have been made with allergy ids {int} and {int}", (first: number, second: number) => { cy.wait("@updateAllergies") .its("request.body") .should("deep.equal", { allergyIds: [first, second] }); }, );