diff --git a/src/components/tasks/task-schedule-dialog.test.tsx b/src/components/tasks/task-schedule-dialog.test.tsx index 68d41beca8..2211c063f0 100644 --- a/src/components/tasks/task-schedule-dialog.test.tsx +++ b/src/components/tasks/task-schedule-dialog.test.tsx @@ -7,7 +7,7 @@ import { render, screen, waitFor } from "@testing-library/react" import userEvent from "@testing-library/user-event" import { NextIntlClientProvider } from "next-intl" -import { beforeEach, describe, expect, it, vi } from "vitest" +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest" import enMessages from "@/i18n/messages/en.json" import { formatScheduleDay, toDateTimeLocalValue } from "@/lib/task-schedule" import type { WorkTask } from "@/lib/types" @@ -67,6 +67,15 @@ async function pickDay(day: Date) { beforeEach(() => { scheduleMock.mockClear() + // Pin "today" to mid-month: this calendar opens on the current month, so a + // wall-clock run on a month's last days can look for a day cell (+2) outside + // the grid. Fake only Date so userEvent and waitFor keep using real timers. + vi.useFakeTimers({ toFake: ["Date"] }) + vi.setSystemTime(new Date(2026, 6, 15, 12, 0)) +}) + +afterEach(() => { + vi.useRealTimers() }) describe("TaskScheduleDialog", () => { diff --git a/src/components/token-usage/token-usage-filters.test.tsx b/src/components/token-usage/token-usage-filters.test.tsx index 2e0c04fb89..9c23dbdb92 100644 --- a/src/components/token-usage/token-usage-filters.test.tsx +++ b/src/components/token-usage/token-usage-filters.test.tsx @@ -9,7 +9,7 @@ import { useState } from "react" import { render, screen, waitFor } from "@testing-library/react" import userEvent from "@testing-library/user-event" import { NextIntlClientProvider } from "next-intl" -import { describe, expect, it, vi } from "vitest" +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest" import enMessages from "@/i18n/messages/en.json" import { toLocalDayValue } from "@/lib/token-usage" import { CustomRangeFields } from "./token-usage-filters" @@ -92,6 +92,18 @@ function lastMonthDay(n: number): Date { } describe("CustomRangeFields", () => { + beforeEach(() => { + // Pin "today" to mid-month: the calendar renders a two-month window ending + // this month, so tomorrow can fall outside the grid near month-end. + // Fake only Date so userEvent and waitFor keep using real timers. + vi.useFakeTimers({ toFake: ["Date"] }) + vi.setSystemTime(new Date(2026, 6, 15, 12, 0)) + }) + + afterEach(() => { + vi.useRealTimers() + }) + it("shows a placeholder until a range is picked", () => { renderFields() expect(pill()).toHaveTextContent("Pick a date range")