Skip to content

Commit

Permalink
chore: Run pnpm lint:fix in editor.planx.uk [skip pizza] (#2603)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Jan 2, 2024
1 parent d94c2c2 commit 9366de1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 128 deletions.
4 changes: 3 additions & 1 deletion editor.planx.uk/src/@planx/components/Calculate/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default function Component(props: Props) {
props.handleSubmit?.({
...makeData(
props,
props.formatOutputForAutomations ? [evaluatedResult.toString()] : evaluatedResult,
props.formatOutputForAutomations
? [evaluatedResult.toString()]
: evaluatedResult,
props.output,
),
// don't show this component to the user, auto=true required
Expand Down
203 changes: 84 additions & 119 deletions editor.planx.uk/src/@planx/components/Calculate/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,172 +14,137 @@ beforeEach(() => {
test("When formatOutputForAutomations is true, Calculate writes an array and future questions are auto-answered", () => {
// Setup
setState({ flow: flowWithAutomation });
expect(upcomingCardIds()).toEqual([
"Calculate",
"Question",
]);
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",
]);
expect(visitedNodes()).toEqual(["Calculate", "Question"]);

expect(upcomingCardIds()).toEqual([
"Group2Notice",
]);
expect(upcomingCardIds()).toEqual(["Group2Notice"]);
});

test("When formatOutputForAutomations is false, Calculate writes a number and future questions are not auto-answered", () => {
// Setup
setState({ flow: flowWithoutAutomation });
expect(upcomingCardIds()).toEqual([
"Calculate",
"Question",
]);
expect(upcomingCardIds()).toEqual(["Calculate", "Question"]);

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

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

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

const flowWithAutomation: Store.flow = {
"_root": {
"edges": [
"Calculate",
"Question"
]
_root: {
edges: ["Calculate", "Question"],
},
"Group2Notice": {
"data": {
"color": "#EFEFEF",
"title": "You are Group 2",
"resetButton": false
Group2Notice: {
data: {
color: "#EFEFEF",
title: "You are Group 2",
resetButton: false,
},
"type": TYPES.Notice
type: TYPES.Notice,
},
"Calculate": {
"data": {
"output": "testGroup",
"formula": "pickRandom([1,2])",
"formatOutputForAutomations": true
Calculate: {
data: {
output: "testGroup",
formula: "pickRandom([1,2])",
formatOutputForAutomations: true,
},
"type": TYPES.Calculate
type: TYPES.Calculate,
},
"Group1Notice": {
"data": {
"color": "#EFEFEF",
"title": "You are Group 1",
"resetButton": false
Group1Notice: {
data: {
color: "#EFEFEF",
title: "You are Group 1",
resetButton: false,
},
"type": TYPES.Notice
type: TYPES.Notice,
},
"Group1Response": {
"data": {
"val": "1",
"text": "1"
Group1Response: {
data: {
val: "1",
text: "1",
},
"type": TYPES.Response,
"edges": [
"Group1Notice"
]
type: TYPES.Response,
edges: ["Group1Notice"],
},
"Question": {
"data": {
"fn": "testGroup",
"text": "Which test group? "
Question: {
data: {
fn: "testGroup",
text: "Which test group? ",
},
"type": TYPES.Statement,
"edges": [
"Group1Response",
"Group2Response"
]
type: TYPES.Statement,
edges: ["Group1Response", "Group2Response"],
},
"Group2Response": {
"data": {
"val": "2",
"text": "2"
Group2Response: {
data: {
val: "2",
text: "2",
},
"type": TYPES.Response,
"edges": [
"Group2Notice"
]
}
type: TYPES.Response,
edges: ["Group2Notice"],
},
};

const flowWithoutAutomation: Store.flow = {
"_root": {
"edges": [
"Calculate",
"Question"
]
_root: {
edges: ["Calculate", "Question"],
},
"Group2Notice": {
"data": {
"color": "#EFEFEF",
"title": "You are Group 2",
"resetButton": false
Group2Notice: {
data: {
color: "#EFEFEF",
title: "You are Group 2",
resetButton: false,
},
"type": TYPES.Notice
type: TYPES.Notice,
},
"Calculate": {
"data": {
"output": "testGroup",
"formula": "pickRandom([1,2])",
"formatOutputForAutomations": false
Calculate: {
data: {
output: "testGroup",
formula: "pickRandom([1,2])",
formatOutputForAutomations: false,
},
"type": TYPES.Calculate
type: TYPES.Calculate,
},
"Group1Notice": {
"data": {
"color": "#EFEFEF",
"title": "You are Group 1",
"resetButton": false
Group1Notice: {
data: {
color: "#EFEFEF",
title: "You are Group 1",
resetButton: false,
},
"type": TYPES.Notice
type: TYPES.Notice,
},
"Group1Response": {
"data": {
"val": "1",
"text": "1"
Group1Response: {
data: {
val: "1",
text: "1",
},
"type": TYPES.Response,
"edges": [
"Group1Notice"
]
type: TYPES.Response,
edges: ["Group1Notice"],
},
"Question": {
"data": {
"fn": "testGroup",
"text": "Which test group? "
Question: {
data: {
fn: "testGroup",
text: "Which test group? ",
},
"type": TYPES.Statement,
"edges": [
"Group1Response",
"Group2Response"
]
type: TYPES.Statement,
edges: ["Group1Response", "Group2Response"],
},
"Group2Response": {
"data": {
"val": "2",
"text": "2"
Group2Response: {
data: {
val: "2",
text: "2",
},
"type": TYPES.Response,
"edges": [
"Group2Notice"
]
}
type: TYPES.Response,
edges: ["Group2Notice"],
},
};
16 changes: 8 additions & 8 deletions editor.planx.uk/src/lib/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ const errorLink = onError(({ graphQLErrors, operation }) => {
}
});

const handleHasuraGraphQLErrors = (errors: GraphQLErrors, operation: Operation) => {
const handleHasuraGraphQLErrors = (
errors: GraphQLErrors,
operation: Operation,
) => {
errors.forEach(({ message, locations, path }) => {
console.error(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
Expand All @@ -75,7 +78,6 @@ const handleHasuraGraphQLErrors = (errors: GraphQLErrors, operation: Operation)
});
};


const parseErrorTypeFromHasuraResponse = (message: string) => {
const permissionErrors = [
// Constraints error - user does not have access to this resource
Expand All @@ -84,15 +86,13 @@ const parseErrorTypeFromHasuraResponse = (message: string) => {
/not found in type/gi,
];

const validationErrors = [
/Invalid HTML content/gi
];

const validationErrors = [/Invalid HTML content/gi];

return {
permission: permissionErrors.some((re) => re.test(message)),
validation: validationErrors.some((re) => re.test(message)),
};
}
};

const handleValidationErrors = (operation: Operation) => {
const user = useStore.getState().getUser();
Expand All @@ -105,7 +105,7 @@ const handleValidationErrors = (operation: Operation) => {
hideProgressBar: true,
progress: undefined,
});
}
};

const handlePermissionErrors = (operation: Operation) => {
const user = useStore.getState().getUser();
Expand Down

0 comments on commit 9366de1

Please sign in to comment.