- 255 tests across 14 files (was 70 tests in 4 files) - src/services/__tests__: auth (registerUser, updateUserPassword, updateUserProfile), okrs (calculateOKRProgress, createOKR, updateKeyResult, updateOKR), teams (createTeam, addTeamMember, isAdminOfUser, getTeamMemberIdsForAdminTeams, getUserTeams), weather (getPreviousWeatherEntriesForUsers, shareWeatherSessionToTeam, getWeatherSessionsHistory), workshops (createSwotItem, duplicateSwotItem, updateAction, createMotivatorSession, updateCardInfluence, addGifMoodItem, shareGifMoodSessionToTeam, getLatestEventTimestamp, cleanupOldEvents) - src/lib/__tests__: date-utils, weather-utils, okr-utils, gravatar, workshops, share-utils - Update vitest coverage to include src/lib/** Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
118 lines
4.6 KiB
TypeScript
118 lines
4.6 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
||
import { getISOWeek, getWeekYearLabel, getWeekBounds } from '@/lib/date-utils';
|
||
|
||
// ── getISOWeek ─────────────────────────────────────────────────────────────
|
||
|
||
describe('getISOWeek', () => {
|
||
it('returns week 1 for January 4 (always in ISO week 1)', () => {
|
||
expect(getISOWeek(new Date(2026, 0, 4))).toBe(1);
|
||
expect(getISOWeek(new Date(2024, 0, 4))).toBe(1);
|
||
});
|
||
|
||
it('returns week 1 for Jan 1 when Jan 1 is Thursday (2026)', () => {
|
||
// Jan 1, 2026 is a Thursday → week 1
|
||
expect(getISOWeek(new Date(2026, 0, 1))).toBe(1);
|
||
});
|
||
|
||
it('returns week 53 for Dec 31 when it falls in last ISO week', () => {
|
||
// Dec 31, 2020 is a Thursday → week 53 of 2020
|
||
expect(getISOWeek(new Date(2020, 11, 31))).toBe(53);
|
||
});
|
||
|
||
it('returns correct week for a known mid-year date', () => {
|
||
// Mar 10, 2026 is in week 11
|
||
expect(getISOWeek(new Date(2026, 2, 10))).toBe(11);
|
||
});
|
||
|
||
it('returns week 52 for Dec 28 (always in ISO week 52 or 53)', () => {
|
||
// Dec 28 is always in the last week of the year per ISO
|
||
const week = getISOWeek(new Date(2026, 11, 28));
|
||
expect(week).toBeGreaterThanOrEqual(52);
|
||
});
|
||
|
||
it('week advances by 1 between consecutive Mondays', () => {
|
||
const w1 = getISOWeek(new Date(2026, 2, 9)); // Monday March 9
|
||
const w2 = getISOWeek(new Date(2026, 2, 16)); // Monday March 16
|
||
expect(w2 - w1).toBe(1);
|
||
});
|
||
|
||
it('same week for all days Monday through Saturday of a given week', () => {
|
||
// Week of March 9–15, 2026
|
||
const week = getISOWeek(new Date(2026, 2, 9)); // Monday
|
||
expect(getISOWeek(new Date(2026, 2, 10))).toBe(week); // Tuesday
|
||
expect(getISOWeek(new Date(2026, 2, 11))).toBe(week); // Wednesday
|
||
expect(getISOWeek(new Date(2026, 2, 14))).toBe(week); // Saturday
|
||
});
|
||
});
|
||
|
||
// ── getWeekYearLabel ──────────────────────────────────────────────────────
|
||
|
||
describe('getWeekYearLabel', () => {
|
||
it('formats as "S{NN}-{YYYY}"', () => {
|
||
const label = getWeekYearLabel(new Date(2026, 2, 10));
|
||
expect(label).toMatch(/^S\d{2}-\d{4}$/);
|
||
});
|
||
|
||
it('returns "S11-2026" for March 10 2026', () => {
|
||
expect(getWeekYearLabel(new Date(2026, 2, 10))).toBe('S11-2026');
|
||
});
|
||
|
||
it('zero-pads single-digit week numbers', () => {
|
||
// Jan 4, 2026 is week 1
|
||
expect(getWeekYearLabel(new Date(2026, 0, 4))).toBe('S01-2026');
|
||
});
|
||
});
|
||
|
||
// ── getWeekBounds ─────────────────────────────────────────────────────────
|
||
|
||
describe('getWeekBounds', () => {
|
||
it('returns Monday as start for a Wednesday', () => {
|
||
const { start } = getWeekBounds(new Date(2026, 2, 11)); // Wednesday March 11
|
||
expect(start.getDate()).toBe(9);
|
||
expect(start.getMonth()).toBe(2); // March
|
||
expect(start.getFullYear()).toBe(2026);
|
||
});
|
||
|
||
it('returns Sunday as end for a Wednesday', () => {
|
||
const { end } = getWeekBounds(new Date(2026, 2, 11));
|
||
expect(end.getDate()).toBe(15);
|
||
expect(end.getMonth()).toBe(2); // March
|
||
});
|
||
|
||
it('start is at 00:00:00.000', () => {
|
||
const { start } = getWeekBounds(new Date(2026, 2, 10));
|
||
expect(start.getHours()).toBe(0);
|
||
expect(start.getMinutes()).toBe(0);
|
||
expect(start.getSeconds()).toBe(0);
|
||
expect(start.getMilliseconds()).toBe(0);
|
||
});
|
||
|
||
it('end is at 23:59:59.999', () => {
|
||
const { end } = getWeekBounds(new Date(2026, 2, 10));
|
||
expect(end.getHours()).toBe(23);
|
||
expect(end.getMinutes()).toBe(59);
|
||
expect(end.getSeconds()).toBe(59);
|
||
expect(end.getMilliseconds()).toBe(999);
|
||
});
|
||
|
||
it('start and end are 6 days apart', () => {
|
||
const { start, end } = getWeekBounds(new Date(2026, 2, 10));
|
||
const diffDays = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||
expect(Math.floor(diffDays)).toBe(6);
|
||
});
|
||
|
||
it('returns same bounds for any day within the same week', () => {
|
||
const monday = getWeekBounds(new Date(2026, 2, 9));
|
||
const wednesday = getWeekBounds(new Date(2026, 2, 11));
|
||
const saturday = getWeekBounds(new Date(2026, 2, 14));
|
||
expect(monday.start.getTime()).toBe(wednesday.start.getTime());
|
||
expect(monday.start.getTime()).toBe(saturday.start.getTime());
|
||
expect(monday.end.getTime()).toBe(wednesday.end.getTime());
|
||
});
|
||
|
||
it('returns Monday as start when given a Monday', () => {
|
||
const { start } = getWeekBounds(new Date(2026, 2, 9)); // Monday March 9
|
||
expect(start.getDate()).toBe(9);
|
||
});
|
||
});
|