[MNT-23194] add long validators, correct filename typos (#9799)

* MNT-23194 add long validators, correct filename typos

* MNT-23194 improve unit tests, fix naming typos

* MNT-23194 change method name to more precise

* MNT-23194 remove redundant type definitions, change any type, add different notation integers parsing
This commit is contained in:
Grzegorz Jaśkowski
2024-06-21 10:07:26 +02:00
committed by GitHub
parent 4d2c489508
commit 6b8c064536
27 changed files with 345 additions and 84 deletions

View File

@@ -28,8 +28,8 @@ import {
CardViewBoolItemModel,
CardViewDatetimeItemModel,
CardViewSelectItemModel,
CardViewSelectItemProperties,
LogService
LogService,
CardViewLongItemModel
} from '@alfresco/adf-core';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { Constraint, Definition, Property as PropertyBase } from '@alfresco/js-api';
@@ -171,7 +171,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
});
@@ -189,7 +189,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAKE:NAME': 'API Fake response' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
expect(cardViewProperty.editable).toBe(false);
});
@@ -224,10 +224,10 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe('The Chariot Line');
expect(cardViewProperty.multiline).toBeFalsy();
expect((cardViewProperty as CardViewTextItemModel).multiline).toBeFalsy();
});
it('should translate properly the multiline and value attributes for d:mltext', () => {
@@ -236,10 +236,10 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe('The Chariot Line');
expect(cardViewProperty.multiline).toBeTruthy();
expect((cardViewProperty as CardViewTextItemModel).multiline).toBeTruthy();
});
it('should translate properly the value attribute for d:date', () => {
@@ -249,7 +249,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': expectedValue };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewDateItemModel = cardViewGroup[0].properties[0] as CardViewDateItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewDateItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(expectedValue);
});
@@ -261,7 +261,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': expectedValue };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewDatetimeItemModel = cardViewGroup[0].properties[0] as CardViewDatetimeItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewDatetimeItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(expectedValue);
});
@@ -272,7 +272,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': '1024' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewIntItemModel = cardViewGroup[0].properties[0] as CardViewIntItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(1024);
});
@@ -283,7 +283,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': 0 };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewIntItemModel = cardViewGroup[0].properties[0] as CardViewIntItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(0);
});
@@ -294,8 +294,8 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': '1024' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewIntItemModel = cardViewGroup[0].properties[0] as CardViewIntItemModel;
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewLongItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(1024);
});
@@ -305,7 +305,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': '1024.24' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewFloatItemModel = cardViewGroup[0].properties[0] as CardViewFloatItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(1024.24);
});
@@ -316,7 +316,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': 0 };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewFloatItemModel = cardViewGroup[0].properties[0] as CardViewFloatItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(0);
});
@@ -327,8 +327,8 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': '1024.24' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewFloatItemModel = cardViewGroup[0].properties[0] as CardViewFloatItemModel;
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTrue();
expect(cardViewProperty.value).toBe(1024.24);
});
@@ -338,7 +338,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': true };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewBoolItemModel = cardViewGroup[0].properties[0] as CardViewBoolItemModel;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewBoolItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(true);
});
@@ -363,7 +363,7 @@ describe('PropertyGroupTranslatorService', () => {
propertyValues = { 'FAS:PLAGUE': 'two' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, definition);
const cardViewProperty = cardViewGroup[0].properties[0] as CardViewSelectItemModel<CardViewSelectItemProperties<string>>;
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewSelectItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe('two');
});
@@ -428,5 +428,27 @@ describe('PropertyGroupTranslatorService', () => {
expect(cardViewProperty.key).toBe('properties.fk:emperor');
expect(cardViewProperty.editable).toBe(false);
});
it('should translate properly the value attribute for d:long', () => {
property.dataType = 'd:long';
propertyValues = { 'FAS:PLAGUE': '1024' };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewLongItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(1024);
});
it('should translate properly the value attribute for d:long and value is 0', () => {
property.dataType = 'd:long';
propertyValues = { 'FAS:PLAGUE': 0 };
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty = cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewLongItemModel).toBeTruthy();
expect(cardViewProperty.value).toBe(0);
});
});
});

View File

@@ -25,6 +25,7 @@ import {
CardViewSelectItemModel,
CardViewDatetimeItemModel,
CardViewIntItemModel,
CardViewLongItemModel,
CardViewFloatItemModel,
MultiValuePipe,
AppConfigService,
@@ -53,10 +54,12 @@ export const RECOGNISED_ECM_TYPES = [D_TEXT, D_MLTEXT, D_DATE, D_DATETIME, D_INT
export class PropertyGroupTranslatorService {
valueSeparator: string;
constructor(private multiValuePipe: MultiValuePipe,
private decimalNumberPipe: DecimalNumberPipe,
private appConfig: AppConfigService,
private logService: LogService) {
constructor(
private multiValuePipe: MultiValuePipe,
private decimalNumberPipe: DecimalNumberPipe,
private appConfig: AppConfigService,
private logService: LogService
) {
this.valueSeparator = this.appConfig.get<string>('content-metadata.multi-value-pipe-separator');
}
@@ -123,42 +126,57 @@ export class PropertyGroupTranslatorService {
} else {
switch (dataType) {
case D_MLTEXT:
cardViewItemProperty = new CardViewTextItemModel(Object.assign(propertyDefinition, {
multiline: true
}));
cardViewItemProperty = new CardViewTextItemModel(
Object.assign(propertyDefinition, {
multiline: true
})
);
break;
case D_INT:
cardViewItemProperty = new CardViewIntItemModel(
Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
})
);
break;
case D_LONG:
cardViewItemProperty = new CardViewIntItemModel(Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
}));
cardViewItemProperty = new CardViewLongItemModel(
Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
})
);
break;
case D_FLOAT:
case D_DOUBLE:
cardViewItemProperty = new CardViewFloatItemModel(Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [
{ pipe: this.decimalNumberPipe },
{ pipe: this.multiValuePipe, params: [this.valueSeparator] }
]
}));
cardViewItemProperty = new CardViewFloatItemModel(
Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.decimalNumberPipe }, { pipe: this.multiValuePipe, params: [this.valueSeparator] }]
})
);
break;
case D_DATE:
cardViewItemProperty = new CardViewDateItemModel(Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
}));
cardViewItemProperty = new CardViewDateItemModel(
Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
})
);
break;
case D_DATETIME:
cardViewItemProperty = new CardViewDatetimeItemModel(Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
}));
cardViewItemProperty = new CardViewDatetimeItemModel(
Object.assign(propertyDefinition, {
multivalued: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
})
);
break;
case D_BOOLEAN:
@@ -167,11 +185,13 @@ export class PropertyGroupTranslatorService {
case D_TEXT:
default:
cardViewItemProperty = new CardViewTextItemModel(Object.assign(propertyDefinition, {
multivalued: isMultiValued,
multiline: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
}));
cardViewItemProperty = new CardViewTextItemModel(
Object.assign(propertyDefinition, {
multivalued: isMultiValued,
multiline: isMultiValued,
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
})
);
}
}