|
1 | 1 | import { createElement } from "react";
|
2 |
| -import { getOptionId, getOptionLabel } from "../utils"; |
| 2 | +import { getOptionId, getOptionLabel, getDisplayLabel } from "../utils"; |
3 | 3 |
|
4 | 4 | describe("getOptionId", () => {
|
5 | 5 | it("should return the correct id starting from 1 instead of 0", () => {
|
@@ -35,3 +35,37 @@ describe("getOptionLabel", () => {
|
35 | 35 | expect(getOptionLabel({ value: "A" }, "label")).toBe(null);
|
36 | 36 | });
|
37 | 37 | });
|
| 38 | + |
| 39 | +describe("getDisplayLabel", () => { |
| 40 | + it("should return null if there is no option", () => { |
| 41 | + expect(getDisplayLabel(null, "label", true)).toBe(null); |
| 42 | + expect(getDisplayLabel(null, "label", false)).toBe(null); |
| 43 | + expect(getDisplayLabel("", "label", true)).toBe(null); |
| 44 | + expect(getDisplayLabel("", "label", false)).toBe(null); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should return the label if the includeLeft option is false or the option is not an object", () => { |
| 48 | + expect(getDisplayLabel(0, "label", true)).toBe(0); |
| 49 | + expect(getDisplayLabel(0, "label", false)).toBe(0); |
| 50 | + expect(getDisplayLabel("0", "label", true)).toBe("0"); |
| 51 | + expect(getDisplayLabel("0", "label", false)).toBe("0"); |
| 52 | + expect(getDisplayLabel("Hello", "label", true)).toBe("Hello"); |
| 53 | + expect(getDisplayLabel("Hello", "label", false)).toBe("Hello"); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should return the TextIconSpacing component when includeLeft is enabled and the option is an prop object", () => { |
| 57 | + const option = { |
| 58 | + leftAddon: "Addon", |
| 59 | + label: "Some Words", |
| 60 | + }; |
| 61 | + |
| 62 | + const result = getDisplayLabel(option, "label", true); |
| 63 | + expect(result).toMatchInlineSnapshot(` |
| 64 | + <TextIconSpacing |
| 65 | + icon="Addon" |
| 66 | + > |
| 67 | + Some Words |
| 68 | + </TextIconSpacing> |
| 69 | + `); |
| 70 | + }); |
| 71 | +}); |
0 commit comments