forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdate-field-parser.spec.ts
More file actions
78 lines (60 loc) · 2.53 KB
/
date-field-parser.spec.ts
File metadata and controls
78 lines (60 loc) · 2.53 KB
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
import { FormFieldModel } from '@dspace/core/shared/form/models/form-field.model';
import { FormFieldMetadataValueObject } from '@dspace/core/shared/form/models/form-field-metadata-value.model';
import { getMockTranslateService } from '@dspace/core/testing/translate.service.mock';
import { DynamicDsDatePickerModel } from '../ds-dynamic-form-ui/models/date-picker/date-picker.model';
import { DateFieldParser } from './date-field-parser';
import { ParserOptions } from './parser-options';
describe('DateFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues: any = {};
let translateService = getMockTranslateService();
const submissionId = '1234';
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: null,
collectionUUID: null,
typeField: 'dc_type',
isInnerForm: false,
};
beforeEach(() => {
field = {
input: {
type: 'date',
},
label: 'Date of Issue.',
mandatory: 'true',
repeatable: false,
hints: 'Please give the date of previous publication or public distribution. You can leave out the day and/or month if they aren\'t applicable.',
mandatoryMessage: 'You must enter at least the year.',
selectableMetadata: [
{
metadata: 'date',
},
],
languageCodes: [],
} as FormFieldModel;
});
it('should init parser properly', () => {
const parser = new DateFieldParser(submissionId, field, initFormValues, parserOptions, null, translateService);
expect(parser instanceof DateFieldParser).toBe(true);
});
it('should return a DynamicDsDatePickerModel object when repeatable option is false', () => {
const parser = new DateFieldParser(submissionId, field, initFormValues, parserOptions, null, translateService);
const fieldModel = parser.parse();
expect(fieldModel instanceof DynamicDsDatePickerModel).toBe(true);
});
it('should set init value properly', () => {
initFormValues = {
date: [new FormFieldMetadataValueObject('1983-11-18')],
};
const expectedValue = '1983-11-18';
const parser = new DateFieldParser(submissionId, field, initFormValues, parserOptions, null, translateService);
const fieldModel = parser.parse();
expect(fieldModel.value).toEqual(expectedValue);
});
it('should skip setting the placeholder', () => {
const parser = new DateFieldParser(submissionId, field, initFormValues, parserOptions, null, translateService);
const fieldModel = parser.parse();
expect(fieldModel.placeholder).toBeNull();
});
});