Merge remote-tracking branch 'upstream/main' into fix-missing-hints-and-required-attributes-main

# Conflicts:
#	src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts
#	src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model.ts
This commit is contained in:
Alexandre Vryghem
2023-03-05 14:40:41 +01:00
2120 changed files with 129426 additions and 52071 deletions

View File

@@ -26,7 +26,7 @@ import {
DynamicSliderModel,
DynamicSwitchModel,
DynamicTextAreaModel,
DynamicTimePickerModel
DynamicTimePickerModel,
} from '@ng-dynamic-forms/core';
import { DynamicTagModel } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
import { DynamicListCheckboxGroupModel } from './ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model';
@@ -48,12 +48,18 @@ import { DynamicConcatModel } from './ds-dynamic-form-ui/models/ds-dynamic-conca
import { DynamicLookupNameModel } from './ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
import { DynamicRowArrayModel } from './ds-dynamic-form-ui/models/ds-dynamic-row-array-model';
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
import {ConfigurationDataService} from '../../../core/data/configuration-data.service';
import {createSuccessfulRemoteDataObject$} from '../../remote-data.utils';
import {ConfigurationProperty} from '../../../core/shared/configuration-property.model';
describe('FormBuilderService test suite', () => {
let testModel: DynamicFormControlModel[];
let testFormConfiguration: SubmissionFormsModel;
let service: FormBuilderService;
let configSpy: ConfigurationDataService;
const typeFieldProp = 'submit.type-bind.field';
const typeFieldTestValue = 'dc.type';
const submissionId = '1234';
@@ -65,15 +71,24 @@ describe('FormBuilderService test suite', () => {
return new Promise<boolean>((resolve) => setTimeout(() => resolve(true), 0));
}
beforeEach(() => {
const createConfigSuccessSpy = (...values: string[]) => jasmine.createSpyObj('configurationDataService', {
findByPropertyName: createSuccessfulRemoteDataObject$({
... new ConfigurationProperty(),
name: typeFieldProp,
values: values,
}),
});
beforeEach(() => {
configSpy = createConfigSuccessSpy(typeFieldTestValue);
TestBed.configureTestingModule({
imports: [ReactiveFormsModule],
providers: [
{ provide: FormBuilderService, useClass: FormBuilderService },
{ provide: DynamicFormValidationService, useValue: {} },
{ provide: NG_VALIDATORS, useValue: testValidator, multi: true },
{ provide: NG_ASYNC_VALIDATORS, useValue: testAsyncValidator, multi: true }
{ provide: NG_ASYNC_VALIDATORS, useValue: testAsyncValidator, multi: true },
{ provide: ConfigurationDataService, useValue: configSpy }
]
});
@@ -104,7 +119,7 @@ describe('FormBuilderService test suite', () => {
new DynamicInputModel(
{
id: 'testInput',
mask: ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
mask: '(000) 000-0000',
}
),
@@ -197,7 +212,7 @@ describe('FormBuilderService test suite', () => {
repeatable: false,
metadataFields: [],
submissionId: '1234',
hasSelectableMetadata: false
hasSelectableMetadata: false,
}),
new DynamicScrollableDropdownModel({
@@ -239,6 +254,7 @@ describe('FormBuilderService test suite', () => {
hints: 'Enter the name of the author.',
input: { type: 'onebox' },
label: 'Authors',
typeBind: [],
languageCodes: [],
mandatory: 'true',
mandatoryMessage: 'Required field!',
@@ -310,9 +326,19 @@ describe('FormBuilderService test suite', () => {
required: false,
metadataKey: 'dc.contributor.author',
metadataFields: ['dc.contributor.author'],
hasSelectableMetadata: true
hasSelectableMetadata: true,
showButtons: true,
typeBindRelations: [{ match: 'VISIBLE', operator: 'OR', when: [{id: 'dc.type', value: 'Book' }]}]
},
),
new DynamicConcatModel({
id: 'testConcatGroup_CONCAT_GROUP',
group: [
new DynamicInputModel({ id: 'testConcatGroup_CONCAT_FIRST_INPUT' }),
new DynamicInputModel({ id: 'testConcatGroup_CONCAT_SECOND_INPUT' }),
]
} as any)
];
testFormConfiguration = {
@@ -430,7 +456,9 @@ describe('FormBuilderService test suite', () => {
} as any;
});
beforeEach(inject([FormBuilderService], (formService: FormBuilderService) => service = formService));
beforeEach(inject([FormBuilderService], (formService: FormBuilderService) => {
service = formService;
}));
it('should find a dynamic form control model by id', () => {
@@ -449,6 +477,7 @@ describe('FormBuilderService test suite', () => {
expect(service.findById('testTimePicker', testModel) instanceof DynamicTimePickerModel).toBe(true);
expect(service.findById('testRating', testModel) instanceof DynamicRatingModel).toBe(true);
expect(service.findById('testColorPicker', testModel) instanceof DynamicColorPickerModel).toBe(true);
expect(service.findById('testConcatGroup', testModel) instanceof DynamicConcatModel).toBe(true);
});
it('should find a nested dynamic form control model by id', () => {
@@ -881,4 +910,12 @@ describe('FormBuilderService test suite', () => {
expect(formArray.length === 0).toBe(true);
});
it(`should request the ${typeFieldProp} property and set value "dc_type"`, () => {
const typeValue = service.getTypeField();
expect(configSpy.findByPropertyName).toHaveBeenCalledTimes(1);
expect(configSpy.findByPropertyName).toHaveBeenCalledWith(typeFieldProp);
expect(typeValue).toEqual('dc_type');
});
});