Skip to content

Commit

Permalink
feat: feedback analytics and previously submitted answers (#3948)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion authored Nov 19, 2024
1 parent 181b245 commit 3c17075
Show file tree
Hide file tree
Showing 6 changed files with 609 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql } from "graphql-request";

import { Passport } from "@opensystemslab/planx-core";

import { $api } from "../../../../client/index.js";
import type { Operation } from "../sanitiseApplicationData/types.js";

Expand All @@ -20,6 +21,7 @@ const ALLOW_LIST = [
"application.information.sensitive",
"application.type",
"drawBoundary.action",
"_feedback",
"findProperty.action",
"_overrides",
"planningConstraints.action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ErrorWrapper from "ui/shared/ErrorWrapper";
import Input from "ui/shared/Input/Input";
import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml/ReactMarkdownOrHtml";

import { getPreviouslySubmittedData, makeData } from "../../shared/utils";
import { makeData } from "../../shared/utils";
import { FaceBox } from "../components/FaceBox";
import { createFeedbackSchema, Feedback, FormProps } from "../model";
import { StyledToggleButtonGroup } from "../styled";
Expand Down Expand Up @@ -50,7 +50,7 @@ const FeedbackComponent = (props: PublicProps<Feedback>): FCReturn => {
};

const formik = useFormik<FormProps>({
initialValues: getPreviouslySubmittedData(props) ?? {
initialValues: props.previouslySubmittedData?.data?._feedback ?? {
feedbackScore: "",
userComment: "",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,34 @@ describe("when feedback is required but the user does not submit any data", asyn
});
});
});

describe("When the user presses to go back to the feedback component", () => {
it("recovers the previously submitted answers", async () => {
const handleSubmit = vi.fn();

const { user } = setup(
<FeedbackComponent
handleSubmit={handleSubmit}
feedbackRequired={false}
previouslySubmittedData={{
data: {
_feedback: {
userComment: "I wrote this previously",
feedbackScore: 2,
},
},
}}
/>,
);

expect(screen.getByText("I wrote this previously")).toBeVisible();

await user.click(screen.getByTestId("continue-button"));

expect(insertFeedbackMutation).toHaveBeenCalledWith({
feedbackScore: 2,
feedbackType: "component",
userComment: "I wrote this previously",
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DocumentNode } from "@apollo/client";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { PASSPORT_FEEDBACK_KEY } from "@planx/components/Feedback/Public/Public";
import Bowser from "bowser";
import { publicClient } from "lib/graphql";
import React, { createContext, useContext, useEffect } from "react";
Expand Down Expand Up @@ -48,6 +49,7 @@ export const ALLOW_LIST = [
"application.information.sensitive",
"application.type",
"drawBoundary.action",
PASSPORT_FEEDBACK_KEY,
"findProperty.action",
"_overrides",
"planningConstraints.action",
Expand Down
Loading

0 comments on commit 3c17075

Please sign in to comment.