Text Share Online

import { When, Then } from “@badeball/cypress-cucumber-preprocessor”;
import ChatWidget from “../pages/ChatWidget.js”;

let lastExpectedPattern = null;

When(“I converse using prompt {string}”, (promptName) => {
cy.fixture(“prompts.json”).then((prompts) => {
constdata=prompts[promptName];
if (!data) thrownewError(`Prompt not found: “${promptName}”`);

lastExpectedPattern=newRegExp(data.expect, “i”);

// ⬇️ Decide how to drive the conversation
constmode= (data.sendVia||”text”).toLowerCase();
if (mode===”chip”) {
ChatWidget.chooseQuickOption(data.utterance);
} else {
ChatWidget.sendMessage(data.utterance);
}
});
});

Then(“the bot should match the expected pattern”, () => {
if (!lastExpectedPattern) {
thrownewError(
‘No expected pattern set. Call: When I converse using prompt “<name>” first.’
);
}
ChatWidget.expectBotResponse(lastExpectedPattern);
});
Share This: