@@ -16,11 +16,15 @@ import { SectionAccessesService } from './section-accesses.service';
1616import { SectionFormOperationsService } from '../form/section-form-operations.service' ;
1717import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder' ;
1818import { TranslateModule , TranslateService } from '@ngx-translate/core' ;
19- import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service' ;
19+ import {
20+ SubmissionJsonPatchOperationsService
21+ } from '../../../core/submission/submission-json-patch-operations.service' ;
2022import { getSectionAccessesService } from '../../../shared/mocks/section-accesses.service.mock' ;
2123import { getMockFormOperationsService } from '../../../shared/mocks/form-operations-service.mock' ;
2224import { getMockTranslateService } from '../../../shared/mocks/translate.service.mock' ;
23- import { SubmissionJsonPatchOperationsServiceStub } from '../../../shared/testing/submission-json-patch-operations-service.stub' ;
25+ import {
26+ SubmissionJsonPatchOperationsServiceStub
27+ } from '../../../shared/testing/submission-json-patch-operations-service.stub' ;
2428import { BrowserModule } from '@angular/platform-browser' ;
2529
2630import { of as observableOf } from 'rxjs' ;
@@ -42,8 +46,6 @@ describe('SubmissionSectionAccessesComponent', () => {
4246 let fixture : ComponentFixture < SubmissionSectionAccessesComponent > ;
4347
4448 const sectionsServiceStub = new SectionsServiceStub ( ) ;
45- // const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId, 'files', fileIndex);
46-
4749 const builderService : FormBuilderService = getMockFormBuilderService ( ) ;
4850 const submissionAccessesConfigService = getSubmissionAccessesConfigService ( ) ;
4951 const sectionAccessesService = getSectionAccessesService ( ) ;
@@ -55,6 +57,7 @@ describe('SubmissionSectionAccessesComponent', () => {
5557 } ) ;
5658
5759 let formService : any ;
60+ let formbuilderService : any ;
5861
5962 const storeStub = jasmine . createSpyObj ( 'store' , [ 'dispatch' ] ) ;
6063
@@ -86,7 +89,6 @@ describe('SubmissionSectionAccessesComponent', () => {
8689 declarations : [ SubmissionSectionAccessesComponent , FormComponent ] ,
8790 providers : [
8891 { provide : SectionsService , useValue : sectionsServiceStub } ,
89- { provide : FormBuilderService , useValue : builderService } ,
9092 { provide : SubmissionAccessesConfigService , useValue : submissionAccessesConfigService } ,
9193 { provide : SectionAccessesService , useValue : sectionAccessesService } ,
9294 { provide : SectionFormOperationsService , useValue : sectionFormOperationsService } ,
@@ -97,6 +99,7 @@ describe('SubmissionSectionAccessesComponent', () => {
9799 { provide : SubmissionJsonPatchOperationsService , useValue : SubmissionJsonPatchOperationsServiceStub } ,
98100 { provide : 'sectionDataProvider' , useValue : sectionData } ,
99101 { provide : 'submissionIdProvider' , useValue : '1508' } ,
102+ FormBuilderService
100103 ]
101104 } )
102105 . compileComponents ( ) ;
@@ -106,6 +109,7 @@ describe('SubmissionSectionAccessesComponent', () => {
106109 fixture = TestBed . createComponent ( SubmissionSectionAccessesComponent ) ;
107110 component = fixture . componentInstance ;
108111 formService = TestBed . inject ( FormService ) ;
112+ formbuilderService = TestBed . inject ( FormBuilderService ) ;
109113 formService . validateAllFormFields . and . callFake ( ( ) => null ) ;
110114 formService . isValid . and . returnValue ( observableOf ( true ) ) ;
111115 formService . getFormData . and . returnValue ( observableOf ( mockAccessesFormData ) ) ;
@@ -133,11 +137,22 @@ describe('SubmissionSectionAccessesComponent', () => {
133137 it ( 'formModel type array should have formgroup with 1 input and 2 datepickers' , ( ) => {
134138 const formModel : any = component . formModel [ 1 ] ;
135139 const formGroup = formModel . groupFactory ( ) [ 0 ] . group ;
140+
136141 expect ( formGroup [ 0 ] instanceof DynamicSelectModel ) . toBeTrue ( ) ;
137142 expect ( formGroup [ 1 ] instanceof DynamicDatePickerModel ) . toBeTrue ( ) ;
138143 expect ( formGroup [ 2 ] instanceof DynamicDatePickerModel ) . toBeTrue ( ) ;
139144 } ) ;
140145
146+ it ( 'should have set maxStartDate and maxEndDate properly' , ( ) => {
147+ const maxStartDate = { year : 2024 , month : 12 , day : 20 } ;
148+ const maxEndDate = { year : 2022 , month : 6 , day : 20 } ;
149+
150+ const startDateModel = formbuilderService . findById ( 'startDate' , component . formModel ) ;
151+ expect ( startDateModel . max ) . toEqual ( maxStartDate ) ;
152+ const endDateModel = formbuilderService . findById ( 'endDate' , component . formModel ) ;
153+ expect ( endDateModel . max ) . toEqual ( maxEndDate ) ;
154+ } ) ;
155+
141156 it ( 'when checkbox changed it should call operationsBuilder replace function' , ( ) => {
142157 component . onChange ( checkboxChangeEvent ) ;
143158 fixture . detectChanges ( ) ;
0 commit comments