-
Notifications
You must be signed in to change notification settings - Fork 2
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
chore: bump planx-core (multiple schemas support) #4206
Changes from 9 commits
5cf941f
74f0b56
e12e1d4
106e1ac
f46a554
6397ae0
f1096bd
9bc22e2
9824f18
cc34927
be3f026
13f8e9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import type { FlowGraph } from "@opensystemslab/planx-core/types"; | ||
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types"; | ||
|
||
import { hasComponentType, numberOfComponentType } from "./helpers.js"; | ||
|
||
describe("hasComponentType", () => { | ||
test("it returns true for a component type that is present", () => { | ||
expect(hasComponentType(flow, TYPES.Question)).toEqual(true); | ||
}); | ||
|
||
test("it returns false for a component type that is not present", () => { | ||
expect(hasComponentType(flow, TYPES.DrawBoundary)).toEqual(false); | ||
}); | ||
|
||
test("it returns true for a component type that is present and has the specified data field as a `val` prop", () => { | ||
expect(hasComponentType(flow, TYPES.Answer, "residential.flat")).toEqual( | ||
true, | ||
); | ||
}); | ||
|
||
test("it returns true for a component type that is present and has the specified data field as a `fn` prop", () => { | ||
expect(hasComponentType(flow, TYPES.Question, "property.type")).toEqual( | ||
true, | ||
); | ||
}); | ||
|
||
test("it returns false for a component type that is present but does not have the specified data field", () => { | ||
expect(hasComponentType(flow, TYPES.Question, "application.type")).toEqual( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
describe("numberOfComponentType", () => { | ||
test("it returns the correct count of nested component types", () => { | ||
expect(numberOfComponentType(flow, TYPES.Answer)).toEqual(5); | ||
}); | ||
|
||
test("it returns the correct count of component types with a specified data field as a `fn` prop", () => { | ||
expect( | ||
numberOfComponentType(flow, TYPES.Question, "property.type"), | ||
).toEqual(2); | ||
}); | ||
|
||
test("it returns the correct count of component types with a specified data field as a `val` prop", () => { | ||
expect(numberOfComponentType(flow, TYPES.Answer, "residential")).toEqual(1); | ||
}); | ||
|
||
test("it returns 0 for a component type that is not present", () => { | ||
expect(numberOfComponentType(flow, TYPES.Calculate)).toEqual(0); | ||
}); | ||
|
||
test("it returns 0 for a component type that is present but does not have the specified data field", () => { | ||
expect( | ||
numberOfComponentType(flow, TYPES.Question, "application.type"), | ||
).toEqual(0); | ||
}); | ||
}); | ||
|
||
const flow: FlowGraph = { | ||
_root: { | ||
edges: ["FindProperty", "QuestionOne", "Result", "Notice"], | ||
}, | ||
"4jSYMB7hBJ": { | ||
data: { | ||
val: "residential.house", | ||
text: "House", | ||
flags: ["flag.pp.permittedDevelopment"], | ||
}, | ||
type: TYPES.Answer, | ||
}, | ||
FindProperty: { | ||
data: { | ||
title: "Find the property", | ||
newAddressTitle: | ||
"Click or tap at where the property is on the map and name it below", | ||
allowNewAddresses: false, | ||
newAddressDescription: | ||
"You will need to select a location and provide a name to continue", | ||
newAddressDescriptionLabel: "Name the site", | ||
}, | ||
type: TYPES.FindProperty, | ||
}, | ||
Notice: { | ||
data: { | ||
color: "#EFEFEF", | ||
title: "End of test", | ||
resetButton: true, | ||
}, | ||
type: TYPES.Notice, | ||
}, | ||
QJeTHUDzfz: { | ||
data: { | ||
text: "Something else", | ||
flags: ["flag.pp.missingInfo"], | ||
}, | ||
type: TYPES.Answer, | ||
}, | ||
QuestionTwo: { | ||
data: { | ||
fn: "property.type", | ||
tags: [], | ||
text: "What type of residence is it?", | ||
neverAutoAnswer: false, | ||
}, | ||
type: TYPES.Question, | ||
edges: ["4jSYMB7hBJ", "xHpGvCpm0y", "QJeTHUDzfz"], | ||
}, | ||
oaF6TgEGZO: { | ||
data: { | ||
val: "residential", | ||
text: "Residential", | ||
flags: ["flag.pp.permittedDevelopment"], | ||
}, | ||
type: TYPES.Answer, | ||
edges: ["QuestionTwo"], | ||
}, | ||
QuestionOne: { | ||
data: { | ||
fn: "property.type", | ||
tags: [], | ||
text: "What type of property is it?", | ||
neverAutoAnswer: false, | ||
}, | ||
type: TYPES.Question, | ||
edges: ["oaF6TgEGZO", "tgP6NiYImY"], | ||
}, | ||
tgP6NiYImY: { | ||
data: { | ||
text: "Something else", | ||
flags: ["flag.pp.missingInfo"], | ||
}, | ||
type: TYPES.Answer, | ||
}, | ||
xHpGvCpm0y: { | ||
data: { | ||
val: "residential.flat", | ||
text: "Flat", | ||
flags: ["flag.pp.permissionNeeded"], | ||
}, | ||
type: TYPES.Answer, | ||
}, | ||
Result: { | ||
data: { | ||
flagSet: "Planning permission", | ||
}, | ||
type: TYPES.Result, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import type { | ||
import { | ||
ComponentType, | ||
FlowGraph, | ||
Node, | ||
type FlowGraph, | ||
type Node, | ||
} from "@opensystemslab/planx-core/types"; | ||
import type { Entry } from "type-fest"; | ||
|
||
|
@@ -24,7 +24,11 @@ export const hasComponentType = ( | |
); | ||
|
||
if (fn) { | ||
return nodeIds.some(([, nodeData]) => nodeData?.data?.fn === fn); | ||
if (type === ComponentType.Answer) { | ||
return nodeIds.some(([, nodeData]) => nodeData?.data?.val === fn); | ||
} else { | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch 👍 |
||
return nodeIds.some(([, nodeData]) => nodeData?.data?.fn === fn); | ||
} | ||
} | ||
|
||
return Boolean(nodeIds.length); | ||
|
@@ -39,11 +43,16 @@ export const numberOfComponentType = ( | |
(entry): entry is [string, Node] => isComponentType(entry, type), | ||
); | ||
if (fn) { | ||
nodeIds | ||
?.filter(([_nodeId, nodeData]) => nodeData?.data?.fn === fn) | ||
?.map(([nodeId, _nodeData]) => nodeId); | ||
if (type === ComponentType.Answer) { | ||
return nodeIds | ||
?.filter(([_nodeId, nodeData]) => nodeData?.data?.val === fn) | ||
?.map(([nodeId, _nodeData]) => nodeId)?.length; | ||
} else { | ||
return nodeIds | ||
?.filter(([_nodeId, nodeData]) => nodeData?.data?.fn === fn) | ||
?.map(([nodeId, _nodeData]) => nodeId)?.length; | ||
} | ||
} else { | ||
nodeIds?.map(([nodeId, _nodeData]) => nodeId); | ||
return nodeIds?.map(([nodeId, _nodeData]) => nodeId)?.length; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are unrelated to the most recent planx-core change, but came across them when investigating why the |
||
return nodeIds?.length; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { Passport } from "@opensystemslab/planx-core/types"; | ||
|
||
import { isApplicationTypeSupported } from "./helpers.js"; | ||
|
||
vi.mock("@opensystemslab/planx-core", () => { | ||
return { | ||
getValidSchemaValues: vi | ||
.fn() | ||
.mockImplementation(() => ["ldc", "ldc.p", "ldc.e", "pp", "pa"]), | ||
}; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These mocks resolve questions raised earlier here: https://opensystemslab.slack.com/archives/C01E3AC0C03/p1737996349338569 When testing the route via |
||
|
||
describe("isApplicationTypeSupported", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test("returns true for statutory application types", () => { | ||
const mockPassport: Passport = { data: { "application.type": ["ldc.p"] } }; | ||
expect(isApplicationTypeSupported(mockPassport)).toEqual(true); | ||
}); | ||
|
||
test("return true for pre-applications", () => { | ||
const mockPassport: Passport = { data: { "application.type": ["preApp"] } }; | ||
expect(isApplicationTypeSupported(mockPassport)).toEqual(true); | ||
}); | ||
|
||
test("returns false for discretionary types", () => { | ||
const mockPassport: Passport = { data: { "application.type": ["breach"] } }; | ||
expect(isApplicationTypeSupported(mockPassport)).toEqual(false); | ||
}); | ||
|
||
test("returns false if passport does not have application.type key", () => { | ||
const mockPassport: Passport = { | ||
data: { "property.type": ["residential"] }, | ||
}; | ||
expect(isApplicationTypeSupported(mockPassport)).toEqual(false); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@cucumber/cucumber": "^11.1.1", | ||
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#01d3dc6", | ||
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#6f16516", | ||
"axios": "^1.7.4", | ||
"dotenv": "^16.3.1", | ||
"dotenv-expand": "^10.0.0", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate the extra coverage here 👍