diff --git a/src/components/SideNote/__test__/SideNote.spec.tsx b/src/components/SideNote/__test__/SideNote.spec.tsx new file mode 100644 index 00000000..36d8b296 --- /dev/null +++ b/src/components/SideNote/__test__/SideNote.spec.tsx @@ -0,0 +1,84 @@ +import React from "react"; +import { render, fireEvent } from "@testing-library/react"; +import { SideNote } from ".."; + +describe("SideNote Component", () => { + + it("renders properly with default props", () => { + const { getByText, queryByTestId, container } = render( + +
Child content
+
, + ); + const title = queryByTestId("dt_deriv-side-note-title"); + const content = getByText("Child content"); + const actionButton = container.getElementsByClassName('deriv-side-note__action'); + expect(title).not.toBeInTheDocument(); + expect(content).toBeInTheDocument(); + expect(actionButton).toHaveLength(0); + }); + + it("renders children and title correctly", () => { + const { getByText } = render( + +
Child content
+
+ ); + const title =getByText("Title"); + const child=getByText("Child content") + expect(title).toBeInTheDocument(); + expect(child).toBeInTheDocument(); + }); + + it("renders action button and handles click event", () => { + const handleClick = jest.fn(); + const { getByText } = render( + +
Child content
+
+ ); + const actionButton = getByText("Action"); + fireEvent.click(actionButton); + expect(handleClick).toHaveBeenCalled(); + }); + + it("applies additional className correctly", () => { + const { container } = render( + +
Child content
+
+ ); + expect(container.firstChild).toHaveClass("deriv-side-note", "custom-class"); + }); + + it("renders only title when children are not provided", () => { + const { getByText, queryByText } = render(); + const title = getByText("Title"); + const child = queryByText("Child content"); + expect(title).toBeInTheDocument(); + expect(child).toBeNull(); + }); + + it("renders only children when title is not provided", () => { + const { getByText, queryByText } = render( + +
Child content
+
+ ); + const title = queryByText("Title"); + const child = getByText("Child content"); + expect(child).toBeInTheDocument(); + expect(title).toBeNull(); + }); + + it("renders action button with default label if no actionLabel provided", () => { + const { getByText } = render( + { }}> +
Child content
+
+ ); + const action = getByText("Learn more") + expect(action).toBeInTheDocument(); + }); + +}); diff --git a/src/components/SideNote/index.tsx b/src/components/SideNote/index.tsx index e3fa4190..9e80d348 100644 --- a/src/components/SideNote/index.tsx +++ b/src/components/SideNote/index.tsx @@ -40,7 +40,7 @@ export const SideNote = ({ }: PropsWithChildren) => (
{title && ( - + {title} )} diff --git a/src/components/Text/index.tsx b/src/components/Text/index.tsx index 853e5f00..95e52369 100644 --- a/src/components/Text/index.tsx +++ b/src/components/Text/index.tsx @@ -1,4 +1,4 @@ -import React, { CSSProperties, ElementType, ReactNode } from "react"; +import React, { CSSProperties,ComponentProps, ElementType, ReactNode } from "react"; import clsx from "clsx"; import "./Text.scss"; @@ -29,7 +29,7 @@ type TGenericSizes = | "xl" | "xs"; -export interface TextProps { +export interface TextProps extends ComponentProps { align?: CSSProperties["textAlign"]; as?: ElementType; children: ReactNode; @@ -51,6 +51,7 @@ export const Text = ({ size = "md", weight = "normal", className, + ...rest }: TextProps) => { const textClassNames = clsx( "deriv-text", @@ -65,5 +66,5 @@ export const Text = ({ const Tag = as; - return {children}; + return {children}; };