Skip to content

Commit c06d2a4

Browse files
committed
fix: resolved merge conflicts
2 parents 06f5a39 + dda8d11 commit c06d2a4

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from "react";
2+
import { render, fireEvent } from "@testing-library/react";
3+
import { SideNote } from "..";
4+
5+
describe("SideNote Component", () => {
6+
7+
it("renders properly with default props", () => {
8+
const { getByText, queryByTestId, container } = render(
9+
<SideNote>
10+
<div>Child content</div>
11+
</SideNote>,
12+
);
13+
const title = queryByTestId("dt_deriv-side-note-title");
14+
const content = getByText("Child content");
15+
const actionButton = container.getElementsByClassName('deriv-side-note__action');
16+
expect(title).not.toBeInTheDocument();
17+
expect(content).toBeInTheDocument();
18+
expect(actionButton).toHaveLength(0);
19+
});
20+
21+
it("renders children and title correctly", () => {
22+
const { getByText } = render(
23+
<SideNote title="Title">
24+
<div>Child content</div>
25+
</SideNote>
26+
);
27+
const title =getByText("Title");
28+
const child=getByText("Child content")
29+
expect(title).toBeInTheDocument();
30+
expect(child).toBeInTheDocument();
31+
});
32+
33+
it("renders action button and handles click event", () => {
34+
const handleClick = jest.fn();
35+
const { getByText } = render(
36+
<SideNote actionClick={handleClick} actionLabel="Action">
37+
<div>Child content</div>
38+
</SideNote>
39+
);
40+
const actionButton = getByText("Action");
41+
fireEvent.click(actionButton);
42+
expect(handleClick).toHaveBeenCalled();
43+
});
44+
45+
it("applies additional className correctly", () => {
46+
const { container } = render(
47+
<SideNote className="custom-class">
48+
<div>Child content</div>
49+
</SideNote>
50+
);
51+
expect(container.firstChild).toHaveClass("deriv-side-note", "custom-class");
52+
});
53+
54+
it("renders only title when children are not provided", () => {
55+
const { getByText, queryByText } = render(<SideNote title="Title" />);
56+
const title = getByText("Title");
57+
const child = queryByText("Child content");
58+
expect(title).toBeInTheDocument();
59+
expect(child).toBeNull();
60+
});
61+
62+
it("renders only children when title is not provided", () => {
63+
const { getByText, queryByText } = render(
64+
<SideNote>
65+
<div>Child content</div>
66+
</SideNote>
67+
);
68+
const title = queryByText("Title");
69+
const child = getByText("Child content");
70+
expect(child).toBeInTheDocument();
71+
expect(title).toBeNull();
72+
});
73+
74+
it("renders action button with default label if no actionLabel provided", () => {
75+
const { getByText } = render(
76+
<SideNote actionClick={() => { }}>
77+
<div>Child content</div>
78+
</SideNote>
79+
);
80+
const action = getByText("Learn more")
81+
expect(action).toBeInTheDocument();
82+
});
83+
84+
});

src/components/SideNote/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const SideNote = ({
4343
}: PropsWithChildren<SideNoteProps>) => (
4444
<div className={clsx("deriv-side-note", className)} {...props}>
4545
{title && (
46-
<Text className={clsx("deriv-side-note__title", titleClassName)} size={titleSize} align="left" weight="bold">
46+
<Text data-testid="dt_deriv-side-note-title" className={clsx("deriv-side-note__title", titleClassName)} size={titleSize} align="left" weight="bold">
4747
{title}
4848
</Text>
4949
)}

src/components/Text/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { CSSProperties, ElementType, ReactNode } from "react";
1+
import React, { CSSProperties,ComponentProps, ElementType, ReactNode } from "react";
22
import clsx from "clsx";
33
import "./Text.scss";
44

@@ -29,7 +29,7 @@ type TGenericSizes =
2929
| "xl"
3030
| "xs";
3131

32-
export interface TextProps {
32+
export interface TextProps extends ComponentProps<ElementType> {
3333
align?: CSSProperties["textAlign"];
3434
as?: ElementType;
3535
children: ReactNode;
@@ -51,6 +51,7 @@ export const Text = ({
5151
size = "md",
5252
weight = "normal",
5353
className,
54+
...rest
5455
}: TextProps) => {
5556
const textClassNames = clsx(
5657
"deriv-text",
@@ -65,5 +66,5 @@ export const Text = ({
6566

6667
const Tag = as;
6768

68-
return <Tag className={textClassNames}>{children}</Tag>;
69+
return <Tag className={textClassNames} {...rest}>{children}</Tag>;
6970
};

0 commit comments

Comments
 (0)