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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stories rework: VaSlider #4183

Merged
merged 2 commits into from
Mar 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/ui/.storybook/interaction-utils/storySelector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function getStoryId(id: string): HTMLElement {
return document.querySelector(`[data-testid="${id}"]`) as HTMLElement
}

export function getStoryIdAll(id: string): NodeListOf<HTMLElement> {
return document.querySelectorAll(`[data-testid="${id}"]`)
}

export function getStorySelector(selector: string): HTMLElement {
return document.querySelector(selector) as HTMLElement
}

export function getStorySelectorAll(selector: string): NodeListOf<HTMLElement> {
return document.querySelectorAll(selector)
}
12 changes: 7 additions & 5 deletions packages/ui/.storybook/interaction-utils/userEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import { userEvent as event } from '@storybook/testing-library'
import { sleep } from '../../src/utils/sleep'

export const userEvent = {
click: async (element: Element, options?: { delay?: number }) => {
const defaultOptions = { delay: 0 }
click: async (element: Element, options?: { delay?: number, clientX?: number, clientY?: number, skipPointerEventsCheck?: boolean }) => {
const defaultOptions = { delay: 0, skipPointerEventsCheck: false }
const mergedOptions = { ...defaultOptions, ...options }
const { delay, skipPointerEventsCheck } = mergedOptions

event.click(element, undefined, { skipHover: true })
event.click(element, options, { skipHover: true, skipPointerEventsCheck })
// waiting for DOM changes
await sleep(mergedOptions.delay)
await sleep(delay)
},

type: async (element: Element, text: string, options?: { sleep?: boolean, delay?: number }) => {
const defaultOptions = { sleep: true, delay: 0 }
const mergedOptions = { ...defaultOptions, ...options }
const { sleep: boolSleep, delay } = mergedOptions

event.type(element, text)
// waiting for DOM changes
if(mergedOptions.sleep) await sleep(mergedOptions.delay)
if(boolSleep) await sleep(delay)
},

hover: async (element: Element, options?: { delay?: number }) => {
Expand Down