mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
[TLC-254] ITs, mocking type bind relation service
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
|||||||
DynamicEditorModel,
|
DynamicEditorModel,
|
||||||
DynamicFileUploadModel,
|
DynamicFileUploadModel,
|
||||||
DynamicFormArrayModel,
|
DynamicFormArrayModel,
|
||||||
DynamicFormControlModel,
|
DynamicFormControlModel, DynamicFormControlRelation,
|
||||||
DynamicFormGroupModel,
|
DynamicFormGroupModel,
|
||||||
DynamicFormsCoreModule,
|
DynamicFormsCoreModule,
|
||||||
DynamicFormService,
|
DynamicFormService,
|
||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
DynamicSliderModel,
|
DynamicSliderModel,
|
||||||
DynamicSwitchModel,
|
DynamicSwitchModel,
|
||||||
DynamicTextAreaModel,
|
DynamicTextAreaModel,
|
||||||
DynamicTimePickerModel
|
DynamicTimePickerModel, MATCH_VISIBLE, OR_OPERATOR
|
||||||
} from '@ng-dynamic-forms/core';
|
} from '@ng-dynamic-forms/core';
|
||||||
import {
|
import {
|
||||||
DynamicNGBootstrapCalendarComponent,
|
DynamicNGBootstrapCalendarComponent,
|
||||||
@@ -83,10 +83,26 @@ import { NgxMaskModule } from 'ngx-mask';
|
|||||||
function getMockDsDynamicTypeBindRelationService(): DsDynamicTypeBindRelationService {
|
function getMockDsDynamicTypeBindRelationService(): DsDynamicTypeBindRelationService {
|
||||||
return jasmine.createSpyObj('DsDynamicTypeBindRelationService', {
|
return jasmine.createSpyObj('DsDynamicTypeBindRelationService', {
|
||||||
getRelatedFormModel: jasmine.createSpy('getRelatedFormModel'),
|
getRelatedFormModel: jasmine.createSpy('getRelatedFormModel'),
|
||||||
isFormControlToBeHidden: jasmine.createSpy('isFormControlToBeHidden')
|
matchesCondition: jasmine.createSpy('matchesCondition'),
|
||||||
|
subscribeRelations: jasmine.createSpy('subscribeRelations')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTypeBindRelations(configuredTypeBindValues: string[]): DynamicFormControlRelation[] {
|
||||||
|
const bindValues = [];
|
||||||
|
configuredTypeBindValues.forEach((value) => {
|
||||||
|
bindValues.push({
|
||||||
|
id: 'dc.type',
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return [{
|
||||||
|
match: MATCH_VISIBLE,
|
||||||
|
operator: OR_OPERATOR,
|
||||||
|
when: bindValues
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
describe('DsDynamicFormControlContainerComponent test suite', () => {
|
describe('DsDynamicFormControlContainerComponent test suite', () => {
|
||||||
|
|
||||||
const vocabularyOptions: VocabularyOptions = {
|
const vocabularyOptions: VocabularyOptions = {
|
||||||
@@ -119,7 +135,8 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
|
|||||||
metadataFields: [],
|
metadataFields: [],
|
||||||
repeatable: false,
|
repeatable: false,
|
||||||
submissionId: '1234',
|
submissionId: '1234',
|
||||||
hasSelectableMetadata: false
|
hasSelectableMetadata: false,
|
||||||
|
typeBindRelations: getTypeBindRelations(['Book'])
|
||||||
}),
|
}),
|
||||||
new DynamicScrollableDropdownModel({
|
new DynamicScrollableDropdownModel({
|
||||||
id: 'scrollableDropdown',
|
id: 'scrollableDropdown',
|
||||||
@@ -178,6 +195,7 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
|
|||||||
];
|
];
|
||||||
const testModel = formModel[8];
|
const testModel = formModel[8];
|
||||||
let formGroup: FormGroup;
|
let formGroup: FormGroup;
|
||||||
|
let formBuilderService: FormBuilderService;
|
||||||
let fixture: ComponentFixture<DsDynamicFormControlContainerComponent>;
|
let fixture: ComponentFixture<DsDynamicFormControlContainerComponent>;
|
||||||
let component: DsDynamicFormControlContainerComponent;
|
let component: DsDynamicFormControlContainerComponent;
|
||||||
let debugElement: DebugElement;
|
let debugElement: DebugElement;
|
||||||
@@ -240,7 +258,7 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(inject([DynamicFormService], (service: DynamicFormService) => {
|
beforeEach(inject([DynamicFormService, FormBuilderService], (service: DynamicFormService, formBuilderService: FormBuilderService) => {
|
||||||
|
|
||||||
formGroup = service.createFormGroup(formModel);
|
formGroup = service.createFormGroup(formModel);
|
||||||
|
|
||||||
@@ -366,4 +384,15 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
|
|||||||
expect(testFn(formModel[25])).toEqual(DsDynamicFormGroupComponent);
|
expect(testFn(formModel[25])).toEqual(DsDynamicFormGroupComponent);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should display a type-bound field when dc.type matcher set to Book', () => {
|
||||||
|
const rels: any = getMockDsDynamicTypeBindRelationService().getRelatedFormModel(formModel[16]);
|
||||||
|
const isVisible = getMockDsDynamicTypeBindRelationService().matchesCondition(rels.typeBindRelations, rels.matcher);
|
||||||
|
expect(isVisible).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should successfully subscribe type bind relations for component', () => {
|
||||||
|
const subscriptions = getMockDsDynamicTypeBindRelationService().subscribeRelations(component.model, component.control);
|
||||||
|
expect(subscriptions).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -48,7 +48,11 @@ 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 { 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 { DynamicRowArrayModel } from './ds-dynamic-form-ui/models/ds-dynamic-row-array-model';
|
||||||
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
|
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
|
||||||
import {DsDynamicTypeBindRelationService} from "./ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service";
|
import { DsDynamicTypeBindRelationService } from './ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
|
||||||
|
import {of as observableOf} from "rxjs";
|
||||||
|
import {MenuSection} from "../../menu/menu.reducer";
|
||||||
|
import {MenuID} from "../../menu/initial-menus-state";
|
||||||
|
import {cold} from "jasmine-marbles";
|
||||||
|
|
||||||
describe('FormBuilderService test suite', () => {
|
describe('FormBuilderService test suite', () => {
|
||||||
|
|
||||||
@@ -60,7 +64,7 @@ describe('FormBuilderService test suite', () => {
|
|||||||
function getMockDsDynamicTypeBindRelationService(): DsDynamicTypeBindRelationService {
|
function getMockDsDynamicTypeBindRelationService(): DsDynamicTypeBindRelationService {
|
||||||
return jasmine.createSpyObj('DsDynamicTypeBindRelationService', {
|
return jasmine.createSpyObj('DsDynamicTypeBindRelationService', {
|
||||||
getRelatedFormModel: jasmine.createSpy('getRelatedFormModel'),
|
getRelatedFormModel: jasmine.createSpy('getRelatedFormModel'),
|
||||||
isFormControlToBeHidden: jasmine.createSpy('isFormControlToBeHidden')
|
matchesCondition: jasmine.createSpy('matchesCondition')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -895,7 +899,7 @@ describe('FormBuilderService test suite', () => {
|
|||||||
it('should hide on type bind', () => {
|
it('should hide on type bind', () => {
|
||||||
const model = service.findById('testFormArray', testModel) as DynamicFormArrayModel;
|
const model = service.findById('testFormArray', testModel) as DynamicFormArrayModel;
|
||||||
typeBindRelationService.getRelatedFormModel(model);
|
typeBindRelationService.getRelatedFormModel(model);
|
||||||
service.getTypeBindModel();
|
const formArray = service.createFormArray(model);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user