/* eslint-env jest */ import { nextSort } from '../sort'; import { timeAgo } from '../time-ago'; type Column = 'title' | 'date' | 'hits'; describe('a click on a column', () => { it('turns the same column the other way, both ways', () => { const titleUp = nextSort({ by: 'date', order: 'desc' }, 'title', [ 'title', ]); expect(titleUp).toEqual({ by: 'title', order: 'asc' }); const titleDown = nextSort(titleUp, 'title', ['title']); expect(titleDown).toEqual({ by: 'title', order: 'desc' }); expect(nextSort(titleDown, 'title', ['title'])).toEqual({ by: 'title', order: 'asc', }); }); it('starts a new column the way it reads best', () => { expect( nextSort({ by: 'title', order: 'asc' }, 'hits', ['title']) ).toEqual({ by: 'hits', order: 'desc' }); }); }); describe('when a link was checked', () => { const now = Date.parse('2026-09-28T12:00:00Z'); it('reads in words', () => { expect(timeAgo('2026-09-28T11:59:40Z', now)).toBe('just now'); expect(timeAgo('2026-09-28T11:45:00Z', now)).toBe('15 min ago'); expect(timeAgo('2026-09-28T07:00:00Z', now)).toBe('5 h ago'); expect(timeAgo('2026-09-27T09:00:00Z', now)).toBe('yesterday'); expect(timeAgo('2026-09-24T09:00:00Z', now)).toBe('4 days ago'); expect(timeAgo('not a date', now)).toBe(''); }); });