Skip to content

Commit

Permalink
DME tests: Add abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-berman committed Sep 6, 2024
1 parent ce303b2 commit 271da78
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions test/dme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,10 @@ describe("DME tests", () => {
},
});

describe("system answer from beliefs", () => {
const runTest = (turns) => {
let expectedSoFar: Turn[] = [];
const actor = createActor(machine).start();
test.each([
{ speaker: "sys", message: "Hello! You can ask me anything!" },
{ speaker: "usr", message: "What's your favorite food?" },
{ speaker: "sys", message: "Pizza." },
])("$speaker> $message", async (turn) => {
test.each(turns)("$speaker> $message", async (turn) => {
expectedSoFar.push(turn);
if (turn.speaker === "usr") {
actor.send({ type: "INPUT", value: turn.message });
Expand All @@ -136,28 +132,21 @@ describe("DME tests", () => {
);
expect(snapshot.context.dialogue).toEqual(expectedSoFar);
});
};

describe("system answer from beliefs", () => {
runTest([
{ speaker: "sys", message: "Hello! You can ask me anything!" },
{ speaker: "usr", message: "What's your favorite food?" },
{ speaker: "sys", message: "Pizza." },
]);
});

describe("system question from plan", () => {
let expectedSoFar: Turn[] = [];
const actor = createActor(machine).start();
test.each([
runTest([
{ speaker: "sys", message: "Hello! You can ask me anything!" },
{ speaker: "usr", message: "Create an appointment" },
{ speaker: "sys", message: "Who are you meeting with?" },
])("$speaker> $message", async (turn) => {
expectedSoFar.push(turn);
if (turn.speaker === "usr") {
actor.send({ type: "INPUT", value: turn.message });
}
const snapshot = await waitFor(
actor,
(snapshot) => snapshot.context.dialogue.length === expectedSoFar.length,
{
timeout: 1000 /** allowed time to transition to the expected state */,
},
);
expect(snapshot.context.dialogue).toEqual(expectedSoFar);
});
]);
});
});

0 comments on commit 271da78

Please sign in to comment.