1- import { render } from "@testing-library/react" ;
1+ import { render , screen } from "@testing-library/react" ;
22import { dynamic , ListValueBuilder } from "@mendix/widget-plugin-test-utils" ;
33
44import MxCalendar from "../Calendar" ;
@@ -10,37 +10,39 @@ jest.mock("react-big-calendar", () => {
1010 const originalModule = jest . requireActual ( "react-big-calendar" ) ;
1111 return {
1212 ...originalModule ,
13- Calendar : ( {
14- children,
15- defaultView,
16- culture,
17- resizable,
18- selectable,
19- showAllEvents,
20- min,
21- max,
22- events,
23- step,
24- timeslots,
25- ...domProps
26- } : any ) => (
27- < div
28- data-testid = "mock-calendar"
29- data-default-view = { defaultView }
30- data-culture = { culture }
31- data-resizable = { resizable }
32- data-selectable = { selectable }
33- data-show-all-events = { showAllEvents }
34- data-min = { min ?. toISOString ( ) }
35- data-max = { max ?. toISOString ( ) }
36- data-events-count = { events ?. length ?? 0 }
37- data-step = { step }
38- data-timeslots = { timeslots }
39- { ...domProps }
40- >
41- { children }
42- </ div >
43- ) ,
13+ Calendar : ( mockProps : any ) => {
14+ const {
15+ children,
16+ defaultView,
17+ defaultDate,
18+ culture,
19+ resizable,
20+ selectable,
21+ showAllEvents,
22+ events,
23+ step,
24+ timeslots,
25+ ...domProps
26+ } = mockProps ;
27+
28+ return (
29+ < div
30+ data-testid = "mock-calendar"
31+ data-default-view = { defaultView }
32+ data-default-date = { defaultDate ?. toISOString ( ) }
33+ data-culture = { culture }
34+ data-resizable = { resizable }
35+ data-selectable = { selectable }
36+ data-show-all-events = { showAllEvents }
37+ data-events-count = { events ?. length ?? 0 }
38+ data-step = { step }
39+ data-timeslots = { timeslots }
40+ { ...domProps }
41+ >
42+ { children }
43+ </ div >
44+ ) ;
45+ } ,
4446 dateFnsLocalizer : ( ) => ( {
4547 format : jest . fn ( ) ,
4648 parse : jest . fn ( ) ,
@@ -58,7 +60,7 @@ jest.mock("react-big-calendar", () => {
5860} ) ;
5961
6062jest . mock ( "react-big-calendar/lib/addons/dragAndDrop" , ( ) => {
61- return jest . fn ( ( Component : any ) => Component ) ;
63+ return jest . fn ( Component => Component ) ;
6264} ) ;
6365
6466const customViewProps : CalendarContainerProps = {
@@ -97,11 +99,6 @@ const customViewProps: CalendarContainerProps = {
9799 topBarDateFormat : undefined
98100} ;
99101
100- const standardViewProps : CalendarContainerProps = {
101- ...customViewProps ,
102- view : "standard"
103- } ;
104-
105102beforeAll ( ( ) => {
106103 jest . useFakeTimers ( ) ;
107104 jest . setSystemTime ( new Date ( "2025-04-28T12:00:00Z" ) ) ;
@@ -123,19 +120,78 @@ describe("Calendar", () => {
123120 expect ( container . querySelector ( ".calendar-class" ) ) . toBeTruthy ( ) ;
124121 } ) ;
125122
126- it ( "does not render custom view button in standard view" , ( ) => {
127- const { container } = render ( < MxCalendar { ...standardViewProps } /> ) ;
128- expect ( container ) . toBeTruthy ( ) ;
129- // Since we're mocking the calendar, we can't test for specific text content
130- // but we can verify the component renders without errors
131- } ) ;
132-
133123 it ( "passes step and timeslots to the calendar" , ( ) => {
134124 const { getByTestId } = render ( < MxCalendar { ...customViewProps } /> ) ;
135125 const calendar = getByTestId ( "mock-calendar" ) ;
136126 expect ( calendar . getAttribute ( "data-step" ) ) . toBe ( "60" ) ;
137127 expect ( calendar . getAttribute ( "data-timeslots" ) ) . toBe ( "2" ) ;
138128 } ) ;
129+
130+ it ( "renders loading bar when startDateAttribute is loading" , ( ) => {
131+ const props = {
132+ ...customViewProps ,
133+ startDateAttribute : {
134+ status : "loading"
135+ } as any
136+ } ;
137+
138+ const { container } = render ( < MxCalendar { ...props } /> ) ;
139+
140+ expect ( container . querySelector ( ".widget-calendar-loading-bar" ) ) . toBeTruthy ( ) ;
141+ expect ( container . querySelector ( "progress.widget-calendar-loading-bar" ) ) . toBeTruthy ( ) ;
142+ expect ( screen . queryByTestId ( "mock-calendar" ) ) . toBeFalsy ( ) ;
143+ } ) ;
144+
145+ it ( "renders calendar when startDateAttribute is available" , ( ) => {
146+ const props = {
147+ ...customViewProps ,
148+ startDateAttribute : {
149+ status : "available" ,
150+ value : new Date ( "2025-05-01T00:00:00.000Z" )
151+ } as any
152+ } ;
153+
154+ render ( < MxCalendar { ...props } /> ) ;
155+
156+ expect ( screen . getByTestId ( "mock-calendar" ) ) . toBeTruthy ( ) ;
157+ expect ( screen . queryByRole ( "progressbar" ) ) . toBeFalsy ( ) ;
158+ } ) ;
159+
160+ it ( "renders calendar when startDateAttribute is unavailable" , ( ) => {
161+ const props = {
162+ ...customViewProps ,
163+ startDateAttribute : {
164+ status : "unavailable"
165+ } as any
166+ } ;
167+
168+ render ( < MxCalendar { ...props } /> ) ;
169+
170+ expect ( screen . getByTestId ( "mock-calendar" ) ) . toBeTruthy ( ) ;
171+ expect ( screen . queryByRole ( "progressbar" ) ) . toBeFalsy ( ) ;
172+ } ) ;
173+
174+ it ( "renders calendar when startDateAttribute is undefined" , ( ) => {
175+ render ( < MxCalendar { ...customViewProps } startDateAttribute = { undefined } /> ) ;
176+
177+ expect ( screen . getByTestId ( "mock-calendar" ) ) . toBeTruthy ( ) ;
178+ expect ( screen . queryByRole ( "progressbar" ) ) . toBeFalsy ( ) ;
179+ } ) ;
180+
181+ it ( "passes defaultDate from startDateAttribute value" , ( ) => {
182+ const defaultDate = new Date ( "2025-06-10T08:30:00.000Z" ) ;
183+ const props = {
184+ ...customViewProps ,
185+ startDateAttribute : {
186+ status : "available" ,
187+ value : defaultDate
188+ } as any
189+ } ;
190+
191+ render ( < MxCalendar { ...props } /> ) ;
192+
193+ expect ( screen . getByTestId ( "mock-calendar" ) . getAttribute ( "data-default-date" ) ) . toBe ( "2025-06-10T08:30:00.000Z" ) ;
194+ } ) ;
139195} ) ;
140196
141197describe ( "CalendarPropsBuilder validation" , ( ) => {
@@ -147,7 +203,10 @@ describe("CalendarPropsBuilder validation", () => {
147203 messages : { }
148204 } as any ;
149205
150- const buildWithStepTimeslots = ( step : number , timeslots : number ) => {
206+ const buildWithStepTimeslots = (
207+ step : number ,
208+ timeslots : number
209+ ) : ReturnType < typeof CalendarPropsBuilder . prototype . build > => {
151210 const props = { ...customViewProps , step, timeslots } ;
152211 const builder = new CalendarPropsBuilder ( props ) ;
153212 return builder . build ( mockLocalizer , "en" ) ;
0 commit comments