mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
## For #31869 - Add fine grain controls for tooltip show and hide delay behavior - Default to 250ms show delay across app - Update ~30 unit tests to expect new delay - See [note](https://github.com/fleetdm/fleet/issues/31869#issuecomment-3300660487) https://github.com/user-attachments/assets/5969e0f7-c137-491f-8430-6f21d01b9350 - [x] Changes file added for user-visible changes in `changes/` - [x] QA'd all new/changed functionality manually --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
94 lines
2.2 KiB
TypeScript
94 lines
2.2 KiB
TypeScript
import React from "react";
|
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
import { renderWithSetup } from "test/test-utils";
|
|
|
|
import RevealButton from "./RevealButton";
|
|
|
|
const SHOW_TEXT = "Show advanced options";
|
|
const HIDE_TEXT = "Hide advanced options";
|
|
const TOOLTIP_CONTENT = "Customize logging type and platforms";
|
|
|
|
describe("Reveal button", () => {
|
|
it("renders show text", async () => {
|
|
render(
|
|
<RevealButton
|
|
isShowing={false}
|
|
hideText={HIDE_TEXT}
|
|
showText={SHOW_TEXT}
|
|
/>
|
|
);
|
|
|
|
const showText = screen.getByText(SHOW_TEXT);
|
|
expect(showText).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders hide text", async () => {
|
|
render(
|
|
<RevealButton isShowing hideText={HIDE_TEXT} showText={SHOW_TEXT} />
|
|
);
|
|
|
|
const hideText = screen.getByText(HIDE_TEXT);
|
|
expect(hideText).toBeInTheDocument();
|
|
});
|
|
|
|
it("hides caret by default", async () => {
|
|
render(
|
|
<RevealButton
|
|
isShowing={false}
|
|
hideText={HIDE_TEXT}
|
|
showText={SHOW_TEXT}
|
|
/>
|
|
);
|
|
|
|
const icon = screen.queryByTestId("chevron-down-icon");
|
|
|
|
expect(icon).toBeNull();
|
|
});
|
|
|
|
it("renders caret on left", async () => {
|
|
render(
|
|
<RevealButton
|
|
isShowing={false}
|
|
hideText={HIDE_TEXT}
|
|
showText={SHOW_TEXT}
|
|
caretPosition="before"
|
|
/>
|
|
);
|
|
|
|
const icon = screen.queryByTestId("chevron-right-icon");
|
|
expect(icon?.nextSibling).toHaveTextContent(SHOW_TEXT);
|
|
});
|
|
|
|
it("renders caret on right", async () => {
|
|
render(
|
|
<RevealButton
|
|
isShowing={false}
|
|
hideText={HIDE_TEXT}
|
|
showText={SHOW_TEXT}
|
|
caretPosition="after"
|
|
/>
|
|
);
|
|
|
|
const icon = screen.queryByTestId("chevron-down-icon");
|
|
|
|
expect(icon?.previousSibling).toHaveTextContent(SHOW_TEXT);
|
|
});
|
|
|
|
it("renders tooltip on hover if provided", async () => {
|
|
const { user } = renderWithSetup(
|
|
<RevealButton
|
|
isShowing={false}
|
|
hideText={HIDE_TEXT}
|
|
showText={SHOW_TEXT}
|
|
caretPosition="before"
|
|
tooltipContent={TOOLTIP_CONTENT}
|
|
/>
|
|
);
|
|
|
|
await user.hover(screen.getByText(SHOW_TEXT));
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText(TOOLTIP_CONTENT)).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|