@@ -21,7 +21,6 @@ import {
2121import { MockModule , MockProvider } from 'ng-mocks' ;
2222
2323import { BookingRecurrence } from '@placeos/common' ;
24- import { SettingsService } from 'libs/common/src/lib/settings.service' ;
2524import { RecurrenceFieldComponent } from '../lib/recurrence-field.component' ;
2625
2726// ---------------------------------------------------------------------------
@@ -52,10 +51,7 @@ describe('RecurrenceFieldComponent – date change regression', () => {
5251 const createComponent = createComponentFactory ( {
5352 component : RecurrenceFieldComponent ,
5453 imports : [ MockModule ( MatFormFieldModule ) , MockModule ( MatSelectModule ) ] ,
55- providers : [
56- MockProvider ( SettingsService , { get : jest . fn ( ) } ) ,
57- MockProvider ( MatDialog , { open : jest . fn ( ) } ) ,
58- ] ,
54+ providers : [ MockProvider ( MatDialog , { open : jest . fn ( ) } ) ] ,
5955 } ) ;
6056
6157 /** Update the date signal input and flush effects. */
@@ -295,8 +291,14 @@ describe('RecurrenceFieldComponent – date change regression', () => {
295291 endOfMonth ( addMonths ( mar15 , 2 ) ) . valueOf ( ) ,
296292 ) ;
297293 } ) ;
294+ } ) ;
298295
299- it ( 'should NOT change end_date when end_type is "date"' , ( ) => {
296+ // -----------------------------------------------------------------------
297+ // Date-based end_date is clamped when booking date moves past it
298+ // -----------------------------------------------------------------------
299+ describe ( 'date-based end_date is clamped when booking date moves forward' , ( ) => {
300+ it ( 'should NOT change end_date when end_type is "date" and new date is still before end_date' , ( ) => {
301+ // end_date is June 30; new booking date Feb 1 is still well before it
300302 const fixed_end = new Date ( 2024 , 5 , 30 ) . valueOf ( ) ;
301303 setDate ( new Date ( 2024 , 0 , 8 ) . valueOf ( ) ) ;
302304 spectator . component . setValue ( {
@@ -310,8 +312,54 @@ describe('RecurrenceFieldComponent – date change regression', () => {
310312
311313 setDate ( new Date ( 2024 , 1 , 1 ) . valueOf ( ) ) ;
312314
315+ // end_date is still in the future relative to the new booking date
316+ // so it should remain unchanged
313317 expect ( spectator . component . value ( ) . end_date ) . toBe ( fixed_end ) ;
314318 } ) ;
319+
320+ it ( 'should update end_date when booking date moves past the recurrence end_date' , ( ) => {
321+ // Set up weekly recurrence ending April 5, 2024
322+ const apr5 = new Date ( 2024 , 3 , 5 ) . valueOf ( ) ;
323+ setDate ( new Date ( 2024 , 2 , 1 ) . valueOf ( ) ) ; // booking date: March 1
324+ spectator . component . setValue ( {
325+ _custom : true ,
326+ type : 'weekly' ,
327+ interval : 1 ,
328+ weekdays : new Set ( [ 5 as any ] ) , // Friday
329+ end_type : 'date' ,
330+ end_date : apr5 ,
331+ } ) ;
332+
333+ // Move booking date to April 10 – now AFTER the end_date of April 5
334+ const apr10 = new Date ( 2024 , 3 , 10 ) . valueOf ( ) ;
335+ setDate ( apr10 ) ;
336+
337+ // end_date must be >= new booking date; stale April 5 is invalid
338+ expect ( spectator . component . value ( ) . end_date ) . toBeGreaterThanOrEqual (
339+ apr10 ,
340+ ) ;
341+ } ) ;
342+
343+ it ( 'should NOT change end_date when booking date moves forward but stays before end_date' , ( ) => {
344+ // Set up weekly recurrence ending April 30, 2024
345+ const apr30 = new Date ( 2024 , 3 , 30 ) . valueOf ( ) ;
346+ setDate ( new Date ( 2024 , 2 , 1 ) . valueOf ( ) ) ; // booking date: March 1
347+ spectator . component . setValue ( {
348+ _custom : true ,
349+ type : 'weekly' ,
350+ interval : 1 ,
351+ weekdays : new Set ( [ 5 as any ] ) , // Friday
352+ end_type : 'date' ,
353+ end_date : apr30 ,
354+ } ) ;
355+
356+ // Move booking date to April 10 – still BEFORE the end_date of April 30
357+ const apr10 = new Date ( 2024 , 3 , 10 ) . valueOf ( ) ;
358+ setDate ( apr10 ) ;
359+
360+ // end_date should remain unchanged because it is still in the future
361+ expect ( spectator . component . value ( ) . end_date ) . toBe ( apr30 ) ;
362+ } ) ;
315363 } ) ;
316364
317365 // -----------------------------------------------------------------------
0 commit comments