import { Given, Then, When } from "@badeball/cypress-cucumber-preprocessor"; // Guided-tour steps (issue #42). Mocks the API via `cy.intercept`, like the // rest of the suite. `I am signed in as` / `the planning request returns // nothing` / `I visit` come from the shared common.steps.ts. const GENERAL_STEPS = [ { order: 0, route: "/", targetKey: "nav-planning", title: "Votre semaine, ici", content: "..." }, { order: 1, route: null, targetKey: "nav-recipes", title: "Vos recettes", content: "..." }, { order: 2, route: null, targetKey: "nav-shopping-list", title: "La liste de courses", content: "...", }, ]; function interceptTours(steps: typeof GENERAL_STEPS) { cy.intercept("GET", "**/reference/tours", { statusCode: 200, body: [{ key: "general", name: "Tour d'orientation", steps }], }); } Given("the guided tour has not been seen yet", () => { interceptTours(GENERAL_STEPS); cy.intercept("GET", "**/profile/tours", { statusCode: 200, body: { completedTourKeys: [] } }); cy.intercept("POST", "**/profile/tours/general/complete", { statusCode: 204 }).as("complete"); }); Given("the guided tour has not been seen yet, with a single step", () => { interceptTours([GENERAL_STEPS[0]]); cy.intercept("GET", "**/profile/tours", { statusCode: 200, body: { completedTourKeys: [] } }); cy.intercept("POST", "**/profile/tours/general/complete", { statusCode: 204 }).as("complete"); }); Given("the guided tour has already been seen", () => { interceptTours(GENERAL_STEPS); cy.intercept("GET", "**/profile/tours", { statusCode: 200, body: { completedTourKeys: ["general"] }, }); cy.intercept("POST", "**/profile/tours/general/complete", { statusCode: 204 }).as("complete"); }); Then("the tour popover shows {string}", (title: string) => { cy.get(".driver-popover.tour-popover .driver-popover-title").should("contain.text", title); }); Then("the sidebar {string} link is highlighted by the tour", (label: string) => { cy.contains(".app-sidebar__nav a", label).should("have.class", "driver-active-element"); }); When("I click the tour's next button", () => { cy.get(".driver-popover.tour-popover .driver-popover-next-btn").click(); }); When("I dismiss the tour", () => { cy.get(".driver-popover.tour-popover .driver-popover-close-btn").click(); }); Then("the tour completion was recorded as finished", () => { cy.wait("@complete").its("request.body").should("deep.equal", { skipped: false }); }); Then("the tour completion was recorded as skipped", () => { cy.wait("@complete").its("request.body").should("deep.equal", { skipped: true }); }); Then("no tour popover is shown", () => { // Give the auto-trigger effect a chance to (not) fire. cy.wait(300); cy.get(".driver-popover").should("not.exist"); }); When("I click {string} next to {string}", (button: string, tourName: string) => { cy.contains(".tour-replay-list__item", tourName).contains("button", button).click(); });