-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Tab): add tooltipProps prop (#2750)
- Loading branch information
1 parent
6102dd1
commit 3714938
Showing
3 changed files
with
70 additions
and
29 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
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
52 changes: 43 additions & 9 deletions
52
packages/core/src/components/Tabs/Tab/__tests__/Tab.test.tsx
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 |
---|---|---|
@@ -1,17 +1,51 @@ | ||
import React from "react"; | ||
import { render, fireEvent, screen } from "@testing-library/react"; | ||
import Tab from "../Tab"; | ||
import { render, fireEvent, screen, cleanup } from "@testing-library/react"; | ||
import { act } from "@testing-library/react-hooks"; | ||
import Tab, { TabProps } from "../Tab"; | ||
|
||
jest.useFakeTimers(); | ||
|
||
const onClickMock = jest.fn(); | ||
const text = "tab"; | ||
|
||
const renderComponent = (props: TabProps = {}) => { | ||
return render( | ||
<Tab onClick={onClickMock} {...props}> | ||
{text} | ||
</Tab> | ||
); | ||
}; | ||
|
||
describe("Tab tests", () => { | ||
const onClickMock = jest.fn(); | ||
const text = "tab"; | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
beforeEach(() => { | ||
render(<Tab onClick={onClickMock}>{text}</Tab>); | ||
describe("click", () => { | ||
it("should call the click callback when clicked", () => { | ||
renderComponent(); | ||
fireEvent.click(screen.getByText(text)); | ||
expect(onClickMock.mock.calls.length).toBe(1); | ||
}); | ||
}); | ||
|
||
it("should call the click callback when clicked", () => { | ||
fireEvent.click(screen.getByText(text)); | ||
expect(onClickMock.mock.calls.length).toBe(1); | ||
describe("Tooltips", () => { | ||
it("should display tooltip content from tooltipProps", () => { | ||
const tooltipContent = "My Text"; | ||
const tooltipProps = { content: tooltipContent }; | ||
|
||
renderComponent({ tooltipProps }); | ||
const component = screen.getByText(text); | ||
act(() => { | ||
fireEvent.mouseEnter(component); | ||
}); | ||
jest.advanceTimersByTime(1000); | ||
const content = screen.getByText(tooltipContent); | ||
expect(content).toBeTruthy(); | ||
act(() => { | ||
fireEvent.mouseLeave(component); | ||
}); | ||
jest.advanceTimersByTime(1000); | ||
}); | ||
}); | ||
}); |