Skip to content

Commit

Permalink
fix: eslint errors from auto-answering changes (#3874)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Oct 29, 2024
1 parent 815dc27 commit 2cdd1c9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
10 changes: 9 additions & 1 deletion editor.planx.uk/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@
}
}
],
"no-nested-ternary": "error"
"no-nested-ternary": "error",
"@vitest/expect-expect": [
"error",
{
"assertFunctionNames": [
"expect"
]
}
]
},
"overrides": [
{
Expand Down
8 changes: 4 additions & 4 deletions editor.planx.uk/src/@planx/components/Checklist/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ function toggleInArray<T>(value: T, arr: Array<T>): Array<T> {
}

const ChecklistComponent: React.FC<Props> = (props) => {
if (props.neverAutoAnswer) {
return <VisibleChecklist {...props} />;
}

const autoAnswerableOptions = useStore(
(state) => state.autoAnswerableOptions,
);

if (props.neverAutoAnswer) {
return <VisibleChecklist {...props} />;
}

let idsThatCanBeAutoAnswered: string[] | undefined;
if (props.id) idsThatCanBeAutoAnswered = autoAnswerableOptions(props.id);
if (idsThatCanBeAutoAnswered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export enum QuestionLayout {
}

const QuestionComponent: React.FC<Question> = (props) => {
if (props.neverAutoAnswer) {
return <VisibleQuestion {...props} />;
}

const [flow, autoAnswerableOptions] = useStore((state) => [
state.flow,
state.autoAnswerableOptions,
]);

if (props.neverAutoAnswer) {
return <VisibleQuestion {...props} />;
}

// Questions without edges act like "sticky notes" in the graph for editors only & can be immediately auto-answered
let edges: Edges | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("Auto-answering blanks", () => {

// The second blank is put to the user because we do not have a passport value and we have NOT seen all options before
expect(computePassport()?.data).not.toHaveProperty("option");
expect(autoAnswerableOptions("Path2Checklist2")).toBeUndefined;
expect(autoAnswerableOptions("Path2Checklist2")).toBeUndefined();
});

test("Questions with the same options auto-answer the blank", () => {
Expand Down Expand Up @@ -63,7 +63,7 @@ describe("Auto-answering blanks", () => {

// The second blank is put to the user because we do not have a passport value and we have NOT seen all options before
expect(computePassport()?.data).not.toHaveProperty("option");
expect(autoAnswerableOptions("Path4Question2")).toBeUndefined;
expect(autoAnswerableOptions("Path4Question2")).toBeUndefined();

// Manually proceed through the second blank
clickContinue("Path4Question2", { answers: ["Path4Question2Blank"], auto: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ describe("Returns undefined and does not auto-answer any flag paths", () => {
}
});

expect(autoAnswerableFlag("SetValue")).not.toBeDefined();
expect(autoAnswerableFlag("SetValue")).toBeUndefined();
});

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

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

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

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

expect(autoAnswerableFlag("Filter")).toBeUndefined();
});
});

const flowWithFilter: Store.Flow = {
Expand Down
4 changes: 2 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export const previewStore: StateCreator<
let optionsThatCanBeAutoAnswered: Array<NodeId> = [];

// Get existing passport value(s) for this node's fn
let passportValues = passportData?.[data.fn];
const passportValues = passportData?.[data.fn];

// If we have existing passport value(s) for this fn in an eligible automation format (eg not numbers or plain strings),
// then proceed through the matching option(s) or the blank option independent if other vals have been seen before
Expand Down Expand Up @@ -549,7 +549,7 @@ export const previewStore: StateCreator<
id: edgeId,
...flow[edgeId],
}));
let optionsThatCanBeAutoAnswered: Array<NodeId> = [];
const optionsThatCanBeAutoAnswered: Array<NodeId> = [];

// "New" Filters will have a category prop, but existing ones may still be relying on DEFAULT category
const filterCategory = data?.category || DEFAULT_FLAG_CATEGORY;
Expand Down

0 comments on commit 2cdd1c9

Please sign in to comment.