diff --git a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts index 3b785dc347..e76827bbaf 100644 --- a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts +++ b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts @@ -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 === ''; + } } diff --git a/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.spec.ts b/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.spec.ts index f8de0bab28..5126fb0782 100644 --- a/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.spec.ts +++ b/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.spec.ts @@ -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 = 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 = 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' }; diff --git a/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.ts b/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.ts index 68713f1969..a3803dec1f 100644 --- a/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.ts +++ b/lib/content-services/src/lib/content-metadata/services/property-groups-translator.service.ts @@ -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 === ''; + } }