Skip to content

Commit

Permalink
chore: Create model file for Question
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 23, 2024
1 parent b6c2b72 commit 8d30dd8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
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;
}

0 comments on commit 8d30dd8

Please sign in to comment.