Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

AP-1335 Fix animations not being disabled by SpaceKitProvider #155

Merged
merged 2 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/AbstractTooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ export const AbstractTooltip: React.FC<Props> = ({
hideOnClick,
...props
}) => {
const { disableAnimations } = useSpaceKitProvider();
const {
disableAnimations: disableAnimationsFromProvider,
} = useSpaceKitProvider();
const disableAnimations =
disableAnimationsFromProvider || forceVisibleForTestingOnly;

// TODO: Change cursor to
return (
<>
<TippyStyles />
<Tippy
animation={!disableAnimations ? "shift-away" : undefined}
animation="shift-away"
arrow={false}
hideOnClick={forceVisibleForTestingOnly ? false : hideOnClick}
trigger={forceVisibleForTestingOnly ? "manual" : trigger}
Expand All @@ -49,6 +52,8 @@ export const AbstractTooltip: React.FC<Props> = ({
className={classnames(className, {
"space-kit-relaxed": padding === "relaxed",
})}
duration={disableAnimations ? 0 : props.duration}
updateDuration={disableAnimations ? 0 : props.updateDuration}
>
{children}
</Tippy>
Expand Down
24 changes: 20 additions & 4 deletions src/ConfirmationTooltip/ConfirmationTooltip.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@ test("when child element is clicked, the tooltip is shown", () => {
const tooltipContent = faker.lorem.word();
const interactiveElementText = faker.lorem.word();

const { container, getByText, queryByText } = render(
const { getByText, queryByText } = render(
<SpaceKitProvider disableAnimations>
<ConfirmationTooltip content={tooltipContent}>
<span>{interactiveElementText}</span>
</ConfirmationTooltip>
</SpaceKitProvider>
);

expect(queryByText(tooltipContent)).not.toBeInTheDocument();
userEvent.click(getByText(interactiveElementText));
getByText(tooltipContent);
});

test("when a tooltip is shown, it is removed after a delay", () => {
jest.useFakeTimers();
const tooltipContent = faker.lorem.word();
const interactiveElementText = faker.lorem.word();

const { getByText, queryByText } = render(
<SpaceKitProvider disableAnimations>
<ConfirmationTooltip content={tooltipContent}>
<span>{interactiveElementText}</span>
Expand All @@ -27,7 +45,5 @@ test("when child element is clicked, the tooltip is shown", () => {
getByText(tooltipContent);
jest.runTimersToTime(5000);

expect(
container.closest("body")!.querySelector(".tippy-popper")
).not.toBeVisible();
expect(queryByText(tooltipContent)).not.toBeInTheDocument();
});