Skip to content

Commit

Permalink
autoAnswerableOptions test todos
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Oct 29, 2024
1 parent efe731d commit 570cb28
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import { Store, useStore } from "../../store";
const { getState, setState } = useStore;
const { resetPreview, autoAnswerableFlag } = getState();

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

// Additionally see src/pages/FlowEditor/lib/filters.test.ts for positive autoAnswerableFlag test cases !!
// 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", () => {
beforeEach(() => {
resetPreview();
});

test("If the node is not a Filter type", () => {
setState({ flow: {
setState({
flow: {
"_root": { "edges": ["SetValue"] },
"SetValue": { "type": 380, "data": { "fn": "projectType", "val": "alter", "operation": "replace" } },
}});
}
});

expect(autoAnswerableFlag("SetValue")).not.toBeDefined();
});
Expand All @@ -28,49 +30,49 @@ describe("Returns undefined and does not auto-answer any flag paths", () => {
});

test("If the node does not have any flag paths (aka options)");
const alteredFlow = structuredClone(flowWithFilter);
delete alteredFlow["Filter"].edges;
setState({ flow: alteredFlow });
const alteredFlow = structuredClone(flowWithFilter);
delete alteredFlow["Filter"].edges;
setState({ flow: alteredFlow });

expect(autoAnswerableFlag("Filter")).not.toBeDefined();
expect(autoAnswerableFlag("Filter")).not.toBeDefined();
});

const flowWithFilter: Store.Flow = {
"_root": {
"edges": [
"Filter"
]
"edges": [
"Filter"
]
},
"Filter": {
"type": 500,
"data": {
"fn": "flag",
"category": "Material change of use"
},
"edges": [
"Flag1",
"Flag2",
"Flag3"
]
"type": 500,
"data": {
"fn": "flag",
"category": "Material change of use"
},
"edges": [
"Flag1",
"Flag2",
"Flag3"
]
},
"Flag1": {
"type": 200,
"data": {
"text": "Material change of use",
"val": "MCOU_TRUE"
}
"type": 200,
"data": {
"text": "Material change of use",
"val": "MCOU_TRUE"
}
},
"Flag2": {
"type": 200,
"data": {
"text": "Not material change of use",
"val": "MCOU_FALSE"
}
"type": 200,
"data": {
"text": "Not material change of use",
"val": "MCOU_FALSE"
}
},
"Flag3": {
"type": 200,
"data": {
"text": "No flag result"
}
"type": 200,
"data": {
"text": "No flag result"
}
}
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { useStore } from "../../store";
import { Store, useStore } from "../../store";

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

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

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

describe("Returns undefined and does not auto-answer any options", () => {
beforeEach(() => {
resetPreview();
});

test("If the node is not a Question or Checklist type", () => {
setState({
flow: {
Expand All @@ -23,11 +24,30 @@ describe("Returns undefined and does not auto-answer any options", () => {
expect(autoAnswerableOptions("SetValue")).not.toBeDefined();
});

test.todo("If the node is a 'sticky note' Question without edges");
test("If the node is a 'sticky note' Question without edges", () => {
const alteredFlow = structuredClone(singleNodeFlow);
delete alteredFlow["Question"]?.edges;
setState({ flow: alteredFlow });

test.todo("If the node does not set a `fn`");
expect(autoAnswerableOptions("Question")).not.toBeDefined();
});

test("If the node does not set a `fn`", () => {
const alteredFlow = structuredClone(singleNodeFlow);
delete alteredFlow["Question"]?.data?.fn;
setState({ flow: alteredFlow });

test.todo("If we've never seen another node with this `fn` before");
expect(autoAnswerableOptions("Question")).not.toBeDefined();
});

test("If we've never seen another node with this `fn` before", () => {
setState({
flow: singleNodeFlow,
breadcrumbs: {}
});

expect(autoAnswerableOptions("Question")).not.toBeDefined();
});
});

describe("Questions", () => {
Expand All @@ -51,3 +71,37 @@ describe("Checklists", () => {

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

const singleNodeFlow: Store.Flow = {
"_root": {
"edges": [
"Question"
]
},
"Question": {
"type": 100,
"data": {
"fn": "direction",
"text": "Which direction?",
"forceSelection": false
},
"edges": [
"Option1",
"Option2"
]
},
"Option1": {
"type": 200,
"data": {
"text": "Left",
"val": "left"
}
},
"Option2": {
"type": 200,
"data": {
"text": "Right",
"val": "right"
}
}
};

0 comments on commit 570cb28

Please sign in to comment.