Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add/update logic tests for auto-answers #2299

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { TYPES } from "@planx/components/types";

import { Store, vanillaStore } from "../store";

const { getState, setState } = vanillaStore;
const { upcomingCardIds, resetPreview, record, currentCard } = getState();

const flow: Store.flow = {
_root: {
edges: ["SetValue", "Content", "AutomatedQuestion"],
},
ResponseApple: {
data: {
val: "apple",
text: "Apple",
},
type: TYPES.Response,
},
ResponsePear: {
data: {
val: "pear",
text: "Pear",
},
type: TYPES.Response,
},
SetValue: {
data: {
fn: "fruit",
val: "apple",
},
type: TYPES.SetValue,
},
AutomatedQuestion: {
data: {
fn: "fruit",
text: "Which fruit?",
},
type: TYPES.Statement,
edges: ["ResponseApple", "ResponsePear"],
},
Content: {
data: {
content: "<p>Pause</p>",
},
type: TYPES.Content,
},
};

beforeEach(() => {
resetPreview();
setState({ flow });
});

test.skip("A question is auto-answered when it is reached, not when its' `fn` is first added to the breadcrumbs/passport", () => {
const visitedNodes = () => Object.keys(getState().breadcrumbs);

// mimic "Continue" button and properly set visitedNodes()
const clickContinue = () => upcomingCardIds();

expect(upcomingCardIds()).toEqual([
"SetValue",
"Content",
"AutomatedQuestion",
]);

// Step forwards through the SetValue
record("SetValue", { data: { fruit: ["apple"] }, auto: true });
clickContinue();

expect(currentCard()?.id).toBe("Content");

// "AutomatedQuestion" should still be queued up, not already answered based on SetValue
expect(visitedNodes()).not.toContain("AutomatedQuestion");
expect(upcomingCardIds()).toContain("AutomatedQuestion");

// Step forwards through Content
record("Content", { data: {}, auto: false });
clickContinue();

// "AutomatedQuestion" has now been auto-answered now, end of flow
expect(visitedNodes()).toContain("AutomatedQuestion");
expect(upcomingCardIds()).toEqual([]);
});
Loading