You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test-utils.ts 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Data } from 'types'
  2. import { getSelectedIds } from 'utils'
  3. export const rectangleId = '1f6c251c-e12e-40b4-8dd2-c1847d80b72f'
  4. export const arrowId = '5ca167d7-54de-47c9-aa8f-86affa25e44d'
  5. interface PointerOptions {
  6. id?: string
  7. x?: number
  8. y?: number
  9. shiftKey?: boolean
  10. altKey?: boolean
  11. ctrlKey?: boolean
  12. }
  13. export function point(
  14. options: PointerOptions = {} as PointerOptions
  15. ): PointerEvent {
  16. const {
  17. id = '1',
  18. x = 0,
  19. y = 0,
  20. shiftKey = false,
  21. altKey = false,
  22. ctrlKey = false,
  23. } = options
  24. return {
  25. shiftKey,
  26. altKey,
  27. ctrlKey,
  28. pointerId: id,
  29. clientX: x,
  30. clientY: y,
  31. } as any
  32. }
  33. export function idsAreSelected(
  34. data: Data,
  35. ids: string[],
  36. strict = true
  37. ): boolean {
  38. const selectedIds = getSelectedIds(data)
  39. return (
  40. (strict ? selectedIds.size === ids.length : true) &&
  41. ids.every((id) => selectedIds.has(id))
  42. )
  43. }
  44. export async function asyncDelay<T>(fn: () => T): Promise<T> {
  45. return new Promise((resolve) => {
  46. setTimeout(() => {
  47. resolve(fn())
  48. }, 100)
  49. })
  50. }