import type { SensorContext } from '@dnd-kit/core' import { KeyboardCode } from '@dnd-kit/core' import { coordinatesFactory } from './coordinates' import type { Coordinates } from '@dnd-kit/utilities' describe('coordinates', () => { let coordinates: ReturnType let currentCoordinates: Coordinates let context: SensorContext beforeEach(() => { coordinates = coordinatesFactory(46) currentCoordinates = { x: 25, y: 100 } context = {} as any }) describe('without a modifier key', () => { it('should move up by half a row', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Up }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: 25, y: 77, }) }) it('should move down by half a row', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Down, }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: 25, y: 123, }) }) it('should move left by size.small', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Left, }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: -11, y: 100, }) }) it('should move right by size.small', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Right, }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: 61, y: 100, }) }) }) describe('with a modifier key', () => { it('should move up by 1.5 rows', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Up, metaKey: true, }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: 25, y: 31, }) }) it('should move down by 1.5 rows', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Down, metaKey: true, }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: 25, y: 169, }) }) it('should move left by 3 x size.small', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Left, metaKey: true, }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: -83, y: 100, }) }) it('should move right by 3 x size.small', () => { const evt = new KeyboardEvent('keypress', { code: KeyboardCode.Right, metaKey: true, }) const res = coordinates(evt, { currentCoordinates, active: '1', context, }) expect(res).toEqual({ x: 133, y: 100, }) }) }) })