Skip to content
Snippets Groups Projects
Commit 83e8b003 authored by Giuseppe Digilio's avatar Giuseppe Digilio
Browse files

Added more tests

parent 3fdb074d
Branches
Tags
No related merge requests found
import { FormFieldModel } from '../models/form-field.model';
import { NameFieldParser } from './name-field-parser';
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
describe('NameFieldParser test suite', () => {
let field1: FormFieldModel;
let field2: FormFieldModel;
let field3: FormFieldModel;
const initFormValues = {};
const readOnly = false;
beforeEach(() => {
field1 = {
input: {type: 'name'},
label: 'Name',
mandatory: 'false',
repeatable: false,
hints: 'Enter the name.',
selectableMetadata: [
{
metadata: 'name',
}
],
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 NameFieldParser(field1, initFormValues, readOnly);
expect(parser instanceof NameFieldParser).toBe(true);
});
it('should return a DynamicConcatModel object', () => {
const parser = new NameFieldParser(field2, initFormValues, readOnly);
const fieldModel = parser.parse();
expect(fieldModel instanceof DynamicConcatModel).toBe(true);
});
it('should return a DynamicConcatModel object with the correct separator', () => {
const parser = new NameFieldParser(field2, initFormValues, readOnly);
const fieldModel = parser.parse();
expect((fieldModel as DynamicConcatModel).separator).toBe(', ');
});
});
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);
});
});
import { FormFieldModel } from '../models/form-field.model';
import { FormRowModel } from '../../../../core/shared/config/config-submission-forms.model';
import { RowParser } from './row-parser';
import { DynamicRowGroupModel } from '../ds-dynamic-form-ui/models/ds-dynamic-row-group-model';
import { DynamicRowArrayModel } from '../ds-dynamic-form-ui/models/ds-dynamic-row-array-model';
describe('RowParser test suite', () => {
let row1: FormRowModel;
let row2: FormRowModel;
let row3: FormRowModel;
const scopeUUID = 'testScopeUUID';
const initFormValues = {};
const submissionScope = 'WORKSPACE';
const readOnly = false;
beforeEach(() => {
row1 = {
fields: [
{
input: {type: 'lookup'},
label: 'Journal',
mandatory: 'false',
repeatable: false,
hints: 'Enter the name of the journal where the item has been\n\t\t\t\t\tpublished, if any.',
selectableMetadata: [
{
metadata: 'journal',
authority: 'JOURNALAuthority',
closed: false
}
],
languageCodes: []
} as FormFieldModel,
{
input: {type: 'onebox'},
label: 'Issue',
mandatory: 'false',
repeatable: false,
hints: ' Enter issue number.',
selectableMetadata: [
{
metadata: 'issue'
}
],
languageCodes: []
} as FormFieldModel,
{
input: {type: 'name'},
label: 'Name',
mandatory: 'false',
repeatable: false,
hints: 'Enter full name.',
selectableMetadata: [
{
metadata: 'name'
}
],
languageCodes: []
} as FormFieldModel
]
} as FormRowModel;
row2 = {
fields: [
{
input: {type: 'onebox'},
label: 'Title',
mandatory: 'false',
repeatable: true,
hints: 'Enter the name of the events, if any.',
selectableMetadata: [
{
metadata: 'title',
authority: 'EVENTAuthority',
closed: false
}
],
languageCodes: []
}
]
} as FormRowModel;
row3 = {
fields: [
{
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: []
},
{
input: {type: 'onebox'},
label: 'Other title',
mandatory: 'false',
repeatable: false,
hints: 'Enter the name of the events, if any.',
scope: 'WORKFLOW',
selectableMetadata: [
{
metadata: 'otherTitle',
authority: 'EVENTAuthority',
closed: false
}
],
languageCodes: []
}
]
} as FormRowModel;
});
it('should init parser properly', () => {
const parser = new RowParser(row1, scopeUUID, initFormValues, submissionScope, readOnly);
expect(parser instanceof RowParser).toBe(true);
});
it('should return a DynamicRowGroupModel object', () => {
const parser = new RowParser(row1, scopeUUID, initFormValues, submissionScope, readOnly);
const rowModel = parser.parse();
expect(rowModel instanceof DynamicRowGroupModel).toBe(true);
});
it('should return a row with three fields', () => {
const parser = new RowParser(row1, scopeUUID, initFormValues, submissionScope, readOnly);
const rowModel = parser.parse();
expect((rowModel as DynamicRowGroupModel).group.length).toBe(3);
});
it('should return a DynamicRowArrayModel object', () => {
const parser = new RowParser(row2, scopeUUID, initFormValues, submissionScope, readOnly);
const rowModel = parser.parse();
expect(rowModel instanceof DynamicRowArrayModel).toBe(true);
});
it('should return a row that contains only scoped fields', () => {
const parser = new RowParser(row3, scopeUUID, initFormValues, submissionScope, readOnly);
const rowModel = parser.parse();
expect((rowModel as DynamicRowGroupModel).group.length).toBe(1);
});
});
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';
import { ConcatFieldParser } from './concat-field-parser';
import { NameFieldParser } from './name-field-parser';
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
import { SeriesFieldParser } from './series-field-parser';
describe('SeriesFieldParser test suite', () => {
let field: FormFieldModel;
const initFormValues = {};
const readOnly = false;
beforeEach(() => {
field = {
input: {type: 'series'},
label: 'Series/Report No.',
mandatory: 'false',
repeatable: false,
hints: 'Enter the series and number assigned to this item by your community.',
selectableMetadata: [
{
metadata: 'series',
}
],
languageCodes: []
} as FormFieldModel;
});
it('should init parser properly', () => {
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
expect(parser instanceof SeriesFieldParser).toBe(true);
});
it('should return a DynamicConcatModel object', () => {
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
const fieldModel = parser.parse();
expect(fieldModel instanceof DynamicConcatModel).toBe(true);
});
it('should return a DynamicConcatModel object with the correct separator', () => {
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
const fieldModel = parser.parse();
expect((fieldModel as DynamicConcatModel).separator).toBe('; ');
});
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment