-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(TooltipPrimitive): add visual tests
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.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,84 @@ | ||
import React from "react"; | ||
import cx from "clsx"; | ||
|
||
import { PLACEMENTS } from "../../common/placements"; | ||
import Stack from "../../Stack"; | ||
import Text from "../../Text"; | ||
// import TextLink from "../../TextLink"; | ||
// import List, { ListItem } from "../../List"; | ||
import { Icons } from "../.."; | ||
import type { Props, Size } from "./types"; | ||
|
||
import TooltipPrimitive from "."; | ||
|
||
export const tooltipContentCtStory = ( | ||
<Stack> | ||
<Text> | ||
We take security very seriously. Especially when it comes to your personal and sensitive | ||
details. | ||
</Text> | ||
{/* <List> | ||
<ListItem> | ||
A common variant, especially in older software, is displaying a description. | ||
</ListItem> | ||
<ListItem> | ||
A common variant, especially in older software, is displaying a description.{" "} | ||
<TextLink href="#">More info.</TextLink> | ||
</ListItem> | ||
</List> */} | ||
</Stack> | ||
); | ||
|
||
type TooltipPrimitiveProps = Pick<Props, "placement" | "block" | "error" | "help">; | ||
|
||
export function DefaultTooltipPrimitive({ | ||
placement = PLACEMENTS.BOTTOM, | ||
error, | ||
help, | ||
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.includes("left") ? "end" : "start"}> | ||
<TooltipPrimitive | ||
content={tooltipContentCtStory} | ||
placement={placement} | ||
error={error} | ||
help={help} | ||
block={block} | ||
> | ||
<Icons.Airplane /> | ||
</TooltipPrimitive> | ||
</Stack> | ||
</div> | ||
); | ||
} | ||
|
||
export function TooltipPrimitiveWithImage({ size = "medium" }: { size?: Size }) { | ||
return ( | ||
<div className="lm:min-h-[500px] min-h-[650px]"> | ||
<Stack justify="center"> | ||
<TooltipPrimitive | ||
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 /> | ||
</TooltipPrimitive> | ||
</Stack> | ||
</div> | ||
); | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.ct.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,50 @@ | ||
import * as React from "react"; | ||
import { test, expect } from "@playwright/experimental-ct-react"; | ||
|
||
import type { Size } from "./types"; | ||
import { DefaultTooltipPrimitive, TooltipPrimitiveWithImage } from "./TooltipPrimitive.ct-story"; | ||
import type { Placement } from "../../common/placements"; | ||
|
||
test.describe("Tooltip primitive visual tests", () => { | ||
const placements = ["top", "right", "bottom", "left"]; | ||
|
||
placements.forEach(placement => { | ||
test(`screenshot for default - ${placement}`, async ({ mount }) => { | ||
const component = await mount(<DefaultTooltipPrimitive placement={placement as Placement} />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); | ||
|
||
const sizes: Size[] = ["small", "medium"]; | ||
sizes.forEach(size => { | ||
test(`screenshot with image inside - ${size}`, async ({ mount }) => { | ||
const component = await mount(<TooltipPrimitiveWithImage size={size} />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); | ||
|
||
test(`screenshot - error tooltip primitive`, async ({ mount }) => { | ||
const component = await mount(<DefaultTooltipPrimitive error />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test(`screenshot - help tooltip primitive`, async ({ mount }) => { | ||
const component = await mount(<DefaultTooltipPrimitive help />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test(`screenshot - block tooltip primitive`, async ({ mount }) => { | ||
const component = await mount(<DefaultTooltipPrimitive block />); | ||
|
||
await component.getByRole("button").hover(); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); |