-
Notifications
You must be signed in to change notification settings - Fork 0
/
componentValidation.js
26 lines (23 loc) · 1.06 KB
/
componentValidation.js
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
import {ComponentTypes, CUSSDataTypes, DeviceTypes, MediaTypes} from "cuss2-javascript-models";
import {expect} from 'chai'
export const validateComponent = (component) => {
expect(component).to.exist
expect(component).to.have.nested.property('componentCharacteristics[0].mediaTypesList')
//TODO: this isn't quite correct- fix later
const type = component.componentCharacteristics[0].mediaTypesList[0]
const validator = validate[type]
if (validator) {
validate[type](component)
}
//TODO: add more component validators
}
export const validate = {
[MediaTypes.BARCODE]: (component) => {
expect(component).to.have.nested.property('componentDescription')
expect(component).to.have.property('componentType', ComponentTypes.MEDIA_INPUT)
expect(component).to.have.property('componentCharacteristics').with.length(1)
const characteristics = component.componentCharacteristics[0]
expect(characteristics).to.have.nested.property('mediaTypesList[0]', MediaTypes.BARCODE)
expect(characteristics).to.have.property('deviceTypesList').with.length(1)
}
}