-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/orbit-components/src/Tooltip/Tooltip.ct-story.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from "react"; | ||
import cx from "clsx"; | ||
|
||
import { PLACEMENTS } from "../common/placements"; | ||
import { tooltipContentCtStory } from "../primitives/TooltipPrimitive/TooltipPrimitive.ct-story"; | ||
import Stack from "../Stack"; | ||
import { Icons } from "../.."; | ||
import type { Props, Size } from "./types"; | ||
|
||
import Tooltip from "."; | ||
|
||
type TooltipPrimitiveProps = Pick<Props, "placement" | "block">; | ||
|
||
export function DefaultTooltip({ placement = PLACEMENTS.BOTTOM, block }: TooltipPrimitiveProps) { | ||
return ( | ||
<div | ||
className={cx([ | ||
"lm:min-h-[300px] flex min-h-[650px]", | ||
placement === "top" ? "items-end" : "items-start", | ||
(placement === "left" || placement === "right") && "items-center", | ||
])} | ||
> | ||
<Stack justify={placement === "left" ? "end" : "start"}> | ||
<Tooltip content={tooltipContentCtStory} placement={placement} block={block}> | ||
<Icons.Airplane /> | ||
</Tooltip> | ||
</Stack> | ||
</div> | ||
); | ||
} | ||
|
||
export function TooltipWithImage({ size = "medium" }: { size?: Size }) { | ||
return ( | ||
<div className="lm:min-h-[500px] min-h-[650px]"> | ||
<Stack justify="center"> | ||
<Tooltip | ||
size={size} | ||
content={ | ||
<Stack> | ||
<img | ||
src="https://images.kiwi.com/illustrations/0x200/Rating-Q85.png" | ||
alt="Preview of card help in TooltipPrimitive component" | ||
/> | ||
{tooltipContentCtStory} | ||
</Stack> | ||
} | ||
> | ||
<Icons.Airplane /> | ||
</Tooltip> | ||
</Stack> | ||
</div> | ||
); | ||
} |
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,104 @@ | ||
import * as React from "react"; | ||
import { test, expect } from "@playwright/experimental-ct-react"; | ||
import { defaultTokens } from "@kiwicom/orbit-design-tokens"; | ||
|
||
import { DefaultTooltip, TooltipWithImage } from "./Tooltip.ct-story"; | ||
import type { Placement } from "../common/placements"; | ||
import type { Size } from "../primitives/TooltipPrimitive/types"; | ||
|
||
const skipIfViewportSmallerThan = (viewport, width, message) => { | ||
test.skip(viewport !== null && viewport.width < width, message); | ||
}; | ||
|
||
const skipIfViewportLargerThanOrEqual = (viewport, width, message) => { | ||
test.skip(viewport !== null && viewport.width >= width, message); | ||
}; | ||
|
||
test.describe("Tooltip visual tests", () => { | ||
const { breakpointLargeMobile } = defaultTokens; | ||
|
||
const placements = ["top", "right", "bottom", "left"]; | ||
const sizes: Size[] = ["small", "medium"]; | ||
|
||
placements.forEach(placement => { | ||
test(`screenshot for default - ${placement} - desktop`, async ({ mount, viewport }) => { | ||
skipIfViewportSmallerThan( | ||
viewport, | ||
breakpointLargeMobile, | ||
"This feature is largeMobile, tablet and desktop only", | ||
); | ||
|
||
const component = await mount(<DefaultTooltip placement={placement as Placement} />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); | ||
|
||
sizes.forEach(size => { | ||
test(`screenshot with image inside - ${size} on desktop`, async ({ mount, viewport }) => { | ||
skipIfViewportSmallerThan( | ||
viewport, | ||
breakpointLargeMobile, | ||
"This feature is largeMobile, tablet and desktop only", | ||
); | ||
|
||
const component = await mount(<TooltipWithImage size={size} />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); | ||
|
||
test(`screenshot - block tooltip on desktop`, async ({ mount, viewport }) => { | ||
skipIfViewportSmallerThan( | ||
viewport, | ||
breakpointLargeMobile, | ||
"This feature is largeMobile, tablet and desktop only", | ||
); | ||
|
||
const component = await mount(<DefaultTooltip block />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
// Tests below cover mobile views - the tooltip is visible on click. | ||
placements.forEach(placement => { | ||
test(`screenshot for default - ${placement} on mobile`, async ({ mount, viewport, page }) => { | ||
skipIfViewportLargerThanOrEqual( | ||
viewport, | ||
breakpointLargeMobile, | ||
"This feature is small and medium mobile only", | ||
); | ||
|
||
const component = await mount(<DefaultTooltip placement={placement as Placement} />); | ||
|
||
const tooltip = await page.getByRole("tooltip"); | ||
|
||
await component.getByRole("button").click(); | ||
|
||
await expect(tooltip).toBeVisible(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); | ||
|
||
sizes.forEach(size => { | ||
test(`screenshot with image inside - ${size} on mobile`, async ({ mount, viewport, page }) => { | ||
skipIfViewportLargerThanOrEqual( | ||
viewport, | ||
breakpointLargeMobile, | ||
"This feature is small and medium mobile only", | ||
); | ||
|
||
const component = await mount(<TooltipWithImage size={size} />); | ||
|
||
const tooltip = await page.getByRole("tooltip"); | ||
|
||
await component.getByRole("button").click(); | ||
|
||
await expect(tooltip).toBeVisible(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); | ||
}); |