Skip to content

Commit 9be235f

Browse files
test: added new test cases and added testid in side note component
1 parent 6017554 commit 9be235f

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/components/SideNote/__test__/SideNote.spec.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { render, fireEvent } from "@testing-library/react";
33
import { SideNote } from "..";
44

55
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+
621
it("renders children and title correctly", () => {
722
const { getByText } = render(
823
<SideNote title="Title">
@@ -52,7 +67,7 @@ describe("SideNote Component", () => {
5267

5368
it("renders action button with default label if no actionLabel provided", () => {
5469
const { getByText } = render(
55-
<SideNote actionClick={() => {}}>
70+
<SideNote actionClick={() => { }}>
5671
<div>Child content</div>
5772
</SideNote>
5873
);

src/components/SideNote/index.tsx

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

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)