});
describe('getType', () => {
- it('should return uint64_t type', () => {
- const ret = component.getType('uint64_t');
+ it('should return uint type', () => {
+ const ret = component.getType('uint');
expect(ret).toBeTruthy();
- expect(ret.name).toBe('uint64_t');
+ expect(ret.name).toBe('uint');
expect(ret.inputType).toBe('number');
expect(ret.humanReadable).toBe('Positive integer value');
expect(ret.defaultMin).toBe(0);
expect(ret.allowsNegative).toBe(false);
});
- it('should return int64_t type', () => {
- const ret = component.getType('int64_t');
+ it('should return int type', () => {
+ const ret = component.getType('int');
expect(ret).toBeTruthy();
- expect(ret.name).toBe('int64_t');
+ expect(ret.name).toBe('int');
expect(ret.inputType).toBe('number');
expect(ret.humanReadable).toBe('Integer value');
expect(ret.defaultMin).toBeUndefined();
expect(ret.allowsNegative).toBe(true);
});
- it('should return size_t type', () => {
- const ret = component.getType('size_t');
+ it('should return size type', () => {
+ const ret = component.getType('size');
expect(ret).toBeTruthy();
- expect(ret.name).toBe('size_t');
+ expect(ret.name).toBe('size');
expect(ret.inputType).toBe('number');
expect(ret.humanReadable).toBe('Positive integer value (size)');
expect(ret.defaultMin).toBe(0);
expect(ret.allowsNegative).toBe(false);
});
- it('should return double type', () => {
- const ret = component.getType('double');
+ it('should return float type', () => {
+ const ret = component.getType('float');
expect(ret).toBeTruthy();
- expect(ret.name).toBe('double');
+ expect(ret.name).toBe('float');
expect(ret.inputType).toBe('number');
expect(ret.humanReadable).toBe('Decimal value');
expect(ret.defaultMin).toBeUndefined();
expect(ret.allowsNegative).toBe(true);
});
- it('should return std::string type', () => {
- const ret = component.getType('std::string');
+ it('should return str type', () => {
+ const ret = component.getType('str');
expect(ret).toBeTruthy();
- expect(ret.name).toBe('std::string');
+ expect(ret.name).toBe('str');
expect(ret.inputType).toBe('text');
expect(ret.humanReadable).toBe('Text');
expect(ret.defaultMin).toBeUndefined();
expect(ret.allowsNegative).toBeUndefined();
});
- it('should return entity_addr_t type', () => {
- const ret = component.getType('entity_addr_t');
+ it('should return addr type', () => {
+ const ret = component.getType('addr');
expect(ret).toBeTruthy();
- expect(ret.name).toBe('entity_addr_t');
+ expect(ret.name).toBe('addr');
expect(ret.inputType).toBe('text');
expect(ret.humanReadable).toBe('IPv4 or IPv6 address');
expect(ret.defaultMin).toBeUndefined();
expect(ret.allowsNegative).toBeUndefined();
});
- it('should return uuid_d type', () => {
- const ret = component.getType('uuid_d');
+ it('should return uuid type', () => {
+ const ret = component.getType('uuid');
expect(ret).toBeTruthy();
- expect(ret.name).toBe('uuid_d');
+ expect(ret.name).toBe('uuid');
expect(ret.inputType).toBe('text');
expect(ret.humanReadable).toBe('UUID');
expect(ret.defaultMin).toBeUndefined();
});
describe('getValidators', () => {
- it('should return a validator for types double, entity_addr_t and uuid_d', () => {
- const types = ['double', 'entity_addr_t', 'uuid_d'];
+ it('should return a validator for types float, addr and uuid', () => {
+ const types = ['float', 'addr', 'uuid'];
types.forEach((valType) => {
const configOption = new ConfigFormModel();
});
});
- it('should not return a validator for types std::string and bool', () => {
- const types = ['std::string', 'bool'];
+ it('should not return a validator for types str and bool', () => {
+ const types = ['str', 'bool'];
types.forEach((valType) => {
const configOption = new ConfigFormModel();
it('should return a pattern and a min validator', () => {
const configOption = new ConfigFormModel();
- configOption.type = 'int64_t';
+ configOption.type = 'int';
configOption.min = 2;
const ret = component.getValidators(configOption);
it('should return a pattern and a max validator', () => {
const configOption = new ConfigFormModel();
- configOption.type = 'int64_t';
+ configOption.type = 'int';
configOption.max = 5;
const ret = component.getValidators(configOption);
it('should return multiple validators', () => {
const configOption = new ConfigFormModel();
- configOption.type = 'double';
+ configOption.type = 'float';
configOption.max = 5.2;
configOption.min = 1.5;
});
describe('getStep', () => {
- it('should return the correct step for type uint64_t and value 0', () => {
- const ret = component.getStep('uint64_t', 0);
+ it('should return the correct step for type uint and value 0', () => {
+ const ret = component.getStep('uint', 0);
expect(ret).toBe(1);
});
- it('should return the correct step for type int64_t and value 1', () => {
- const ret = component.getStep('int64_t', 1);
+ it('should return the correct step for type int and value 1', () => {
+ const ret = component.getStep('int', 1);
expect(ret).toBe(1);
});
- it('should return the correct step for type int64_t and value null', () => {
- const ret = component.getStep('int64_t', null);
+ it('should return the correct step for type int and value null', () => {
+ const ret = component.getStep('int', null);
expect(ret).toBe(1);
});
- it('should return the correct step for type size_t and value 2', () => {
- const ret = component.getStep('size_t', 2);
+ it('should return the correct step for type size and value 2', () => {
+ const ret = component.getStep('size', 2);
expect(ret).toBe(1);
});
expect(ret).toBe(1);
});
- it('should return the correct step for type double and value 1', () => {
- const ret = component.getStep('double', 1);
+ it('should return the correct step for type float and value 1', () => {
+ const ret = component.getStep('float', 1);
expect(ret).toBe(0.1);
});
- it('should return the correct step for type double and value 0.1', () => {
- const ret = component.getStep('double', 0.1);
+ it('should return the correct step for type float and value 0.1', () => {
+ const ret = component.getStep('float', 0.1);
expect(ret).toBe(0.1);
});
- it('should return the correct step for type double and value 0.02', () => {
- const ret = component.getStep('double', 0.02);
+ it('should return the correct step for type float and value 0.02', () => {
+ const ret = component.getStep('float', 0.02);
expect(ret).toBe(0.01);
});
- it('should return the correct step for type double and value 0.003', () => {
- const ret = component.getStep('double', 0.003);
+ it('should return the correct step for type float and value 0.003', () => {
+ const ret = component.getStep('float', 0.003);
expect(ret).toBe(0.001);
});
- it('should return the correct step for type double and value null', () => {
- const ret = component.getStep('double', null);
+ it('should return the correct step for type float and value null', () => {
+ const ret = component.getStep('float', null);
expect(ret).toBe(0.1);
});
getType(type: string): any {
const knownTypes = [
{
- name: 'uint64_t',
+ name: 'uint',
inputType: 'number',
humanReadable: this.i18n('Positive integer value'),
defaultMin: 0,
allowsNegative: false
},
{
- name: 'int64_t',
+ name: 'int',
inputType: 'number',
humanReadable: this.i18n('Integer value'),
patternHelpText: this.i18n('The entered value needs to be a number.'),
allowsNegative: true
},
{
- name: 'size_t',
+ name: 'size',
inputType: 'number',
humanReadable: this.i18n('Positive integer value (size)'),
defaultMin: 0,
allowsNegative: false
},
{
- name: 'double',
+ name: 'float',
inputType: 'number',
humanReadable: this.i18n('Decimal value'),
patternHelpText: this.i18n('The entered value needs to be a number or decimal.'),
allowsNegative: true
},
{
- name: 'std::string',
+ name: 'str',
inputType: 'text',
humanReadable: this.i18n('Text'),
isNumberType: false
},
{
- name: 'entity_addr_t',
+ name: 'addr',
inputType: 'text',
humanReadable: this.i18n('IPv4 or IPv6 address'),
patternHelpText: this.i18n('The entered value needs to be a valid IP address.'),
isNumberType: false
},
{
- name: 'uuid_d',
+ name: 'uuid',
inputType: 'text',
humanReadable: this.i18n('UUID'),
patternHelpText: this.i18n(
validators.push(Validators.min(typeParams.defaultMin));
}
- if (configOption.type === 'double') {
+ if (configOption.type === 'float') {
validators.push(CdValidators.decimalNumber());
} else {
validators.push(CdValidators.number(typeParams.allowsNegative));
}
return validators;
- } else if (configOption.type === 'entity_addr_t') {
+ } else if (configOption.type === 'addr') {
return [CdValidators.ip()];
- } else if (configOption.type === 'uuid_d') {
+ } else if (configOption.type === 'uuid') {
return [CdValidators.uuid()];
}
}
getStep(type: string, value: number): number | undefined {
- const numberTypes = ['uint64_t', 'int64_t', 'size_t', 'secs'];
+ const numberTypes = ['uint', 'int', 'size', 'secs'];
if (numberTypes.includes(type)) {
return 1;
}
- if (type === 'double') {
+ if (type === 'float') {
if (value !== null) {
const stringVal = value.toString();
if (stringVal.indexOf('.') !== -1) {
- // Value type double and contains decimal characters
+ // Value type float and contains decimal characters
const decimal = value.toString().split('.');
return Math.pow(10, -decimal[1].length);
}