import { beforeEach, describe, expect, it } from 'vitest'
import { setLocale } from '@/i18n/index.js'
import { intervalText, recallInText } from '@/utils/recall.js'
beforeEach(() => setLocale('en'))
describe('intervalText', () => {
it('keeps minutes when the span is not whole hours', () => {
expect(intervalText(1800)).toBe('30 min')
expect(intervalText(90)).toBe('2 min')
})
it('uses hours and days for whole values', () => {
expect(intervalText(7200)).toBe('2 h')
expect(intervalText(172800)).toBe('2 d')
})
})
describe('recallInText', () => {
const now = new Date('2026-11-02T12:00:00Z').getTime()
it('counts down from the given moment', () => {
expect(recallInText('2026-11-02T12:25:00Z', now)).toBe('in 25 min')
})
it('does not go negative once the time has passed', () => {
expect(recallInText('2026-11-02T11:59:00Z', now)).toBe('any moment now')
})
it('says less than a minute rather than "0 min"', () => {
expect(recallInText('2026-11-02T12:00:45Z', now)).toBe('in under a minute')
})
it('picks hours and days instead of counting out thousands of minutes', () => {
expect(recallInText('2026-11-02T15:00:00Z', now)).toBe('in 3 h')
expect(recallInText('2026-12-02T12:00:00Z', now)).toBe('in 30 d')
})
})