11import { ChangeDetectorRef , Component , NO_ERRORS_SCHEMA } from '@angular/core' ;
2- import { waitForAsync , ComponentFixture , inject , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
2+ import { ComponentFixture , fakeAsync , inject , TestBed , tick , waitForAsync } from '@angular/core/testing' ;
33import { BrowserModule } from '@angular/platform-browser' ;
44import { CommonModule } from '@angular/common' ;
55import { TranslateModule } from '@ngx-translate/core' ;
66import {
7- DynamicFormArrayGroupModel ,
87 DynamicFormArrayModel ,
98 DynamicFormControlEvent ,
109 DynamicFormGroupModel ,
@@ -17,13 +16,13 @@ import { SubmissionService } from '../../../../submission.service';
1716import { SubmissionSectionUploadFileEditComponent } from './section-upload-file-edit.component' ;
1817import { POLICY_DEFAULT_WITH_LIST } from '../../section-upload.component' ;
1918import {
19+ mockFileFormData ,
2020 mockSubmissionCollectionId ,
2121 mockSubmissionId ,
22+ mockSubmissionObject ,
2223 mockUploadConfigResponse ,
2324 mockUploadConfigResponseMetadata ,
2425 mockUploadFiles ,
25- mockFileFormData ,
26- mockSubmissionObject ,
2726} from '../../../../../shared/mocks/submission.mock' ;
2827import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
2928import { FormComponent } from '../../../../../shared/form/form.component' ;
@@ -32,12 +31,20 @@ import { getMockFormService } from '../../../../../shared/mocks/form-service.moc
3231import { createTestComponent } from '../../../../../shared/testing/utils.test' ;
3332import { NgbActiveModal , NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
3433import { JsonPatchOperationsBuilder } from '../../../../../core/json-patch/builder/json-patch-operations-builder' ;
35- import { SubmissionJsonPatchOperationsServiceStub } from '../../../../../shared/testing/submission-json-patch-operations-service.stub' ;
36- import { SubmissionJsonPatchOperationsService } from '../../../../../core/submission/submission-json-patch-operations.service' ;
34+ import {
35+ SubmissionJsonPatchOperationsServiceStub
36+ } from '../../../../../shared/testing/submission-json-patch-operations-service.stub' ;
37+ import {
38+ SubmissionJsonPatchOperationsService
39+ } from '../../../../../core/submission/submission-json-patch-operations.service' ;
3740import { SectionUploadService } from '../../section-upload.service' ;
3841import { getMockSectionUploadService } from '../../../../../shared/mocks/section-upload.service.mock' ;
39- import { FormFieldMetadataValueObject } from '../../../../../shared/form/builder/models/form-field-metadata-value.model' ;
40- import { JsonPatchOperationPathCombiner } from '../../../../../core/json-patch/builder/json-patch-operation-path-combiner' ;
42+ import {
43+ FormFieldMetadataValueObject
44+ } from '../../../../../shared/form/builder/models/form-field-metadata-value.model' ;
45+ import {
46+ JsonPatchOperationPathCombiner
47+ } from '../../../../../core/json-patch/builder/json-patch-operation-path-combiner' ;
4148import { dateToISOFormat } from '../../../../../shared/date.util' ;
4249import { of } from 'rxjs' ;
4350
@@ -171,6 +178,8 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
171178 it ( 'should init form model properly' , ( ) => {
172179 comp . fileData = fileData ;
173180 comp . formId = 'testFileForm' ;
181+ const maxStartDate = { year : 2022 , month : 1 , day : 12 } ;
182+ const maxEndDate = { year : 2019 , month : 7 , day : 12 } ;
174183
175184 comp . ngOnInit ( ) ;
176185
@@ -179,6 +188,10 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
179188 expect ( comp . formModel [ 0 ] instanceof DynamicFormGroupModel ) . toBeTruthy ( ) ;
180189 expect ( comp . formModel [ 1 ] instanceof DynamicFormArrayModel ) . toBeTruthy ( ) ;
181190 expect ( ( comp . formModel [ 1 ] as DynamicFormArrayModel ) . groups . length ) . toBe ( 2 ) ;
191+ const startDateModel = formbuilderService . findById ( 'startDate' , comp . formModel ) ;
192+ expect ( startDateModel . max ) . toEqual ( maxStartDate ) ;
193+ const endDateModel = formbuilderService . findById ( 'endDate' , comp . formModel ) ;
194+ expect ( endDateModel . max ) . toEqual ( maxEndDate ) ;
182195 } ) ;
183196
184197 it ( 'should call setOptions method onChange' , ( ) => {
@@ -208,20 +221,19 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
208221 const formGroup = formbuilderService . createFormGroup ( comp . formModel ) ;
209222 const control = formbuilderService . getFormControlById ( 'name' , formGroup , comp . formModel , 0 ) ;
210223
211- spyOn ( formbuilderService , 'findById ' ) . and . callThrough ( ) ;
224+ spyOn ( control . parent , 'markAsDirty ' ) . and . callThrough ( ) ;
212225
213226 control . value = 'openaccess' ;
214227 comp . setOptions ( model , control ) ;
215- expect ( formbuilderService . findById ) . not . toHaveBeenCalledWith ( 'endDate' , ( model . parent as DynamicFormArrayGroupModel ) . group ) ;
216- expect ( formbuilderService . findById ) . not . toHaveBeenCalledWith ( 'startDate' , ( model . parent as DynamicFormArrayGroupModel ) . group ) ;
228+ expect ( control . parent . markAsDirty ) . toHaveBeenCalled ( ) ;
217229
218230 control . value = 'lease' ;
219231 comp . setOptions ( model , control ) ;
220- expect ( formbuilderService . findById ) . toHaveBeenCalledWith ( 'endDate' , ( model . parent as DynamicFormArrayGroupModel ) . group ) ;
232+ expect ( control . parent . markAsDirty ) . toHaveBeenCalled ( ) ;
221233
222234 control . value = 'embargo' ;
223235 comp . setOptions ( model , control ) ;
224- expect ( formbuilderService . findById ) . toHaveBeenCalledWith ( 'startDate' , ( model . parent as DynamicFormArrayGroupModel ) . group ) ;
236+ expect ( control . parent . markAsDirty ) . toHaveBeenCalled ( ) ;
225237 } ) ;
226238
227239 it ( 'should retrieve Value From Field properly' , ( ) => {
0 commit comments