Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltip/TooltipPrimitive: add visual tests #4508

Merged
merged 3 commits into from
Nov 11, 2024
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
16 changes: 16 additions & 0 deletions packages/orbit-components/src/Tooltip/Tooltip.ct-story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react";

import { tooltipContentCtStory } from "../primitives/TooltipPrimitive/TooltipPrimitive.ct-story";
import Text from "../Text";

import Tooltip from ".";

export function TooltipVisualDefaultStory() {
return (
<div className="lm:min-h-[128px] min-h-[660px]">
<Tooltip content={tooltipContentCtStory}>
<Text>Tooltip.</Text>
</Tooltip>
</div>
);
}
47 changes: 47 additions & 0 deletions packages/orbit-components/src/Tooltip/Tooltip.ct.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from "react";
import { test, expect } from "@playwright/experimental-ct-react";
import { defaultTokens } from "@kiwicom/orbit-design-tokens";

import { TooltipVisualDefaultStory } from "./Tooltip.ct-story";

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;

test(`screenshot for default - desktop`, async ({ mount, viewport }) => {
skipIfViewportSmallerThan(
viewport,
breakpointLargeMobile,
"This feature is largeMobile, tablet and desktop only",
);

const component = await mount(<TooltipVisualDefaultStory />);

await component.getByRole("button").hover();
await expect(component).toHaveScreenshot();
});

test(`screenshot for default - mobile`, async ({ mount, viewport, page }) => {
skipIfViewportLargerThanOrEqual(
viewport,
breakpointLargeMobile,
"This feature is small and medium mobile only",
);

const component = await mount(<TooltipVisualDefaultStory />);

const tooltip = await page.getByRole("tooltip");

await component.getByRole("button").click();

await expect(tooltip).toBeVisible();
await expect(component).toHaveScreenshot();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading