-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from yaswanth-deriv/yaswanth/FEQ-1974_Added_t…
…est_for_sidenote_component [FEQ]Yaswanth/FEQ-1974_Added test cases for sidenote component
- Loading branch information
Showing
3 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<SideNote> | ||
<div>Child content</div> | ||
</SideNote>, | ||
); | ||
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( | ||
<SideNote title="Title"> | ||
<div>Child content</div> | ||
</SideNote> | ||
); | ||
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( | ||
<SideNote actionClick={handleClick} actionLabel="Action"> | ||
<div>Child content</div> | ||
</SideNote> | ||
); | ||
const actionButton = getByText("Action"); | ||
fireEvent.click(actionButton); | ||
expect(handleClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it("applies additional className correctly", () => { | ||
const { container } = render( | ||
<SideNote className="custom-class"> | ||
<div>Child content</div> | ||
</SideNote> | ||
); | ||
expect(container.firstChild).toHaveClass("deriv-side-note", "custom-class"); | ||
}); | ||
|
||
it("renders only title when children are not provided", () => { | ||
const { getByText, queryByText } = render(<SideNote title="Title" />); | ||
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( | ||
<SideNote> | ||
<div>Child content</div> | ||
</SideNote> | ||
); | ||
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( | ||
<SideNote actionClick={() => { }}> | ||
<div>Child content</div> | ||
</SideNote> | ||
); | ||
const action = getByText("Learn more") | ||
expect(action).toBeInTheDocument(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters