diff --git a/editor.planx.uk/src/@planx/components/Question/Public.test.tsx b/editor.planx.uk/src/@planx/components/Question/Public.test.tsx index 38a780c4a1..34ad08ae52 100644 --- a/editor.planx.uk/src/@planx/components/Question/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/Question/Public.test.tsx @@ -4,9 +4,10 @@ import { setup } from "testUtils"; import { vi } from "vitest"; import { axe } from "vitest-axe"; -import Question, { IQuestion, QuestionLayout } from "./Public"; +import type { Question } from "./model"; +import QuestionComponent, { QuestionLayout } from "./Public"; -const responses: { [key in QuestionLayout]: IQuestion["responses"] } = { +const responses: { [key in QuestionLayout]: Question["responses"] } = { [QuestionLayout.Basic]: [ { id: "pizza_id", @@ -59,7 +60,7 @@ describe("Question component", () => { const handleSubmit = vi.fn(); const { user, getByTestId, getByRole, getByText } = setup( - { it(`should display previously selected answer on back or change`, async () => { const handleSubmit = vi.fn(); const { user, getByRole, getByTestId } = setup( - { it(`should not have any accessibility violations`, async () => { const handleSubmit = vi.fn(); const { container } = setup( - { const errorMessage = /Select your answer before continuing/; const { user, getByTestId, getByText, queryByText } = setup( - = (props) => { +const QuestionComponent: React.FC = (props) => { const previousResponseId = props?.previouslySubmittedData?.answers?.[0]; const previousResponseKey = props.responses.find( (response) => response.id === previousResponseId, @@ -170,4 +150,4 @@ const Question: React.FC = (props) => { ); }; -export default Question; +export default QuestionComponent; diff --git a/editor.planx.uk/src/@planx/components/Question/model.ts b/editor.planx.uk/src/@planx/components/Question/model.ts new file mode 100644 index 0000000000..4ddbec9e58 --- /dev/null +++ b/editor.planx.uk/src/@planx/components/Question/model.ts @@ -0,0 +1,22 @@ +import { Store } from "pages/FlowEditor/lib/store"; +import { HandleSubmit } from "pages/Preview/Node"; + +export interface Question { + id?: string; + text?: string; + description?: string; + info?: string; + policyRef?: string; + howMeasured?: string; + definitionImg?: string; + img?: string; + responses: { + id: string; + responseKey: string | number; + title: string; + description?: string; + img?: string; + }[]; + previouslySubmittedData?: Store.UserData; + handleSubmit: HandleSubmit; +}