-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Coverage for all exceptional node types
- Loading branch information
1 parent
f3bd160
commit 8da07a2
Showing
2 changed files
with
791 additions
and
8 deletions.
There are no files selected for viewing
120 changes: 112 additions & 8 deletions
120
...uk/src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/DataDisplayMap.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.