Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Oct 28, 2024
1 parent 7bba548 commit 9b522e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ beforeEach(() => {
resetPreview();
});

// Additionally see src/pages/FlowEditor/lib/filters.test.ts for positive autoAnswerableFlag test cases !!

describe("Returns undefined and does not auto-answer any flag paths", () => {
test("If the node is not a Filter type", () => {
setState({ flow: {
Expand All @@ -33,12 +35,6 @@ describe("Returns undefined and does not auto-answer any flag paths", () => {
expect(autoAnswerableFlag("Filter")).not.toBeDefined();
});

describe("Filters", () => {
test.todo("Auto-answer the single highest order flag path when many flags are collected");

test.todo("Auto-answer the blank path (no flag result) when no matching flags have been collected");
});

const flowWithFilter: Store.Flow = {
"_root": {
"edges": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ beforeEach(() => {
resetPreview();
});

// Find additional auto-answering tests at:
// - src/pages/FlowEditor/lib/automations.blanks.test.ts
// - src/pages/FlowEditor/lib/automations.parentChild.test.ts

describe("Returns undefined and does not auto-answer any options", () => {
test("If the node is not a Question or Checklist type", () => {
setState({
Expand All @@ -29,7 +33,7 @@ describe("Returns undefined and does not auto-answer any options", () => {
describe("Questions", () => {
test.todo("Auto-answer the option that exactly matches a passport value");

test.todo("Auto-answer the less granular option when there's a single more granular passport value");
test.todo("Auto-answer the less granular option when there's a single more granular passport value and no more granular options available");

test.todo("Auto-answer the single most granular, left-most option when there are many matching passport values");

Expand All @@ -41,13 +45,9 @@ describe("Questions", () => {
describe("Checklists", () => {
test.todo("Auto-answer all options that exactly match passport values");

test.todo("Auto-answer all less granular options when there are more granular passport values");
test.todo("Auto-answer all less granular options when there are more granular passport values and not more granular options available");

test.todo("Auto-answer through the blank path when we have seen thsi node `fn` but there are no matching passport values");
test.todo("Auto-answer through the blank path when we have seen this node `fn` but there are no matching passport values");

test.todo("Auto-answer through the blank path when we have not seen this node `fn` but we have seen all possible option `val`");
});

describe("Blanks and `_nots`", () => {
test.todo("TODO");
});
9 changes: 3 additions & 6 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,28 @@ import type {
GovUKPayment,
Node,
NodeId,
Value,
} from "@opensystemslab/planx-core/types";
import {
ComponentType as TYPES,
DEFAULT_FLAG_CATEGORY,
flatFlags,
ComponentType as TYPES,
} from "@opensystemslab/planx-core/types";
import { FileList } from "@planx/components/FileUploadAndLabel/model";
import { SetValue } from "@planx/components/SetValue/model";
import { handleSetValue } from "@planx/components/SetValue/utils";
import { sortIdsDepthFirst } from "@planx/graph";
import { logger } from "airbrake";
import { objectWithoutNullishValues } from "lib/objectHelpers";
import difference from "lodash/difference";
import flatten from "lodash/flatten";
import isEqual from "lodash/isEqual";
import omit from "lodash/omit";
import pick from "lodash/pick";
import uniq from "lodash/uniq";
import { v4 as uuidV4 } from "uuid";
import type { StateCreator } from "zustand";

import type { Store } from ".";
import type { Session } from "./../../../../types";
import { ApplicationPath } from "./../../../../types";
import type { Store } from ".";
import { NavigationStore } from "./navigation";
import type { SharedStore } from "./shared";

Expand Down Expand Up @@ -448,7 +445,7 @@ export const previewStore: StateCreator<
const { type, data, edges } = flow[id];

// Only Question & Checklist nodes that have an fn & edges are eligible for auto-answering
if (!type || ![TYPES.Question, TYPES.Checklist].includes(type) || !data?.fn || !edges) return;
if (!type || !SUPPORTED_DECISION_TYPES.includes(type) || !data?.fn || !edges) return;

// Only proceed if the user has seen at least one node with this fn before
const visitedFns = Object.entries(breadcrumbs).filter(([nodeId, _breadcrumb]) => flow[nodeId].data?.fn === data.fn);
Expand Down

0 comments on commit 9b522e6

Please sign in to comment.