From d21bd67bf347d21e5e91ec0f5af8881eac7e07ac Mon Sep 17 00:00:00 2001 From: Sarka Chwastkova Date: Wed, 6 Nov 2024 16:36:31 +0100 Subject: [PATCH] test(Tooltip): add visual tests --- .../src/Tooltip/Tooltip.ct-story.tsx | 16 +++++++ .../src/Tooltip/Tooltip.ct.tsx | 47 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 packages/orbit-components/src/Tooltip/Tooltip.ct-story.tsx create mode 100644 packages/orbit-components/src/Tooltip/Tooltip.ct.tsx diff --git a/packages/orbit-components/src/Tooltip/Tooltip.ct-story.tsx b/packages/orbit-components/src/Tooltip/Tooltip.ct-story.tsx new file mode 100644 index 0000000000..7abece0001 --- /dev/null +++ b/packages/orbit-components/src/Tooltip/Tooltip.ct-story.tsx @@ -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 ( +
+ + Tooltip. + +
+ ); +} diff --git a/packages/orbit-components/src/Tooltip/Tooltip.ct.tsx b/packages/orbit-components/src/Tooltip/Tooltip.ct.tsx new file mode 100644 index 0000000000..0f5985d7be --- /dev/null +++ b/packages/orbit-components/src/Tooltip/Tooltip.ct.tsx @@ -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(); + + 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(); + + const tooltip = await page.getByRole("tooltip"); + + await component.getByRole("button").click(); + + await expect(tooltip).toBeVisible(); + await expect(component).toHaveScreenshot(); + }); +});