+ {renderHighlightText(
+ labelParts,
+ inputWithoutSpace,
+ "suggestion-item-label-highlight",
+ )}
+
+ {renderHighlightText(
+ subDescriptionParts,
+ inputWithoutSpace,
+ "suggestion-item-subDescription-highlight",
+ )}
+
+
+ );
};
export default FormatOptionLabel;
diff --git a/app/components/inputs/suggestionInput/customComponents/__test__/FormatOptionLabel.test.tsx b/app/components/inputs/suggestionInput/customComponents/__test__/FormatOptionLabel.test.tsx
new file mode 100644
index 000000000..5df89161f
--- /dev/null
+++ b/app/components/inputs/suggestionInput/customComponents/__test__/FormatOptionLabel.test.tsx
@@ -0,0 +1,109 @@
+import { render } from "@testing-library/react";
+import FormatOptionLabel from "../FormatOptionLabel";
+
+describe("FormatOptionLabel", () => {
+ it("it should render the label if the context is a value", () => {
+ const dataListOption = [{ label: "Paris", value: " any value" }];
+
+ const { getByText } = render(
+ FormatOptionLabel(dataListOption[0], {
+ context: "value",
+ inputValue: "Paris",
+ selectValue: dataListOption,
+ }),
+ );
+
+ expect(getByText(dataListOption[0].label)).toBeInTheDocument();
+ });
+
+ it("it should render the label and the subDescription without highlight if the context is a menu", () => {
+ const dataListOption = [
+ { label: "Paris", subDescription: "Paris, France", value: " any value" },
+ ];
+
+ const { queryByTestId } = render(
+ FormatOptionLabel(dataListOption[0], {
+ context: "menu",
+ inputValue: "any text",
+ selectValue: dataListOption,
+ }),
+ );
+
+ expect(
+ queryByTestId("suggestion-item-label-highlight"),
+ ).not.toBeInTheDocument();
+
+ expect(
+ queryByTestId("suggestion-item-subDescription-highlight"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("it should render the label and the subDescription with highlight if the context is a menu", () => {
+ const dataListOption = [
+ {
+ label: "Paris Charles de Gaulle",
+ subDescription: "Paris, France",
+ value: " any value",
+ },
+ ];
+
+ const mockInputValue = "Paris";
+
+ const { queryByTestId } = render(
+ FormatOptionLabel(dataListOption[0], {
+ context: "menu",
+ inputValue: mockInputValue,
+ selectValue: dataListOption,
+ }),
+ );
+
+ expect(
+ queryByTestId("suggestion-item-label-highlight"),
+ ).toBeInTheDocument();
+ expect(queryByTestId("suggestion-item-label-highlight")?.innerHTML).toBe(
+ mockInputValue,
+ );
+
+ expect(
+ queryByTestId("suggestion-item-subDescription-highlight"),
+ ).toBeInTheDocument();
+ expect(
+ queryByTestId("suggestion-item-subDescription-highlight")?.innerHTML,
+ ).toBe(mockInputValue);
+ });
+
+ it("it should render the label and the subDescription with highlight if the context is a menu even with empty space", () => {
+ const dataListOption = [
+ {
+ label: "Paris Charles de Gaulle",
+ subDescription: "Paris, France",
+ value: " any value",
+ },
+ ];
+
+ const mockInputValue = "Paris";
+ const emptySpace = " ";
+
+ const { queryByTestId } = render(
+ FormatOptionLabel(dataListOption[0], {
+ context: "menu",
+ inputValue: `${mockInputValue}${emptySpace}`,
+ selectValue: dataListOption,
+ }),
+ );
+
+ expect(
+ queryByTestId("suggestion-item-label-highlight"),
+ ).toBeInTheDocument();
+ expect(queryByTestId("suggestion-item-label-highlight")?.innerHTML).toBe(
+ mockInputValue,
+ );
+
+ expect(
+ queryByTestId("suggestion-item-subDescription-highlight"),
+ ).toBeInTheDocument();
+ expect(
+ queryByTestId("suggestion-item-subDescription-highlight")?.innerHTML,
+ ).toBe(mockInputValue);
+ });
+});