-
Notifications
You must be signed in to change notification settings - Fork 153
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
96 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
import React from "react"; | ||
|
||
import { PLACEMENTS } from "../../common/placements"; | ||
import Stack from "../../Stack"; | ||
import Text from "../../Text"; | ||
import type { Props } from "./types"; | ||
|
||
import TooltipPrimitive from "."; | ||
|
||
export const tooltipContentCtStory = <Text>Lorem ipsum.</Text>; | ||
|
||
type TooltipPrimitiveProps = Pick<Props, "size" | "removeUnderlinedText" | "error" | "help">; | ||
|
||
export function TooltipPrimitiveVisualDefaultStory({ | ||
size = "medium", | ||
removeUnderlinedText, | ||
error, | ||
help, | ||
}: TooltipPrimitiveProps) { | ||
return ( | ||
<div className="min-h-[96px]"> | ||
<TooltipPrimitive | ||
content={tooltipContentCtStory} | ||
error={error} | ||
help={help} | ||
removeUnderlinedText={removeUnderlinedText} | ||
size={size} | ||
tooltipShown | ||
> | ||
<Text>Tooltip.</Text> | ||
</TooltipPrimitive> | ||
</div> | ||
); | ||
} | ||
|
||
export function TooltipPrimitiveVariousPlacementsStory() { | ||
return ( | ||
<div className="lm:grid-cols-3 mm:grid-cols-2 lm:grid-rows-4 mm:grid-rows-6 lm:min-h-[800px] grid min-h-[1300px] grid-cols-1"> | ||
{Object.values(PLACEMENTS).map(placement => ( | ||
<div className="p-200 relative flex size-full items-center"> | ||
<Stack | ||
justify={ | ||
// eslint-disable-next-line no-nested-ternary | ||
placement.includes("left") ? "end" : placement.includes("right") ? "start" : "center" | ||
} | ||
> | ||
<TooltipPrimitive content={tooltipContentCtStory} placement={placement} tooltipShown> | ||
<Text>Tooltip</Text> | ||
</TooltipPrimitive> | ||
</Stack> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
import * as React from "react"; | ||
import { test, expect } from "@playwright/experimental-ct-react"; | ||
|
||
import { | ||
TooltipPrimitiveVisualDefaultStory, | ||
TooltipPrimitiveVariousPlacementsStory, | ||
} from "./TooltipPrimitive.ct-story"; | ||
|
||
test.describe("Tooltip primitive visual tests", () => { | ||
test(`screenshot for default - various placements`, async ({ mount, page }) => { | ||
const viewportSize = await page.viewportSize(); | ||
|
||
if (viewportSize) { | ||
// Set a new height, keeping the original width | ||
await page.setViewportSize({ width: viewportSize.width, height: 1300 }); | ||
} | ||
|
||
const component = await mount(<TooltipPrimitiveVariousPlacementsStory />); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test(`screenshot for help state`, async ({ mount }) => { | ||
const component = await mount(<TooltipPrimitiveVisualDefaultStory help />); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test(`screenshot for error state`, async ({ mount }) => { | ||
const component = await mount(<TooltipPrimitiveVisualDefaultStory error />); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test(`screenshot for small size`, async ({ mount }) => { | ||
const component = await mount(<TooltipPrimitiveVisualDefaultStory size="small" />); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test(`screenshot for no underline text`, async ({ mount }) => { | ||
const component = await mount(<TooltipPrimitiveVisualDefaultStory removeUnderlinedText />); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
}); |