@@ -6,14 +6,18 @@ import {
66 screen ,
77 waitFor ,
88} from "@testing-library/react" ;
9+ import { act } from "react" ;
910import { Provider } from "react-redux" ;
10- import { type Schema_Event } from "@core/types/event.types" ;
11+ import { Priorities } from "@core/constants/core.constants" ;
12+ import { Categories_Event , type Schema_Event } from "@core/types/event.types" ;
1113import dayjs , { type Dayjs } from "@core/util/date/dayjs" ;
1214import { createInitialState } from "@web/__tests__/utils/state/store.test.util" ;
1315import {
1416 ID_GRID_COLUMNS_TIMED ,
1517 ZIndex ,
1618} from "@web/common/constants/web.constants" ;
19+ import { gridColorByPriority } from "@web/common/styles/theme.util" ;
20+ import { draftSlice } from "@web/ducks/events/slices/draft.slice" ;
1721import { pendingEventsSlice } from "@web/ducks/events/slices/pending.slice" ;
1822import { reducers } from "@web/store/reducers" ;
1923import { DraftContext } from "@web/views/Week/components/Draft/context/DraftContext" ;
@@ -65,7 +69,10 @@ const measurements = {
6569 } ,
6670} satisfies Measurements_Grid ;
6771
68- const createStore = ( events : Schema_Event [ ] = [ ] ) => {
72+ const createStore = (
73+ events : Schema_Event [ ] = [ ] ,
74+ draftEvent : Schema_Event | null = null ,
75+ ) => {
6976 const preloadedState = createInitialState ( ) ;
7077 const eventIds : string [ ] = [ ] ;
7178 const eventEntities : Record < string , Schema_Event > = { } ;
@@ -88,6 +95,20 @@ const createStore = (events: Schema_Event[] = []) => {
8895 pageSize : eventIds . length || 1 ,
8996 } ;
9097
98+ if ( draftEvent ) {
99+ preloadedState . events . draft = {
100+ event : draftEvent ,
101+ status : {
102+ activity : "keyboardEdit" ,
103+ dateToResize : null ,
104+ eventType : draftEvent . isAllDay
105+ ? Categories_Event . ALLDAY
106+ : Categories_Event . TIMED ,
107+ isDrafting : true ,
108+ } ,
109+ } ;
110+ }
111+
91112 return configureStore ( {
92113 preloadedState,
93114 reducer : reducers ,
@@ -482,6 +503,46 @@ describe("Week calendar accessibility", () => {
482503 expect ( getHoveredCalendarEventTarget ( ) ) . toBeNull ( ) ;
483504 } ) ;
484505
506+ it ( "updates the timed placeholder color when the active draft priority changes" , async ( ) => {
507+ const savedEvent = createSavedEvent ( {
508+ _id : "priority-event" ,
509+ title : "Priority event" ,
510+ } ) ;
511+ const store = createStore ( [ savedEvent ] , savedEvent ) ;
512+
513+ render (
514+ < Provider store = { store } >
515+ < MainGridEvents
516+ measurements = { measurements }
517+ weekProps = { createWeekProps ( ) }
518+ />
519+ </ Provider > ,
520+ ) ;
521+
522+ const eventButton = screen . getByRole ( "button" , {
523+ name : / p r i o r i t y e v e n t / i,
524+ } ) ;
525+
526+ expect ( eventButton . style . getPropertyValue ( "--event-bg" ) ) . toBe (
527+ gridColorByPriority [ Priorities . UNASSIGNED ] ,
528+ ) ;
529+
530+ act ( ( ) => {
531+ store . dispatch (
532+ draftSlice . actions . setEvent ( {
533+ ...savedEvent ,
534+ priority : Priorities . WORK ,
535+ } ) ,
536+ ) ;
537+ } ) ;
538+
539+ await waitFor ( ( ) => {
540+ expect ( eventButton . style . getPropertyValue ( "--event-bg" ) ) . toBe (
541+ gridColorByPriority [ Priorities . WORK ] ,
542+ ) ;
543+ } ) ;
544+ } ) ;
545+
485546 it ( "gives all-day events an all-day accessible name and target type" , ( ) => {
486547 const store = createStore ( [
487548 createSavedEvent ( {
@@ -515,6 +576,50 @@ describe("Week calendar accessibility", () => {
515576 ) . toBe ( "all-day" ) ;
516577 } ) ;
517578
579+ it ( "updates the all-day placeholder color when the active draft priority changes" , async ( ) => {
580+ const savedEvent = createSavedEvent ( {
581+ _id : "all-day-priority-event" ,
582+ isAllDay : true ,
583+ startDate : "2024-01-15T00:00:00.000Z" ,
584+ endDate : "2024-01-16T00:00:00.000Z" ,
585+ title : "All-day priority event" ,
586+ } ) ;
587+ const store = createStore ( [ savedEvent ] , savedEvent ) ;
588+
589+ render (
590+ < Provider store = { store } >
591+ < AllDayEvents
592+ endOfView = { startOfView . endOf ( "week" ) }
593+ measurements = { measurements }
594+ startOfView = { startOfView }
595+ />
596+ </ Provider > ,
597+ ) ;
598+
599+ const eventButton = screen . getByRole ( "button" , {
600+ name : / a l l - d a y e v e n t : a l l - d a y p r i o r i t y e v e n t / i,
601+ } ) ;
602+
603+ expect ( eventButton . style . getPropertyValue ( "--event-bg" ) ) . toBe (
604+ gridColorByPriority [ Priorities . UNASSIGNED ] ,
605+ ) ;
606+
607+ act ( ( ) => {
608+ store . dispatch (
609+ draftSlice . actions . setEvent ( {
610+ ...savedEvent ,
611+ priority : Priorities . RELATIONS ,
612+ } ) ,
613+ ) ;
614+ } ) ;
615+
616+ await waitFor ( ( ) => {
617+ expect ( eventButton . style . getPropertyValue ( "--event-bg" ) ) . toBe (
618+ gridColorByPriority [ Priorities . RELATIONS ] ,
619+ ) ;
620+ } ) ;
621+ } ) ;
622+
518623 it ( "keeps full-week all-day events spanning seven columns" , ( ) => {
519624 const store = createStore ( [
520625 createSavedEvent ( {
0 commit comments