Skip to content

Commit

Permalink
blanks and Calculate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Oct 28, 2024
1 parent 65d8375 commit 7bba548
Show file tree
Hide file tree
Showing 5 changed files with 513 additions and 24 deletions.
24 changes: 10 additions & 14 deletions editor.planx.uk/src/@planx/components/Calculate/logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { clickContinue, visitedNodes } from "pages/FlowEditor/lib/__tests__/utils";
import { Store, useStore } from "pages/FlowEditor/lib/store";

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

// Helper method
const visitedNodes = () => Object.keys(getState().breadcrumbs);
const { upcomingCardIds, resetPreview, autoAnswerableOptions } = getState();

beforeEach(() => {
resetPreview();
Expand All @@ -17,13 +15,12 @@ test("When formatOutputForAutomations is true, Calculate writes an array and fut
expect(upcomingCardIds()).toEqual(["Calculate", "Question"]);

// Step forwards through the Calculate
record("Calculate", { data: { testGroup: ["2"] }, auto: true });
upcomingCardIds();

// The Question has been auto-answered
expect(visitedNodes()).toEqual(["Calculate", "Question"]);
clickContinue("Calculate", { data: { testGroup: ["2"] }, auto: true });

expect(upcomingCardIds()).toEqual(["Group2Notice"]);
// The Question can be auto-answered
expect(visitedNodes()).toEqual(["Calculate"]);
expect(upcomingCardIds()).toEqual(["Question"])
expect(autoAnswerableOptions("Question")).toEqual(["Group2Response"]);
});

test("When formatOutputForAutomations is false, Calculate writes a number and future questions are not auto-answered", () => {
Expand All @@ -32,13 +29,12 @@ test("When formatOutputForAutomations is false, Calculate writes a number and fu
expect(upcomingCardIds()).toEqual(["Calculate", "Question"]);

// Step forwards through the Calculate
record("Calculate", { data: { testGroup: 2 }, auto: true });
upcomingCardIds();
clickContinue("Calculate", { data: { testGroup: 2 }, auto: true });

// The Question has NOT been auto-answered
// The Question cannot be auto-answered
expect(visitedNodes()).toEqual(["Calculate"]);

expect(upcomingCardIds()).toEqual(["Question"]);
expect(autoAnswerableOptions("Question")).toBeUndefined();
});

const flowWithAutomation: Store.Flow = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const QuestionComponent: React.FC<Question> = (props) => {
state.autoAnswerableOptions,
]);

console.log("HERE flow", props);

// Questions without edges act like "sticky notes" in the graph for editors only & can be immediately auto-answered
let edges: Edges | undefined;
if (props.id) edges = flow[props.id]?.edges
Expand Down
Loading

0 comments on commit 7bba548

Please sign in to comment.