Skip to content

Commit

Permalink
test: Confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 16, 2024
1 parent e93d655 commit 1a9a619
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentType } from "@opensystemslab/planx-core/types";
import { useStore } from "pages/FlowEditor/lib/store";

import { mockChecklistOptionResult, mockChecklistResult, mockContentResult, mockFileUploadAndLabelResult, mockFlow, mockNextStepsOptionResult, mockNumberInputResult, mockPayResult, mockQuestionResult, mockSchemaResult, mockTaskListResult } from "../mocks/allFacetFlow";
import { mockChecklistOptionResult, mockChecklistResult, mockConfirmationResult, mockContentResult, mockFileUploadAndLabelResult, mockFlow, mockNextStepsOptionResult, mockNumberInputResult, mockPayResult, mockQuestionResult, mockSchemaResult, mockTaskListResult } from "../mocks/allFacetFlow";
import { getDisplayDetailsForResult } from "./getDisplayDetailsForResult";

type Output = ReturnType<typeof getDisplayDetailsForResult>;
Expand Down Expand Up @@ -49,7 +49,6 @@ describe("Basic fields", () => {
});
});
});

describe("More information fields", () => {
it("renders data.notes", () => {
const output = getDisplayDetailsForResult({
Expand Down Expand Up @@ -111,7 +110,6 @@ describe("More information fields", () => {
});
});
});

describe("checklist fields", () => {
it("renders data.categories.title", () => {
const output = getDisplayDetailsForResult(mockChecklistResult);
Expand All @@ -137,6 +135,7 @@ describe("checklist fields", () => {
});
});
});

describe("nextSteps fields", () => {
it("renders data.steps.title", () => {
const output = getDisplayDetailsForResult(mockNextStepsOptionResult);
Expand Down Expand Up @@ -253,7 +252,6 @@ describe("numberInput fields", () => {
});
});
});

describe("schemaComponents fields", () => {
it("renders data.schemaName", () => {
const output = getDisplayDetailsForResult(mockSchemaResult);
Expand Down Expand Up @@ -380,11 +378,78 @@ describe("content fields", () => {
});

describe("confirmation fields", () => {
it.todo("renders data.heading");
it.todo("renders data.moreInfo");
it.todo("renders data.contactInfo");
it.todo("renders data.nextSteps.title");
it.todo("renders data.nextSteps.description");
it("renders data.heading", () => {
const output = getDisplayDetailsForResult(mockConfirmationResult);

expect(output).toStrictEqual<Output>({
key: "Title",
iconKey: ComponentType.Confirmation,
componentType: "Confirmation",
title: "",
headline: "Snake",
});
});

it("renders data.moreInfo", () => {
const output = getDisplayDetailsForResult({
...mockConfirmationResult,
key: "data.moreInfo",
});

expect(output).toStrictEqual<Output>({
key: "More information",
iconKey: ComponentType.Confirmation,
componentType: "Confirmation",
title: "",
headline: "<p>Tarantula</p>",
});
});

it("renders data.contactInfo", () => {
const output = getDisplayDetailsForResult({
...mockConfirmationResult,
key: "data.contactInfo",
});

expect(output).toStrictEqual<Output>({
key: "Contact information",
iconKey: ComponentType.Confirmation,
componentType: "Confirmation",
title: "",
headline: "<p>Weasel</p>",
});
});

it("renders data.nextSteps.title", () => {
const output = getDisplayDetailsForResult({
...mockConfirmationResult,
key: "data.nextSteps.title"
});

expect(output).toStrictEqual<Output>({
key: "Title (next steps)",
iconKey: ComponentType.Confirmation,
componentType: "Confirmation",
title: "",
headline: "Llama",
});
});

it("renders data.nextSteps.description", () => {
const output = getDisplayDetailsForResult({
...mockConfirmationResult,
key: "data.nextSteps.description"
});

expect(output).toStrictEqual<Output>({
key: "Description (next steps)",
iconKey: ComponentType.Confirmation,
componentType: "Confirmation",
title: "",
headline: "Toucan",
});
});

});

describe("findProperty fields", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const keyFormatters: KeyMap = {
(item.data as unknown as Confirmation).nextSteps![refIndex].title,
},
"data.nextSteps.description": {
getDisplayKey: () => "Description",
getDisplayKey: () => "Description (next steps)",
getHeadline: ({ item, refIndex }) =>
(item.data as unknown as Confirmation).nextSteps![refIndex].description,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,42 @@ export const mockTaskListResult: SearchResult<IndexedNode> = {
refIndex: 0,
};


export const mockContentResult: SearchResult<IndexedNode> = {
item: {
id: "StMBQK1WZo",
parentId: "_root",
type: 250,
data: {
content: "<p>Sheep</p>"
}
content: "<p>Sheep</p>",
},
},
key: "data.content",
matchIndices: [
[
3,
7
]
],
refIndex: 0
};
matchIndices: [[3, 7]],
refIndex: 0,
};

export const mockConfirmationResult: SearchResult<IndexedNode> = {
item: {
id: "7eG9iF86xd",
parentId: "_root",
type: 725,
data: {
color: {
text: "#000",
background: "rgba(1, 99, 96, 0.1)",
},
heading: "Snake",
moreInfo: "<p>Tarantula</p>",
nextSteps: [
{
title: "Llama",
description: "Toucan",
},
],
contactInfo: "<p>Weasel</p>",
},
},
key: "data.heading",
matchIndices: [[0, 4]],
refIndex: 0,
};

0 comments on commit 1a9a619

Please sign in to comment.