mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
created DynamicLookupNameModel and added more tests
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user