Tofu/tests/dates/formatWeekRange.test.js

26 lines
977 B
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { formatWeekRange } from '#tofu/tools/dates/formatWeekRange.js'
test('names a week held inside a single month', () => {
assert.equal(formatWeekRange(new Date(2026, 8, 21)), 'Semaine du 21 au 27 septembre')
})
test('names both months when the week spans two months', () => {
assert.equal(formatWeekRange(new Date(2025, 8, 29)), 'Semaine du 29 septembre au 5 octobre')
})
test('adds both years when the week spans two years', () => {
assert.equal(formatWeekRange(new Date(2025, 11, 29)), 'Semaine du 29 décembre 2025 au 4 janvier 2026')
})
test('ignores the time of day', () => {
assert.equal(formatWeekRange(new Date(2026, 8, 21, 22, 30)), 'Semaine du 21 au 27 septembre')
})
test('does not mutate the received date', () => {
const weekStart = new Date(2026, 8, 21, 10, 0)
const before = weekStart.getTime()
formatWeekRange(weekStart)
assert.equal(weekStart.getTime(), before)
})