Files
hapi/web/src/lib/attachmentOrder.test.ts
T
AnanovoandGitHub a9d09cb3ff feat(web): support composer attachment drag reordering (#1682)
* feat(web): support composer attachment drag reordering

* fix(web): handle forward attachment reordering

* fix(web): enlarge file attachment touch targets

* fix(web): preserve staged attachment order
2026-08-24 14:27:10 +08:00

20 lines
974 B
TypeScript

import { describe, expect, it } from 'vitest'
import { moveAttachmentId, orderItemsById, reconcileAttachmentOrder } from './attachmentOrder'
describe('attachment order helpers', () => {
it('keeps existing order while appending newly added attachments', () => {
expect(reconcileAttachmentOrder(['b', 'stale', 'a'], ['a', 'b', 'c'])).toEqual(['b', 'a', 'c'])
})
it('moves an attachment immediately before the drop target', () => {
expect(moveAttachmentId(['a', 'b', 'c'], 'a', 'c')).toEqual(['b', 'a', 'c'])
expect(moveAttachmentId(['a', 'b', 'c'], 'c', 'a')).toEqual(['c', 'a', 'b'])
expect(moveAttachmentId(['a', 'b', 'c'], 'a', 'b', 'after')).toEqual(['b', 'a', 'c'])
})
it('orders objects without dropping ids unknown to the order list', () => {
const items = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]
expect(orderItemsById(items, ['c', 'a'])).toEqual([{ id: 'c' }, { id: 'a' }, { id: 'b' }])
})
})