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

fix: eslint errors from auto-answering changes #3874

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
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
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"
]
}
]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is consistent with our API's eslintrc too

},
"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
Loading