-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a63e70e
commit 035acf2
Showing
5 changed files
with
158 additions
and
21 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.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,78 @@ | ||
import { expect, test } from "../../playwright/a11y"; | ||
import type { Locator } from "@playwright/test"; | ||
import { executeMatrixScreenshotTest } from "../../playwright/screenshots"; | ||
import OnyxInfoTooltip from "./OnyxInfoTooltip.vue"; | ||
|
||
test("should trigger with hover", async ({ mount, page }) => { | ||
// ARRANGE | ||
let component = await mount(OnyxInfoTooltip, { | ||
props: { | ||
text: "Test tooltip", | ||
}, | ||
}); | ||
|
||
let tooltip = component.getByRole("tooltip"); | ||
|
||
// ASSERT | ||
await expect(tooltip).toBeHidden(); | ||
|
||
// ACT | ||
await component.hover(); | ||
|
||
// ASSERT | ||
await expect(tooltip).toBeHidden(); // should use debounce to show tooltip only after a short delay | ||
await expect(tooltip).toBeVisible(); | ||
|
||
await page.mouse.move(0, 0); | ||
await expect(tooltip).toBeVisible(); // should use debounce to hide tooltip only after a short delay | ||
await expect(tooltip).toBeHidden(); | ||
|
||
// ACT | ||
await component.unmount(); | ||
component = await mount(<OnyxInfoTooltip text="Test tooltip" />); | ||
tooltip = component.getByRole("tooltip"); | ||
|
||
await page.keyboard.press("Tab"); | ||
|
||
// ASSERT | ||
await expect(tooltip).toBeVisible(); | ||
|
||
// ACT | ||
await page.keyboard.press("Escape"); | ||
|
||
// ASSERT | ||
await expect(tooltip).toBeHidden(); | ||
}); | ||
|
||
test.describe("Screenshot tests", () => { | ||
const isTooltipVisible = async (tooltip: Locator) => { | ||
await expect(tooltip).toBeVisible(); | ||
}; | ||
|
||
executeMatrixScreenshotTest({ | ||
name: "Info Tooltip", | ||
columns: ["default", "long-text"], | ||
rows: ["default", "bottom"], | ||
component: (column, row) => { | ||
return ( | ||
<OnyxInfoTooltip | ||
text={column === "long-text" ? "Lorem ipsum dolor sit amet " : "Test tooltip"} | ||
position={row === "bottom" ? "bottom" : "top"} | ||
/> | ||
); | ||
}, | ||
// set component size to fully include the tooltip | ||
beforeScreenshot: async (component, page, _column, _row) => { | ||
const tooltip = page.getByRole("tooltip"); | ||
|
||
// set paddings to fit the full tooltip in the screenshot | ||
await component.evaluate((element) => { | ||
element.style.padding = `3rem 5rem`; | ||
}); | ||
|
||
await component.hover(); | ||
|
||
await isTooltipVisible(tooltip); | ||
}, | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.stories.ts
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,35 @@ | ||
import { defineStorybookActionsAndVModels } from "@sit-onyx/storybook-utils"; | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
import OnyxInfoTooltip from "./OnyxInfoTooltip.vue"; | ||
|
||
/** | ||
* Info tooltips offer contextual information or additional details while hovering an info icon. | ||
*/ | ||
const meta: Meta<typeof OnyxInfoTooltip> = { | ||
title: "support/InfoTooltip", | ||
...defineStorybookActionsAndVModels({ | ||
component: OnyxInfoTooltip, | ||
events: [], | ||
decorators: [ | ||
(story) => ({ | ||
components: { story }, | ||
template: ` | ||
<div style="padding: 4rem 6rem; font-family: var(--onyx-font-family); color: var(--onyx-color-text-icons-neutral-intense)"> | ||
<story /> | ||
</div>`, | ||
}), | ||
], | ||
}), | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof OnyxInfoTooltip>; | ||
|
||
/** | ||
* This example shows a default tooltip. | ||
*/ | ||
export const Default = { | ||
args: { | ||
text: "Info tooltip text", | ||
}, | ||
} satisfies Story; |
38 changes: 38 additions & 0 deletions
38
packages/sit-onyx/src/components/OnyxInfoTooltip/OnyxInfoTooltip.vue
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,38 @@ | ||
<script lang="ts" setup> | ||
import OnyxIcon from "../OnyxIcon/OnyxIcon.vue"; | ||
import circleInformation from "@sit-onyx/icons/circle-information.svg?raw"; | ||
import OnyxTooltip from "../OnyxTooltip/OnyxTooltip.vue"; | ||
import type { OnyxInfoTooltipProps } from "./types"; | ||
import { injectI18n } from "../../i18n"; | ||
const props = defineProps<OnyxInfoTooltipProps>(); | ||
const { t } = injectI18n(); | ||
</script> | ||
|
||
<template> | ||
<OnyxTooltip | ||
v-if="props.text" | ||
class="onyx-info-tooltip" | ||
:text="props.text" | ||
:position="props.position" | ||
> | ||
<button :aria-label="t('showInfoTooltip')" class="onyx-info-tooltip__trigger"> | ||
<OnyxIcon :icon="circleInformation" color="neutral" size="12px" /> | ||
</button> | ||
</OnyxTooltip> | ||
</template> | ||
|
||
<style lang="scss"> | ||
@use "../../styles/mixins/layers"; | ||
.onyx-info-tooltip { | ||
@include layers.component() { | ||
&__trigger { | ||
border: none; | ||
background-color: transparent; | ||
padding: 0; | ||
margin-left: var(--onyx-spacing-2xs); | ||
} | ||
} | ||
} | ||
</style> |
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,3 @@ | ||
import type { OnyxTooltipProps } from "../OnyxTooltip/types"; | ||
|
||
export type OnyxInfoTooltipProps = Pick<OnyxTooltipProps, "text" | "position">; |
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