util.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { describe, expect, it } from 'vitest'
  2. import { EVENT_CODE } from '@element-plus/constants'
  3. import * as Util from '../src/utils'
  4. describe('util', () => {
  5. it('should be able to fetch focusIntent', () => {
  6. expect(
  7. Util.getFocusIntent(
  8. new KeyboardEvent('mousedown', {
  9. key: EVENT_CODE.enter,
  10. })
  11. )
  12. ).toBe(undefined)
  13. expect(
  14. Util.getFocusIntent(
  15. new KeyboardEvent('mousedown', {
  16. key: EVENT_CODE.left,
  17. })
  18. )
  19. ).toBe('prev')
  20. expect(
  21. Util.getFocusIntent(
  22. new KeyboardEvent('mousedown', {
  23. key: EVENT_CODE.left,
  24. }),
  25. 'vertical'
  26. )
  27. ).toBeUndefined()
  28. expect(
  29. Util.getFocusIntent(
  30. new KeyboardEvent('mousedown', {
  31. key: EVENT_CODE.up,
  32. }),
  33. 'horizontal'
  34. )
  35. ).toBeUndefined()
  36. expect(
  37. Util.getFocusIntent(
  38. new KeyboardEvent('mousedown', {
  39. key: EVENT_CODE.left,
  40. }),
  41. 'horizontal',
  42. 'rtl'
  43. )
  44. ).toBe('next')
  45. expect(
  46. Util.getFocusIntent(
  47. new KeyboardEvent('mousedown', {
  48. key: EVENT_CODE.right,
  49. }),
  50. 'horizontal',
  51. 'rtl'
  52. )
  53. ).toBe('prev')
  54. expect(
  55. Util.getFocusIntent(
  56. new KeyboardEvent('mousedown', {
  57. key: EVENT_CODE.up,
  58. }),
  59. 'vertical',
  60. 'rtl'
  61. )
  62. ).toBe('prev')
  63. })
  64. it('should reorder array at index X', () => {
  65. expect(Util.reorderArray([1, 2, 3, 4], 2)).toStrictEqual([3, 4, 1, 2])
  66. })
  67. })