Something went wrong. Try again.
Explore blocks, labels, lists, and posts on Bluesky. skytrace.aly.town
Something went wrong. Try again.
12345678910111213141516171819202122232425import { expect, it } from 'vitest'import { newestFirst } from '../src/lib/sorting'
it('sorts dates without mutating input and preserves ties and undated item order', () => { const items = [ { kind: 'unavailable', id: 'missing-first' }, { kind: 'post', id: 'older', createdAt: '2026-01-01T00:00:00Z' }, { kind: 'post', id: 'invalid', createdAt: 'invalid' }, { kind: 'post', id: 'newer-first', createdAt: '2026-02-01T00:00:00Z' }, { kind: 'unavailable', id: 'missing-last' }, { kind: 'post', id: 'newer-second', createdAt: '2026-02-01T00:00:00Z' }, ] const original = [...items]
expect(newestFirst(items).map((item) => item.id)).toEqual([ 'newer-first', 'newer-second', 'older', 'missing-first', 'invalid', 'missing-last', ]) expect(items).toEqual(original)})