-
Notifications
You must be signed in to change notification settings - Fork 22
[FEQ]Yaswanth/FEQ-1974_Added test cases for sidenote component #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shayan-deriv
merged 4 commits into
deriv-com:main
from
yaswanth-deriv:yaswanth/FEQ-1974_Added_test_for_sidenote_component
Mar 26, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dfaf382
test: added test cases for sidenote component
yaswanth-deriv 6017554
Merge branch 'deriv-com:main' into yaswanth/FEQ-1974_Added_test_for_s…
yaswanth-deriv 9be235f
test: added new test cases and added testid in side note component
yaswanth-deriv 2e41afb
test : mde changes in test cases
yaswanth-deriv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.