2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2022-02-11 11:03:15 +08:00
|
|
|
import { EVENT_CODE } from '@element-plus/constants'
|
2022-01-04 09:15:15 +08:00
|
|
|
import * as Util from '../src/utils'
|
|
|
|
|
|
|
|
describe('util', () => {
|
|
|
|
it('should be able to fetch focusIntent', () => {
|
|
|
|
expect(
|
|
|
|
Util.getFocusIntent(
|
|
|
|
new KeyboardEvent('mousedown', {
|
|
|
|
key: EVENT_CODE.enter,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
).toBe(undefined)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
Util.getFocusIntent(
|
|
|
|
new KeyboardEvent('mousedown', {
|
|
|
|
key: EVENT_CODE.left,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
).toBe('prev')
|
|
|
|
|
|
|
|
expect(
|
|
|
|
Util.getFocusIntent(
|
|
|
|
new KeyboardEvent('mousedown', {
|
|
|
|
key: EVENT_CODE.left,
|
|
|
|
}),
|
|
|
|
'vertical'
|
|
|
|
)
|
|
|
|
).toBeUndefined()
|
|
|
|
expect(
|
|
|
|
Util.getFocusIntent(
|
|
|
|
new KeyboardEvent('mousedown', {
|
|
|
|
key: EVENT_CODE.up,
|
|
|
|
}),
|
|
|
|
'horizontal'
|
|
|
|
)
|
|
|
|
).toBeUndefined()
|
|
|
|
|
|
|
|
expect(
|
|
|
|
Util.getFocusIntent(
|
|
|
|
new KeyboardEvent('mousedown', {
|
|
|
|
key: EVENT_CODE.left,
|
|
|
|
}),
|
|
|
|
'horizontal',
|
|
|
|
'rtl'
|
|
|
|
)
|
|
|
|
).toBe('next')
|
|
|
|
|
|
|
|
expect(
|
|
|
|
Util.getFocusIntent(
|
|
|
|
new KeyboardEvent('mousedown', {
|
|
|
|
key: EVENT_CODE.right,
|
|
|
|
}),
|
|
|
|
'horizontal',
|
|
|
|
'rtl'
|
|
|
|
)
|
|
|
|
).toBe('prev')
|
|
|
|
|
|
|
|
expect(
|
|
|
|
Util.getFocusIntent(
|
|
|
|
new KeyboardEvent('mousedown', {
|
|
|
|
key: EVENT_CODE.up,
|
|
|
|
}),
|
|
|
|
'vertical',
|
|
|
|
'rtl'
|
|
|
|
)
|
|
|
|
).toBe('prev')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should reorder array at index X', () => {
|
|
|
|
expect(Util.reorderArray([1, 2, 3, 4], 2)).toStrictEqual([3, 4, 1, 2])
|
|
|
|
})
|
|
|
|
})
|