mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
created DynamicLookupNameModel and added more tests
This commit is contained in:
@@ -317,6 +317,18 @@
|
||||
></ds-dynamic-lookup>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngSwitchCase="19">
|
||||
<ds-dynamic-lookup
|
||||
[bindId]="bindId"
|
||||
[group]="group"
|
||||
[model]="model"
|
||||
[showErrorMessages]="showErrorMessages"
|
||||
(blur)="onBlur($event)"
|
||||
(change)="onValueChange($event)"
|
||||
(focus)="onFocus($event)"
|
||||
></ds-dynamic-lookup>
|
||||
</ng-container>
|
||||
|
||||
<small *ngIf="showHint" class="text-muted" [innerHTML]="model.hint"
|
||||
[ngClass]="getClass('element', 'hint')"></small>
|
||||
|
||||
|
@@ -38,6 +38,7 @@ import { DynamicScrollableDropdownModel } from './models/scrollable-dropdown/dyn
|
||||
import { DynamicTagModel } from './models/tag/dynamic-tag.model';
|
||||
import { DynamicTypeaheadModel } from './models/typeahead/dynamic-typeahead.model';
|
||||
import { DynamicQualdropModel } from './models/ds-dynamic-qualdrop.model';
|
||||
import { DynamicLookupNameModel } from './models/lookup/dynamic-lookup-name.model';
|
||||
|
||||
describe('DsDynamicFormControlComponent test suite', () => {
|
||||
|
||||
@@ -79,7 +80,8 @@ describe('DsDynamicFormControlComponent test suite', () => {
|
||||
submissionScope: ''
|
||||
}),
|
||||
new DynamicDsDatePickerModel({id: 'datepicker'}),
|
||||
new DynamicLookupModel({id: 'lookup', separator: ','}),
|
||||
new DynamicLookupModel({id: 'lookup'}),
|
||||
new DynamicLookupNameModel({id: 'lookupName'}),
|
||||
new DynamicQualdropModel({id: 'combobox', readOnly: false})
|
||||
];
|
||||
const testModel = formModel[8];
|
||||
@@ -272,6 +274,8 @@ describe('DsDynamicFormControlComponent test suite', () => {
|
||||
|
||||
expect(testFn(formModel[23])).toEqual(NGBootstrapFormControlType.Lookup);
|
||||
|
||||
expect(testFn(formModel[24])).toEqual(NGBootstrapFormControlType.Group);
|
||||
expect(testFn(formModel[24])).toEqual(NGBootstrapFormControlType.LookupName);
|
||||
|
||||
expect(testFn(formModel[25])).toEqual(NGBootstrapFormControlType.Group);
|
||||
});
|
||||
});
|
||||
|
@@ -39,6 +39,7 @@ import { DYNAMIC_FORM_CONTROL_TYPE_LOOKUP } from './models/lookup/dynamic-lookup
|
||||
import { DynamicListCheckboxGroupModel } from './models/list/dynamic-list-checkbox-group.model';
|
||||
import { DynamicListRadioGroupModel } from './models/list/dynamic-list-radio-group.model';
|
||||
import { isNotEmpty } from '../../../empty.util';
|
||||
import { DYNAMIC_FORM_CONTROL_TYPE_LOOKUP_NAME } from './models/lookup/dynamic-lookup-name.model';
|
||||
|
||||
export const enum NGBootstrapFormControlType {
|
||||
|
||||
@@ -60,6 +61,7 @@ export const enum NGBootstrapFormControlType {
|
||||
Relation = 16, // 'RELATION'
|
||||
Date = 17, // 'DATE'
|
||||
Lookup = 18, // LOOKUP
|
||||
LookupName = 19, // LOOKUP_NAME
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -144,6 +146,9 @@ export class DsDynamicFormControlComponent extends DynamicFormControlComponent i
|
||||
case DYNAMIC_FORM_CONTROL_TYPE_LOOKUP:
|
||||
return NGBootstrapFormControlType.Lookup;
|
||||
|
||||
case DYNAMIC_FORM_CONTROL_TYPE_LOOKUP_NAME:
|
||||
return NGBootstrapFormControlType.LookupName;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@@ -0,0 +1,26 @@
|
||||
import { DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core';
|
||||
import { DynamicLookupModel, DynamicLookupModelConfig } from './dynamic-lookup.model';
|
||||
|
||||
export const DYNAMIC_FORM_CONTROL_TYPE_LOOKUP_NAME = 'LOOKUP_NAME';
|
||||
|
||||
export interface DynamicLookupNameModelConfig extends DynamicLookupModelConfig {
|
||||
separator?: string;
|
||||
firstPlaceholder?: string;
|
||||
secondPlaceholder?: string;
|
||||
}
|
||||
|
||||
export class DynamicLookupNameModel extends DynamicLookupModel {
|
||||
|
||||
@serializable() separator: string;
|
||||
@serializable() secondPlaceholder: string;
|
||||
@serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_LOOKUP_NAME;
|
||||
|
||||
constructor(config: DynamicLookupNameModelConfig, layout?: DynamicFormControlLayout) {
|
||||
|
||||
super(config, layout);
|
||||
|
||||
this.separator = config.separator || ',';
|
||||
this.placeholder = config.firstPlaceholder || 'form.last-name';
|
||||
this.secondPlaceholder = config.secondPlaceholder || 'form.first-name';
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
(openChange)="openChange($event);">
|
||||
|
||||
<!--Simple lookup, only 1 field -->
|
||||
<div class="form-row" *ngIf="!isLookupName">
|
||||
<div class="form-row" *ngIf="!isLookupName()">
|
||||
<div class="col-xs-12 col-sm-8 col-md-9 col-lg-10">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
|
||||
<!--Lookup-name, 2 fields-->
|
||||
<div class="form-row" *ngIf="isLookupName">
|
||||
<div class="form-row" *ngIf="isLookupName()">
|
||||
<div class="col-xs-12 col-md-8 col-lg-9">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
@@ -63,7 +63,7 @@
|
||||
(input)="onInput($event)">
|
||||
</div>
|
||||
|
||||
<div *ngIf="isLookupName" class="col-xs-12 col-md-6 pl-md-0" >
|
||||
<div *ngIf="isLookupName()" class="col-xs-12 col-md-6 pl-md-0" >
|
||||
<input class="form-control"
|
||||
[ngClass]="{}"
|
||||
[attr.autoComplete]="model.autoComplete"
|
||||
@@ -73,7 +73,7 @@
|
||||
[type]="model.inputType"
|
||||
[(ngModel)]="secondInputValue"
|
||||
[disabled]="firstInputValue.length === 0 || isInputDisabled()"
|
||||
[placeholder]="model.placeholder2 | translate"
|
||||
[placeholder]="model.secondPlaceholder | translate"
|
||||
[readonly]="model.readOnly"
|
||||
(change)="$event.preventDefault()"
|
||||
(blur)="onBlurEvent($event); $event.stopPropagation(); sdRef.close();"
|
||||
|
@@ -10,6 +10,7 @@ import { PageInfo } from '../../../../../../core/shared/page-info.model';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model';
|
||||
import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model';
|
||||
import { DynamicLookupNameModel } from './dynamic-lookup-name.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-dynamic-lookup',
|
||||
@@ -19,7 +20,7 @@ import { AuthorityValueModel } from '../../../../../../core/integration/models/a
|
||||
export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
@Input() bindId = true;
|
||||
@Input() group: FormGroup;
|
||||
@Input() model: DynamicLookupModel;
|
||||
@Input() model: DynamicLookupModel | DynamicLookupNameModel;
|
||||
@Input() showErrorMessages = false;
|
||||
|
||||
@Output() blur: EventEmitter<any> = new EventEmitter<any>();
|
||||
@@ -31,7 +32,6 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
public loading = false;
|
||||
public pageInfo: PageInfo;
|
||||
public optionsList: any;
|
||||
public isLookupName: boolean;
|
||||
public name2: string;
|
||||
|
||||
protected searchOptions: IntegrationSearchOptions;
|
||||
@@ -51,8 +51,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
1);
|
||||
|
||||
// Switch Lookup/LookupName
|
||||
if (this.model.separator) {
|
||||
this.isLookupName = true;
|
||||
if (this.isLookupName()) {
|
||||
this.name2 = this.model.name + '2';
|
||||
}
|
||||
|
||||
@@ -107,8 +106,8 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
}
|
||||
|
||||
if (hasValue(displayValue)) {
|
||||
if (this.isLookupName) {
|
||||
const values = displayValue.split(this.model.separator);
|
||||
if (this.isLookupName()) {
|
||||
const values = displayValue.split((this.model as DynamicLookupNameModel).separator);
|
||||
|
||||
this.firstInputValue = (values[0] || '').trim();
|
||||
this.secondInputValue = (values[1] || '').trim();
|
||||
@@ -121,7 +120,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
|
||||
protected getCurrentValue(): string {
|
||||
let result = '';
|
||||
if (!this.isLookupName) {
|
||||
if (!this.isLookupName()) {
|
||||
result = this.firstInputValue;
|
||||
} else {
|
||||
if (isNotEmpty(this.firstInputValue)) {
|
||||
@@ -130,7 +129,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
if (isNotEmpty(this.secondInputValue)) {
|
||||
result = isEmpty(result)
|
||||
? this.secondInputValue
|
||||
: this.firstInputValue + this.model.separator + ' ' + this.secondInputValue;
|
||||
: this.firstInputValue + (this.model as DynamicLookupNameModel).separator + ' ' + this.secondInputValue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -163,7 +162,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
|
||||
protected resetFields() {
|
||||
this.firstInputValue = '';
|
||||
if (this.isLookupName) {
|
||||
if (this.isLookupName()) {
|
||||
this.secondInputValue = '';
|
||||
}
|
||||
}
|
||||
@@ -181,6 +180,10 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
|
||||
return this.model.authorityOptions.closed && hasValue(this.model.value);
|
||||
}
|
||||
|
||||
isLookupName() {
|
||||
return (this.model instanceof DynamicLookupNameModel);
|
||||
}
|
||||
|
||||
isSearchDisabled() {
|
||||
// if (this.firstInputValue === ''
|
||||
// && (this.isLookupName ? this.secondInputValue === '' : true)) {
|
||||
|
@@ -1,14 +1,11 @@
|
||||
import { AUTOCOMPLETE_OFF, DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core';
|
||||
import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model';
|
||||
import { DsDynamicInputModel, DsDynamicInputModelConfig } from '../ds-dynamic-input.model';
|
||||
import { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model';
|
||||
|
||||
export const DYNAMIC_FORM_CONTROL_TYPE_LOOKUP = 'LOOKUP';
|
||||
|
||||
export interface DynamicLookupModelConfig extends DsDynamicInputModelConfig {
|
||||
maxOptions?: number;
|
||||
value?: any;
|
||||
separator: string;
|
||||
}
|
||||
|
||||
export class DynamicLookupModel extends DsDynamicInputModel {
|
||||
@@ -16,10 +13,6 @@ export class DynamicLookupModel extends DsDynamicInputModel {
|
||||
@serializable() maxOptions: number;
|
||||
@serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_LOOKUP;
|
||||
@serializable() value: any;
|
||||
@serializable() separator: string; // Defined only for lookup-name
|
||||
|
||||
@serializable() placeholder: string;
|
||||
@serializable() placeholder2: string;
|
||||
|
||||
constructor(config: DynamicLookupModelConfig, layout?: DynamicFormControlLayout) {
|
||||
|
||||
@@ -27,11 +20,7 @@ export class DynamicLookupModel extends DsDynamicInputModel {
|
||||
|
||||
this.autoComplete = AUTOCOMPLETE_OFF;
|
||||
this.maxOptions = config.maxOptions || 10;
|
||||
this.separator = config.separator; // Defined only for lookup-name
|
||||
|
||||
this.valueUpdates.next(config.value);
|
||||
// this.valueUpdates.subscribe(() => {
|
||||
// this.setInputsValue();
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,7 @@ import { DynamicRowGroupModel } from './ds-dynamic-form-ui/models/ds-dynamic-row
|
||||
import { DsDynamicInputModel } from './ds-dynamic-form-ui/models/ds-dynamic-input.model';
|
||||
import { FormFieldMetadataValueObject } from './models/form-field-metadata-value.model';
|
||||
import { DynamicConcatModel } from './ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
||||
import { DynamicLookupNameModel } from './ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
|
||||
|
||||
describe('FormBuilderService test suite', () => {
|
||||
|
||||
@@ -243,7 +244,9 @@ describe('FormBuilderService test suite', () => {
|
||||
|
||||
new DynamicDsDatePickerModel({id: 'testDate'}),
|
||||
|
||||
new DynamicLookupModel({id: 'testLookup', separator: ','}),
|
||||
new DynamicLookupModel({id: 'testLookup'}),
|
||||
|
||||
new DynamicLookupNameModel({id: 'testLookupName'}),
|
||||
|
||||
new DynamicQualdropModel({id: 'testCombobox', readOnly: false})
|
||||
];
|
||||
|
@@ -36,7 +36,7 @@ describe('DateFieldParser test suite', () => {
|
||||
expect(parser instanceof DateFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicDsDatePickerModel object', () => {
|
||||
it('should return a DynamicDsDatePickerModel object when repeatable option is false', () => {
|
||||
const parser = new DateFieldParser(field, initFormValues, readOnly);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
@@ -36,7 +36,7 @@ describe('DropdownFieldParser test suite', () => {
|
||||
expect(parser instanceof DropdownFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicScrollableDropdownModel object', () => {
|
||||
it('should return a DynamicScrollableDropdownModel object when repeatable option is false', () => {
|
||||
const parser = new DropdownFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
108
src/app/shared/form/builder/parsers/group-field-parser.spec.ts
Normal file
108
src/app/shared/form/builder/parsers/group-field-parser.spec.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { GroupFieldParser } from './group-field-parser';
|
||||
import { DynamicGroupModel } from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||
|
||||
describe('GroupFieldParser test suite', () => {
|
||||
let field: FormFieldModel;
|
||||
let initFormValues = {};
|
||||
|
||||
const authorityUuid = 'testScopeUUID';
|
||||
const readOnly = false;
|
||||
const submissionScope = 'WORKSPACE';
|
||||
|
||||
beforeEach(() => {
|
||||
field = {
|
||||
input: {
|
||||
type: 'group'
|
||||
},
|
||||
rows: [
|
||||
{
|
||||
fields: [
|
||||
{
|
||||
input: {
|
||||
type: 'onebox'
|
||||
},
|
||||
label: 'Author',
|
||||
mandatory: 'false',
|
||||
repeatable: false,
|
||||
hints: 'Enter the name of the author.',
|
||||
selectableMetadata: [
|
||||
{
|
||||
metadata: 'author'
|
||||
}
|
||||
],
|
||||
languageCodes: []
|
||||
},
|
||||
{
|
||||
input: {
|
||||
type: 'onebox'
|
||||
},
|
||||
label: 'Affiliation',
|
||||
mandatory: false,
|
||||
repeatable: true,
|
||||
hints: 'Enter the affiliation of the author.',
|
||||
selectableMetadata: [
|
||||
{
|
||||
metadata: 'affiliation'
|
||||
}
|
||||
],
|
||||
languageCodes: []
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
label: 'Authors',
|
||||
mandatory: 'true',
|
||||
repeatable: false,
|
||||
mandatoryMessage: 'Entering at least the first author is mandatory.',
|
||||
hints: 'Enter the names of the authors of this item.',
|
||||
selectableMetadata: [
|
||||
{
|
||||
metadata: 'author'
|
||||
}
|
||||
],
|
||||
languageCodes: []
|
||||
} as FormFieldModel;
|
||||
|
||||
});
|
||||
|
||||
it('should init parser properly', () => {
|
||||
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
|
||||
|
||||
expect(parser instanceof GroupFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicGroupModel object', () => {
|
||||
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel instanceof DynamicGroupModel).toBe(true);
|
||||
});
|
||||
|
||||
it('should throw when rows configuration is empty', () => {
|
||||
field.rows = null;
|
||||
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
|
||||
|
||||
expect(() => parser.parse())
|
||||
.toThrow();
|
||||
});
|
||||
|
||||
it('should set group init value properly', () => {
|
||||
initFormValues = {
|
||||
author: [new FormFieldMetadataValueObject('test author')],
|
||||
affiliation: [new FormFieldMetadataValueObject('test affiliation')]
|
||||
};
|
||||
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
const expectedValue = [{
|
||||
author: new FormFieldMetadataValueObject('test author'),
|
||||
affiliation: new FormFieldMetadataValueObject('test affiliation')
|
||||
}];
|
||||
|
||||
expect(fieldModel.value).toEqual(expectedValue);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,71 @@
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||
import { ListFieldParser } from './list-field-parser';
|
||||
import { DynamicListCheckboxGroupModel } from '../ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model';
|
||||
import { DynamicListRadioGroupModel } from '../ds-dynamic-form-ui/models/list/dynamic-list-radio-group.model';
|
||||
|
||||
describe('ListFieldParser test suite', () => {
|
||||
let field: FormFieldModel;
|
||||
let initFormValues = {};
|
||||
|
||||
const authorityUuid = 'testScopeUUID';
|
||||
const readOnly = false;
|
||||
|
||||
beforeEach(() => {
|
||||
field = {
|
||||
input: {
|
||||
type: 'list'
|
||||
},
|
||||
label: 'Type',
|
||||
mandatory: 'false',
|
||||
repeatable: true,
|
||||
hints: 'Select the type.',
|
||||
selectableMetadata: [
|
||||
{
|
||||
metadata: 'type',
|
||||
authority: 'type_programme',
|
||||
closed: false
|
||||
}
|
||||
],
|
||||
languageCodes: []
|
||||
} as FormFieldModel;
|
||||
|
||||
});
|
||||
|
||||
it('should init parser properly', () => {
|
||||
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
expect(parser instanceof ListFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicListCheckboxGroupModel object when repeatable option is true', () => {
|
||||
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel instanceof DynamicListCheckboxGroupModel).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicListRadioGroupModel object when repeatable option is false', () => {
|
||||
field.repeatable = false;
|
||||
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel instanceof DynamicListRadioGroupModel).toBe(true);
|
||||
});
|
||||
|
||||
it('should set init value properly', () => {
|
||||
initFormValues = {
|
||||
type: [new FormFieldMetadataValueObject('test type')],
|
||||
};
|
||||
const expectedValue = [new FormFieldMetadataValueObject('test type')];
|
||||
|
||||
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel.value).toEqual(expectedValue);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,61 @@
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||
import { LookupFieldParser } from './lookup-field-parser';
|
||||
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
|
||||
|
||||
describe('LookupFieldParser test suite', () => {
|
||||
let field: FormFieldModel;
|
||||
let initFormValues = {};
|
||||
|
||||
const authorityUuid = 'testScopeUUID';
|
||||
const readOnly = false;
|
||||
|
||||
beforeEach(() => {
|
||||
field = {
|
||||
input: {
|
||||
type: 'lookup'
|
||||
},
|
||||
label: 'Journal',
|
||||
mandatory: 'false',
|
||||
repeatable: false,
|
||||
hints: 'Enter the name of the journal where the item has been published, if any.',
|
||||
selectableMetadata: [
|
||||
{
|
||||
metadata: 'journal',
|
||||
authority: 'JOURNALAuthority',
|
||||
closed: false
|
||||
}
|
||||
],
|
||||
languageCodes: []
|
||||
} as FormFieldModel;
|
||||
|
||||
});
|
||||
|
||||
it('should init parser properly', () => {
|
||||
const parser = new LookupFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
expect(parser instanceof LookupFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicLookupModel object when repeatable option is false', () => {
|
||||
const parser = new LookupFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel instanceof DynamicLookupModel).toBe(true);
|
||||
});
|
||||
|
||||
it('should set init value properly', () => {
|
||||
initFormValues = {
|
||||
journal: [new FormFieldMetadataValueObject('test journal')],
|
||||
};
|
||||
const expectedValue = new FormFieldMetadataValueObject('test journal');
|
||||
|
||||
const parser = new LookupFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel.value).toEqual(expectedValue);
|
||||
});
|
||||
|
||||
});
|
@@ -19,8 +19,8 @@ export class LookupFieldParser extends FieldParser {
|
||||
|
||||
this.setValues(lookupModelConfig, fieldValue, true);
|
||||
|
||||
const lookupModel = new DynamicLookupModel(lookupModelConfig);
|
||||
return lookupModel;
|
||||
return new DynamicLookupModel(lookupModelConfig);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,63 @@
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||
import { LookupFieldParser } from './lookup-field-parser';
|
||||
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
|
||||
import { LookupNameFieldParser } from './lookup-name-field-parser';
|
||||
import { DynamicLookupNameModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
|
||||
|
||||
describe('LookupNameFieldParser test suite', () => {
|
||||
let field: FormFieldModel;
|
||||
let initFormValues = {};
|
||||
|
||||
const authorityUuid = 'testScopeUUID';
|
||||
const readOnly = false;
|
||||
|
||||
beforeEach(() => {
|
||||
field = {
|
||||
input: {
|
||||
type: 'lookup-name'
|
||||
},
|
||||
label: 'Author',
|
||||
mandatory: 'false',
|
||||
repeatable: false,
|
||||
hints: 'Enter the name of the author.',
|
||||
selectableMetadata: [
|
||||
{
|
||||
metadata: 'author',
|
||||
authority: 'RPAuthority',
|
||||
closed: false
|
||||
}
|
||||
],
|
||||
languageCodes: []
|
||||
} as FormFieldModel;
|
||||
|
||||
});
|
||||
|
||||
it('should init parser properly', () => {
|
||||
const parser = new LookupNameFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
expect(parser instanceof LookupNameFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicLookupNameModel object when repeatable option is false', () => {
|
||||
const parser = new LookupNameFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel instanceof DynamicLookupNameModel).toBe(true);
|
||||
});
|
||||
|
||||
it('should set init value properly', () => {
|
||||
initFormValues = {
|
||||
author: [new FormFieldMetadataValueObject('test author')],
|
||||
};
|
||||
const expectedValue = new FormFieldMetadataValueObject('test author');
|
||||
|
||||
const parser = new LookupNameFieldParser(field, initFormValues, readOnly, authorityUuid);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
||||
expect(fieldModel.value).toEqual(expectedValue);
|
||||
});
|
||||
|
||||
});
|
@@ -1,22 +1,29 @@
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||
import { LookupFieldParser } from './lookup-field-parser';
|
||||
import { FieldParser } from './field-parser';
|
||||
import {
|
||||
DynamicLookupNameModel,
|
||||
DynamicLookupNameModelConfig
|
||||
} from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
|
||||
|
||||
export class LookupNameFieldParser extends LookupFieldParser {
|
||||
export class LookupNameFieldParser extends FieldParser {
|
||||
|
||||
constructor(protected configData: FormFieldModel,
|
||||
protected initFormValues,
|
||||
protected readOnly: boolean,
|
||||
protected authorityUuid: string) {
|
||||
super(configData, initFormValues, readOnly, authorityUuid);
|
||||
super(configData, initFormValues, readOnly);
|
||||
}
|
||||
|
||||
public modelFactory(fieldValue: FormFieldMetadataValueObject | any): any {
|
||||
const lookupModel = super.modelFactory(fieldValue);
|
||||
lookupModel.separator = ',';
|
||||
lookupModel.placeholder = 'form.last-name';
|
||||
lookupModel.placeholder2 = 'form.first-name';
|
||||
return lookupModel;
|
||||
public modelFactory(fieldValue: any): any {
|
||||
if (this.configData.selectableMetadata[0].authority) {
|
||||
const lookupModelConfig: DynamicLookupNameModelConfig = this.initModel();
|
||||
|
||||
this.setAuthorityOptions(lookupModelConfig, this.authorityUuid);
|
||||
|
||||
this.setValues(lookupModelConfig, fieldValue, true);
|
||||
|
||||
return new DynamicLookupNameModel(lookupModelConfig);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ describe('NameFieldParser test suite', () => {
|
||||
expect(parser instanceof NameFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicConcatModel object', () => {
|
||||
it('should return a DynamicConcatModel object when repeatable option is false', () => {
|
||||
const parser = new NameFieldParser(field2, initFormValues, readOnly);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
@@ -31,7 +31,7 @@ describe('SeriesFieldParser test suite', () => {
|
||||
expect(parser instanceof SeriesFieldParser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return a DynamicConcatModel object', () => {
|
||||
it('should return a DynamicConcatModel object when repeatable option is false', () => {
|
||||
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
|
||||
|
||||
const fieldModel = parser.parse();
|
||||
|
@@ -112,11 +112,23 @@ describe('FormService test suite', () => {
|
||||
});
|
||||
|
||||
it('should add error to field', () => {
|
||||
const control = builderService.getFormControlById('description', formGroup, formModel);
|
||||
const model = builderService.findById('description', formModel);
|
||||
let control = builderService.getFormControlById('description', formGroup, formModel);
|
||||
let model = builderService.findById('description', formModel);
|
||||
let errorKeys: string[];
|
||||
|
||||
service.addErrorToField(control, model, 'Test error message');
|
||||
const errorKeys = Object.keys(control.errors);
|
||||
errorKeys = Object.keys(control.errors);
|
||||
|
||||
expect(errorKeys.length).toBe(1);
|
||||
|
||||
expect(control.hasError(errorKeys[0])).toBe(true);
|
||||
|
||||
expect(formGroup.controls.description.touched).toBe(true);
|
||||
|
||||
control = builderService.getFormControlById('title', formGroup, formModel);
|
||||
model = builderService.findById('title', formModel);
|
||||
service.addErrorToField(control, model, 'error.required');
|
||||
errorKeys = Object.keys(control.errors);
|
||||
|
||||
expect(errorKeys.length).toBe(1);
|
||||
|
||||
@@ -126,11 +138,26 @@ describe('FormService test suite', () => {
|
||||
});
|
||||
|
||||
it('should remove error from field', () => {
|
||||
const control = builderService.getFormControlById('description', formGroup, formModel);
|
||||
const model = builderService.findById('description', formModel);
|
||||
let control = builderService.getFormControlById('description', formGroup, formModel);
|
||||
let model = builderService.findById('description', formModel);
|
||||
let errorKeys: string[];
|
||||
|
||||
service.addErrorToField(control, model, 'Test error message');
|
||||
const errorKeys = Object.keys(control.errors);
|
||||
errorKeys = Object.keys(control.errors);
|
||||
|
||||
service.removeErrorFromField(control, model, errorKeys[0]);
|
||||
|
||||
expect(errorKeys.length).toBe(1);
|
||||
|
||||
expect(control.hasError(errorKeys[0])).toBe(false);
|
||||
|
||||
expect(formGroup.controls.description.touched).toBe(false);
|
||||
|
||||
control = builderService.getFormControlById('title', formGroup, formModel);
|
||||
model = builderService.findById('title', formModel);
|
||||
|
||||
service.addErrorToField(control, model, 'error.required');
|
||||
errorKeys = Object.keys(control.errors);
|
||||
|
||||
service.removeErrorFromField(control, model, errorKeys[0]);
|
||||
|
||||
|
Reference in New Issue
Block a user