Commits
Tim Donohue authored and GitHub committed f4c6284c23e Merge
9 9 | import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock'; |
10 10 | import { SubmissionAccessesConfigService } from '../../../core/config/submission-accesses-config.service'; |
11 11 | import { |
12 12 | getSubmissionAccessesConfigNotChangeDiscoverableService, |
13 13 | getSubmissionAccessesConfigService |
14 14 | } from '../../../shared/mocks/section-accesses-config.service.mock'; |
15 15 | import { SectionAccessesService } from './section-accesses.service'; |
16 16 | import { SectionFormOperationsService } from '../form/section-form-operations.service'; |
17 17 | import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder'; |
18 18 | import { 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'; |
20 22 | import { getSectionAccessesService } from '../../../shared/mocks/section-accesses.service.mock'; |
21 23 | import { getMockFormOperationsService } from '../../../shared/mocks/form-operations-service.mock'; |
22 24 | import { 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'; |
24 28 | import { BrowserModule } from '@angular/platform-browser'; |
25 29 | |
26 30 | import { of as observableOf } from 'rxjs'; |
27 31 | import { Store } from '@ngrx/store'; |
28 32 | import { FormComponent } from '../../../shared/form/form.component'; |
29 33 | import { |
30 34 | DynamicCheckboxModel, |
31 35 | DynamicDatePickerModel, |
32 36 | DynamicFormArrayModel, |
33 37 | DynamicSelectModel |
34 38 | } from '@ng-dynamic-forms/core'; |
35 39 | import { AppState } from '../../../app.reducer'; |
36 40 | import { getMockFormService } from '../../../shared/mocks/form-service.mock'; |
37 41 | import { mockAccessesFormData } from '../../../shared/mocks/submission.mock'; |
38 42 | import { accessConditionChangeEvent, checkboxChangeEvent } from '../../../shared/testing/form-event.stub'; |
39 43 | |
40 44 | describe('SubmissionSectionAccessesComponent', () => { |
41 45 | let component: SubmissionSectionAccessesComponent; |
42 46 | let fixture: ComponentFixture<SubmissionSectionAccessesComponent>; |
43 47 | |
44 48 | const sectionsServiceStub = new SectionsServiceStub(); |
45 - | // const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId, 'files', fileIndex); |
46 - | |
47 49 | const builderService: FormBuilderService = getMockFormBuilderService(); |
48 50 | const submissionAccessesConfigService = getSubmissionAccessesConfigService(); |
49 51 | const sectionAccessesService = getSectionAccessesService(); |
50 52 | const sectionFormOperationsService = getMockFormOperationsService(); |
51 53 | const operationsBuilder = jasmine.createSpyObj('operationsBuilder', { |
52 54 | add: undefined, |
53 55 | remove: undefined, |
54 56 | replace: undefined, |
55 57 | }); |
56 58 | |
57 59 | let formService: any; |
60 + | let formbuilderService: any; |
58 61 | |
59 62 | const storeStub = jasmine.createSpyObj('store', ['dispatch']); |
60 63 | |
61 64 | const sectionData = { |
62 65 | header: 'submit.progressbar.accessCondition', |
63 66 | config: 'http://localhost:8080/server/api/config/submissionaccessoptions/AccessConditionDefaultConfiguration', |
64 67 | mandatory: true, |
65 68 | sectionType: 'accessCondition', |
66 69 | collapsed: false, |
67 70 | enabled: true, |
79 82 | |
80 83 | beforeEach(async () => { |
81 84 | await TestBed.configureTestingModule({ |
82 85 | imports: [ |
83 86 | BrowserModule, |
84 87 | TranslateModule.forRoot() |
85 88 | ], |
86 89 | declarations: [SubmissionSectionAccessesComponent, FormComponent], |
87 90 | providers: [ |
88 91 | { provide: SectionsService, useValue: sectionsServiceStub }, |
89 - | { provide: FormBuilderService, useValue: builderService }, |
90 92 | { provide: SubmissionAccessesConfigService, useValue: submissionAccessesConfigService }, |
91 93 | { provide: SectionAccessesService, useValue: sectionAccessesService }, |
92 94 | { provide: SectionFormOperationsService, useValue: sectionFormOperationsService }, |
93 95 | { provide: JsonPatchOperationsBuilder, useValue: operationsBuilder }, |
94 96 | { provide: TranslateService, useValue: getMockTranslateService() }, |
95 97 | { provide: FormService, useValue: getMockFormService() }, |
96 98 | { provide: Store, useValue: storeStub }, |
97 99 | { provide: SubmissionJsonPatchOperationsService, useValue: SubmissionJsonPatchOperationsServiceStub }, |
98 100 | { provide: 'sectionDataProvider', useValue: sectionData }, |
99 101 | { provide: 'submissionIdProvider', useValue: '1508' }, |
102 + | FormBuilderService |
100 103 | ] |
101 104 | }) |
102 105 | .compileComponents(); |
103 106 | }); |
104 107 | |
105 108 | beforeEach(inject([Store], (store: Store<AppState>) => { |
106 109 | fixture = TestBed.createComponent(SubmissionSectionAccessesComponent); |
107 110 | component = fixture.componentInstance; |
108 111 | formService = TestBed.inject(FormService); |
112 + | formbuilderService = TestBed.inject(FormBuilderService); |
109 113 | formService.validateAllFormFields.and.callFake(() => null); |
110 114 | formService.isValid.and.returnValue(observableOf(true)); |
111 115 | formService.getFormData.and.returnValue(observableOf(mockAccessesFormData)); |
112 116 | fixture.detectChanges(); |
113 117 | })); |
114 118 | |
115 119 | |
116 120 | it('should create', () => { |
117 121 | expect(component).toBeTruthy(); |
118 122 | }); |
126 130 | }); |
127 131 | |
128 132 | it('formModel should have 1 model type checkbox and 1 model type array', () => { |
129 133 | expect(component.formModel[0] instanceof DynamicCheckboxModel).toBeTrue(); |
130 134 | expect(component.formModel[1] instanceof DynamicFormArrayModel).toBeTrue(); |
131 135 | }); |
132 136 | |
133 137 | it('formModel type array should have formgroup with 1 input and 2 datepickers', () => { |
134 138 | const formModel: any = component.formModel[1]; |
135 139 | const formGroup = formModel.groupFactory()[0].group; |
140 + | |
136 141 | expect(formGroup[0] instanceof DynamicSelectModel).toBeTrue(); |
137 142 | expect(formGroup[1] instanceof DynamicDatePickerModel).toBeTrue(); |
138 143 | expect(formGroup[2] instanceof DynamicDatePickerModel).toBeTrue(); |
139 144 | }); |
140 145 | |
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 + | |
141 156 | it('when checkbox changed it should call operationsBuilder replace function', () => { |
142 157 | component.onChange(checkboxChangeEvent); |
143 158 | fixture.detectChanges(); |
144 159 | |
145 160 | expect(operationsBuilder.replace).toHaveBeenCalled(); |
146 161 | }); |
147 162 | |
148 163 | it('when dropdown select changed it should call operationsBuilder add function', () => { |
149 164 | component.onChange(accessConditionChangeEvent); |
150 165 | fixture.detectChanges(); |