Some checks failed
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Failing after 1m46s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Migration 015 für Backlog sort_order; DnD auf Desktop, Pfeile auf Mobile; PATCH-Batches für Geschwister. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
computeDropPatches,
|
|
computeMovePatches,
|
|
computeReorderPatches,
|
|
sortByOrder,
|
|
} from './reorder.js'
|
|
|
|
const items = [
|
|
{ id: 'a', sort_order: 0 },
|
|
{ id: 'b', sort_order: 10 },
|
|
{ id: 'c', sort_order: 20 },
|
|
]
|
|
|
|
describe('reorder', () => {
|
|
it('sorts by sort_order then id', () => {
|
|
const unsorted = [
|
|
{ id: 'c', sort_order: 20 },
|
|
{ id: 'a', sort_order: 0 },
|
|
{ id: 'b', sort_order: 10 },
|
|
]
|
|
expect(sortByOrder(unsorted).map((i) => i.id)).toEqual(['a', 'b', 'c'])
|
|
})
|
|
|
|
it('computes patches when moving down', () => {
|
|
const patches = computeMovePatches(items, 'a', 'down')
|
|
expect(patches).toEqual(
|
|
expect.arrayContaining([
|
|
{ id: 'a', sort_order: 10 },
|
|
{ id: 'b', sort_order: 0 },
|
|
]),
|
|
)
|
|
expect(patches).toHaveLength(2)
|
|
})
|
|
|
|
it('computes patches for drag drop', () => {
|
|
const patches = computeDropPatches(items, 'c', 'a')
|
|
expect(patches).toEqual([
|
|
{ id: 'c', sort_order: 0 },
|
|
{ id: 'a', sort_order: 10 },
|
|
{ id: 'b', sort_order: 20 },
|
|
])
|
|
})
|
|
|
|
it('returns empty when indices unchanged', () => {
|
|
expect(computeReorderPatches(items, 1, 1)).toEqual([])
|
|
})
|
|
})
|