Skip to content

Commit

Permalink
test: Coverage for all exceptional node types
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 10, 2024
1 parent f3bd160 commit 8da07a2
Show file tree
Hide file tree
Showing 2 changed files with 791 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,126 @@
import { ComponentType } from "@opensystemslab/planx-core/types";
import { useStore } from "pages/FlowEditor/lib/store";

import {
mockAnswerResult,
mockCalculateFormulaResult,
mockCalculateRootResult,
mockFileUploadAndLabelResult,
mockFlow,
mockListAnswerResult,
mockListDataResult,
mockListRootResult,
mockQuestionResult,
} from "../mocks/DataDisplayMap";
import { getDisplayDetailsForResult } from "./DataDisplayMap";

type Output = ReturnType<typeof getDisplayDetailsForResult>;

// Setup flow so that it can be referenced by SearchResults (e.g. getting parent nodes)
beforeAll(() => useStore.setState({ flow: mockFlow }));

describe("Question component", () => {
it.todo("returns the expected display values");
it("returns the expected display values", () => {
const output = getDisplayDetailsForResult(mockQuestionResult);

expect(output).toStrictEqual<Output>({
key: "Data",
iconKey: ComponentType.Question,
componentType: "Question",
title: "This is a question component",
headline: "colour",
});
});
});

describe("Answer component", () => {
it.todo("returns the expected display values");
it("returns the expected display values", () => {
const output = getDisplayDetailsForResult(mockAnswerResult);

expect(output).toStrictEqual<Output>({
key: "Option (data)",
iconKey: ComponentType.Question,
componentType: "Question",
title: "This is a question component",
headline: "red",
});
});
});

describe("List component", () => {
it.todo("handles the default (root) data value");
it.todo("handles nested data variables");
it.todo("handles nested data variables in Answers");
it("handles the root data value", () => {
const output = getDisplayDetailsForResult(mockListRootResult);

expect(output).toStrictEqual<Output>({
componentType: "List",
headline: "listRoot",
iconKey: ComponentType.List,
key: "Data",
title: "This is a list component",
});
});

it("handles nested data variables", () => {
const output = getDisplayDetailsForResult(mockListDataResult);

expect(output).toStrictEqual<Output>({
componentType: "List",
headline: "tenure",
iconKey: ComponentType.List,
key: "Data",
title: "This is a list component",
});
});

it("handles nested data variables in Answers", () => {
const output = getDisplayDetailsForResult(mockListAnswerResult);

expect(output).toStrictEqual<Output>({
componentType: "List",
headline: "selfCustomBuild",
iconKey: ComponentType.List,
key: "Option (data)",
title: "This is a list component",
});
});
});

describe("Calculate component", () => {
it.todo("handles the output data variables");
it.todo("handles the formula data variables");
it("handles the output data variables", () => {
const output = getDisplayDetailsForResult(mockCalculateRootResult);

expect(output).toStrictEqual<Output>({
componentType: "Calculate",
headline: "calculateOutput",
iconKey: ComponentType.Calculate,
key: "Output (data)",
title: "This is a calculate component",
});
});

it("handles the formula data variables", () => {
const output = getDisplayDetailsForResult(mockCalculateFormulaResult);

expect(output).toStrictEqual<Output>({
componentType: "Calculate",
headline: "formulaOne + formulaTwo",
iconKey: ComponentType.Calculate,
key: "Formula",
title: "This is a calculate component",
});
});
});

describe("FileUploadAndLabel component", () => {
it.todo("handles the data variables nested in FileTypes");
it("handles the data variables nested in FileTypes", () => {
const output = getDisplayDetailsForResult(mockFileUploadAndLabelResult);

expect(output).toStrictEqual<Output>({
componentType: "File upload and label",
headline: "floorplan",
iconKey: ComponentType.FileUploadAndLabel,
key: "File type (data)",
title: "This is a FileUploadAndLabel component",
});
});
});
Loading

0 comments on commit 8da07a2

Please sign in to comment.