Skip to content

Commit

Permalink
test(TooltipPrimitive): add visual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkaaa committed Nov 11, 2024
1 parent 36193e0 commit dc0155d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
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>
);
}
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();
});
});

0 comments on commit dc0155d

Please sign in to comment.