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

chore: Create model file for Question #3726

Merged
merged 1 commit into from
Sep 24, 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
13 changes: 7 additions & 6 deletions editor.planx.uk/src/@planx/components/Question/Public.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -59,7 +60,7 @@ describe("Question component", () => {
const handleSubmit = vi.fn();

const { user, getByTestId, getByRole, getByText } = setup(
<Question
<QuestionComponent
text="Best food"
responses={responses[type]}
handleSubmit={handleSubmit}
Expand All @@ -82,7 +83,7 @@ describe("Question component", () => {
it(`should display previously selected answer on back or change`, async () => {
const handleSubmit = vi.fn();
const { user, getByRole, getByTestId } = setup(
<Question
<QuestionComponent
text="Best food"
responses={responses[type]}
previouslySubmittedData={{
Expand Down Expand Up @@ -112,7 +113,7 @@ describe("Question component", () => {
it(`should not have any accessibility violations`, async () => {
const handleSubmit = vi.fn();
const { container } = setup(
<Question
<QuestionComponent
text="Best food"
responses={responses[type]}
handleSubmit={handleSubmit}
Expand All @@ -127,7 +128,7 @@ describe("Question component", () => {
const errorMessage = /Select your answer before continuing/;

const { user, getByTestId, getByText, queryByText } = setup(
<Question
<QuestionComponent
text="Best food"
responses={responses[type]}
handleSubmit={handleSubmit}
Expand Down
26 changes: 3 additions & 23 deletions editor.planx.uk/src/@planx/components/Question/Public/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,21 @@ import BasicRadio from "@planx/components/shared/Radio/BasicRadio";
import DescriptionRadio from "@planx/components/shared/Radio/DescriptionRadio";
import ImageRadio from "@planx/components/shared/Radio/ImageRadio";
import { useFormik } from "formik";
import { Store } from "pages/FlowEditor/lib/store";
import { HandleSubmit } from "pages/Preview/Node";
import React from "react";
import FormWrapper from "ui/public/FormWrapper";
import FullWidthWrapper from "ui/public/FullWidthWrapper";
import ErrorWrapper from "ui/shared/ErrorWrapper";
import { mixed, object, string } from "yup";

export interface IQuestion {
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;
}
import { Question } from "../model";

export enum QuestionLayout {
Basic,
Images,
Descriptions,
}

const Question: React.FC<IQuestion> = (props) => {
const QuestionComponent: React.FC<Question> = (props) => {
const previousResponseId = props?.previouslySubmittedData?.answers?.[0];
const previousResponseKey = props.responses.find(
(response) => response.id === previousResponseId,
Expand Down Expand Up @@ -170,4 +150,4 @@ const Question: React.FC<IQuestion> = (props) => {
);
};

export default Question;
export default QuestionComponent;
22 changes: 22 additions & 0 deletions editor.planx.uk/src/@planx/components/Question/model.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Loading