11import userEvent from "@testing-library/user-event" ;
2+ import { rest } from "msw" ;
23import { act } from "react" ;
34import { type Calendar } from "@core/types/calendar.contracts" ;
45import { type CompassEvent } from "@core/types/compass-event.contracts" ;
@@ -13,11 +14,13 @@ import {
1314 waitFor ,
1415 within ,
1516} from "@web/__tests__/__mocks__/mock.render" ;
17+ import { server } from "@web/__tests__/__mocks__/server/mock.server" ;
1618import { createMockEvent } from "@web/__tests__/utils/factories/event.factory" ;
1719import { createCompassQueryClient } from "@web/api/query-client" ;
1820import { calendarQueryKeys } from "@web/calendars/calendar.query" ;
1921import { setCalendarVisibility } from "@web/calendars/calendar-visibility.store" ;
2022import { getLocalCalendarSentinelId } from "@web/calendars/local-calendar.sentinel" ;
23+ import { ENV_WEB } from "@web/common/constants/env.constants" ;
2124import {
2225 DATA_TIMED_GRID_ROW ,
2326 ZIndex ,
@@ -129,6 +132,16 @@ const renderDayCalendarGrid = (calendars?: Calendar[]) => {
129132 const queryClient = createCompassQueryClient ( ) ;
130133 if ( calendars ) {
131134 queryClient . setQueryData ( calendarQueryKeys . all , calendars ) ;
135+ // Seeded fixtures must survive the calendars query mount-fetch. Without
136+ // an MSW handler the failed GET clears the cache and
137+ // filterEventsByVisibleCalendars drops events mid-assertion (common in
138+ // CI). Keep the handler local — a global default breaks suites that
139+ // expect the legacy undefined calendarIds read.
140+ server . use (
141+ rest . get ( `${ ENV_WEB . API_BASEURL } /calendars` , ( _req , res , ctx ) =>
142+ res ( ctx . json ( calendars ) ) ,
143+ ) ,
144+ ) ;
132145 }
133146
134147 return {
@@ -325,7 +338,7 @@ describe("DayCalendarGrid", () => {
325338 expect ( within ( timedGrid ) . getAllByRole ( "columnheader" ) ) . toHaveLength ( 1 ) ;
326339 } ) ;
327340
328- it ( "renders enabled calendars as separate event columns" , async ( ) => {
341+ it ( "renders enabled calendars as separate event columns" , ( ) => {
329342 const primary = makeCalendar ( "Primary" , { isPrimary : true } ) ;
330343 const projects = makeCalendar ( "Projects" ) ;
331344 const hidden = makeCalendar ( "Hidden" ) ;
@@ -372,23 +385,17 @@ describe("DayCalendarGrid", () => {
372385 expect ( within ( headers ) . getByText ( "Projects" ) ) . toBeInTheDocument ( ) ;
373386 expect ( within ( headers ) . queryByText ( "Hidden" ) ) . not . toBeInTheDocument ( ) ;
374387
375- // Column widths settle after measurement/layout; wait so a transient
376- // single-column paint cannot flake the equal-width assertion in CI.
377- await waitFor ( ( ) => {
378- const primaryEvent = screen . getByRole ( "button" , {
379- name : / p r i m a r y e v e n t / i,
380- } ) ;
381- const projectEvent = screen . getByRole ( "button" , {
382- name : / p r o j e c t e v e n t / i,
383- } ) ;
384- expect (
385- screen . queryByRole ( "button" , { name : / h i d d e n e v e n t / i } ) ,
386- ) . toBeNull ( ) ;
387- expect ( parseFloat ( projectEvent . style . left ) ) . toBeGreaterThan (
388- parseFloat ( primaryEvent . style . left ) ,
389- ) ;
390- expect ( primaryEvent . style . width ) . toBe ( projectEvent . style . width ) ;
388+ const primaryEvent = screen . getByRole ( "button" , {
389+ name : / p r i m a r y e v e n t / i,
391390 } ) ;
391+ const projectEvent = screen . getByRole ( "button" , {
392+ name : / p r o j e c t e v e n t / i,
393+ } ) ;
394+ expect ( screen . queryByRole ( "button" , { name : / h i d d e n e v e n t / i } ) ) . toBeNull ( ) ;
395+ expect ( parseFloat ( projectEvent . style . left ) ) . toBeGreaterThan (
396+ parseFloat ( primaryEvent . style . left ) ,
397+ ) ;
398+ expect ( primaryEvent . style . width ) . toBe ( projectEvent . style . width ) ;
392399 } ) ;
393400
394401 it ( "falls back to the primary calendar when every calendar is disabled" , ( ) => {
0 commit comments