import { describe, expect, it } from 'vitest'; import { dropIndex, neighborsForMove } from './reorder'; const ids = ['A', 'B', 'C', 'D']; describe('neighborsForMove (issue #45)', () => { it('moves up one: D between B and C', () => { // D at index 3 → newIndex 2 in the without-array [A, B, C]. expect(neighborsForMove(ids, 'D', 2)).toEqual({ afterId: 'B', beforeId: 'C' }); }); it('moves to the top: afterId null', () => { expect(neighborsForMove(ids, 'C', 0)).toEqual({ afterId: null, beforeId: 'A' }); }); it('moves to the bottom: beforeId null', () => { expect(neighborsForMove(ids, 'A', 3)).toEqual({ afterId: 'D', beforeId: null }); }); it('clamps an out-of-range index', () => { expect(neighborsForMove(ids, 'A', 99)).toEqual({ afterId: 'D', beforeId: null }); expect(neighborsForMove(ids, 'A', -5)).toEqual({ afterId: null, beforeId: 'B' }); }); }); describe('dropIndex (issue #45)', () => { it('drops before the target by default', () => { // Drop A onto C (upper half) → before C. without = [B, C, D], C at 1. expect(dropIndex(ids, 'A', 'C', false)).toBe(1); }); it('drops after the target on the lower half — reaches the bottom', () => { // Drop A onto D lower half → after D. without = [B, C, D], D at 2 → 3 (end). expect(dropIndex(ids, 'A', 'D', true)).toBe(3); }); });