Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { FormFieldModel } from '../models/form-field.model';
import { OneboxFieldParser } from './onebox-field-parser';
import { DynamicQualdropModel } from '../ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
import { DynamicTypeaheadModel } from '../ds-dynamic-form-ui/models/typeahead/dynamic-typeahead.model';
import { DsDynamicInputModel } from '../ds-dynamic-form-ui/models/ds-dynamic-input.model';
describe('OneboxFieldParser test suite', () => {
let field1: FormFieldModel;
let field2: FormFieldModel;
let field3: FormFieldModel;
const authorityUuid = 'testScopeUUID';
const initFormValues = {};
const readOnly = false;
beforeEach(() => {
field1 = {
input: {type: 'onebox'},
label: 'Title',
mandatory: 'false',
repeatable: false,
hints: 'Enter the name of the events, if any.',
selectableMetadata: [
{
metadata: 'title',
authority: 'EVENTAuthority',
closed: false
}
],
languageCodes: []
} as FormFieldModel;
field2 = {
hints: 'If the item has any identification numbers or codes associated with↵ it, please enter the types and the actual numbers or codes.',
input: {type: 'onebox'},
label: 'Identifiers',
languageCodes: [],
mandatory: 'false',
repeatable: false,
selectableMetadata: [
{metadata: 'dc.identifier.issn', label: 'ISSN'},
{metadata: 'dc.identifier.other', label: 'Other'},
{metadata: 'dc.identifier.ismn', label: 'ISMN'},
{metadata: 'dc.identifier.govdoc', label: 'Gov\'t Doc #'},
{metadata: 'dc.identifier.uri', label: 'URI'},
{metadata: 'dc.identifier.isbn', label: 'ISBN'},
{metadata: 'dc.identifier.doi', label: 'DOI'},
{metadata: 'dc.identifier.pmid', label: 'PubMed ID'},
{metadata: 'dc.identifier.arxiv', label: 'arXiv'}
]
} as FormFieldModel;
field3 = {
input: {type: 'onebox'},
label: 'Title',
mandatory: 'false',
repeatable: false,
hints: 'Enter the name of the events, if any.',
selectableMetadata: [
{
metadata: 'title',
}
],
languageCodes: []
} as FormFieldModel;
});
it('should init parser properly', () => {
const parser = new OneboxFieldParser(field1, initFormValues, readOnly, authorityUuid);
expect(parser instanceof OneboxFieldParser).toBe(true);
});
it('should return a DynamicQualdropModel object when selectableMetadata is multiple', () => {
const parser = new OneboxFieldParser(field2, initFormValues, readOnly, authorityUuid);
const fieldModel = parser.parse();
expect(fieldModel instanceof DynamicQualdropModel).toBe(true);
});
it('should return a DsDynamicInputModel object when selectableMetadata is not multiple', () => {
const parser = new OneboxFieldParser(field3, initFormValues, readOnly, authorityUuid);
const fieldModel = parser.parse();
expect(fieldModel instanceof DsDynamicInputModel).toBe(true);
});
it('should return a DynamicTypeaheadModel object when selectableMetadata has authority', () => {
const parser = new OneboxFieldParser(field1, initFormValues, readOnly, authorityUuid);
const fieldModel = parser.parse();
expect(fieldModel instanceof DynamicTypeaheadModel).toBe(true);
});
});