[MNT-21920] Fix Card View Integers initialization when they are set to 0 (#6320)

* [MNT-21920] Fix Card View Integers initialization when they are set to 0

* Add unit tests
This commit is contained in:
davidcanonieto
2020-11-10 10:07:23 +00:00
committed by GitHub
parent 11f3d2405c
commit a9f9e18a1a
3 changed files with 41 additions and 11 deletions

View File

@@ -201,7 +201,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
showGroup(group: CardViewGroup): boolean {
const properties = group.properties.filter((property) => {
return !!property.displayValue;
return !this.isEmpty(property.displayValue);
});
return properties.length > 0;
@@ -225,4 +225,8 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
event.stopPropagation();
}
}
private isEmpty(value: any): boolean {
return value === undefined || value === null || value === '';
}
}

View File

@@ -86,14 +86,14 @@ describe('PropertyGroupTranslatorService', () => {
mandatory: false,
multiValued: false
},
{
name: 'FAS:ALOY',
title: 'title',
dataType: 'd:text',
defaultValue: 'defaultValue',
mandatory: false,
multiValued: false
}];
{
name: 'FAS:ALOY',
title: 'title',
dataType: 'd:text',
defaultValue: 'defaultValue',
mandatory: false,
multiValued: false
}];
propertyGroups.push(propertyGroup);
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
@@ -253,6 +253,17 @@ describe('PropertyGroupTranslatorService', () => {
expect(cardViewProperty.value).toBe(1024);
});
it('should translate properly the value attribute for d:int and value is 0', () => {
property.dataType = 'd:int';
propertyValues = { 'FAS:PLAGUE': 0 };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewIntItemModel = <CardViewIntItemModel> cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy('Property should be instance of CardViewIntItemModel');
expect(cardViewProperty.value).toBe(0);
});
it('should translate properly the value attribute for d:long', () => {
property.dataType = 'd:long';
@@ -275,6 +286,17 @@ describe('PropertyGroupTranslatorService', () => {
expect(cardViewProperty.value).toBe(1024.24);
});
it('should translate properly the value attribute for d:float and value is 0', () => {
property.dataType = 'd:float';
propertyValues = { 'FAS:PLAGUE': 0 };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewFloatItemModel = <CardViewFloatItemModel> cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy('Property should be instance of CardViewFloatItemModel');
expect(cardViewProperty.value).toBe(0);
});
it('should translate properly the value attribute for d:double', () => {
property.dataType = 'd:double';
@@ -309,7 +331,7 @@ describe('PropertyGroupTranslatorService', () => {
}
}
]
} as Constraint ]
} as Constraint]
};
property.dataType = 'd:text';
propertyValues = { 'FAS:PLAGUE': 'two' };

View File

@@ -77,7 +77,7 @@ export class PropertyGroupTranslatorService {
private translate(property: Property, propertyValues: any, constraints: Constraint[]): CardViewItem {
let propertyValue: any;
if (propertyValues && propertyValues[property.name]) {
if (propertyValues && !this.isEmpty(propertyValues[property.name])) {
propertyValue = propertyValues[property.name];
}
@@ -159,4 +159,8 @@ export class PropertyGroupTranslatorService {
this.logService.error(`Unknown type for mapping: ${ecmPropertyType}`);
}
}
private isEmpty(value: any): boolean {
return value === undefined || value === null || value === '';
}
}