Skip to content

Commit

Permalink
[ADF-5231] The protected flag for properties should not be editable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrn committed May 25, 2021
1 parent 65cbd57 commit 4b3a7f4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Expand Up @@ -24,4 +24,8 @@ export interface Property {
mandatory: boolean;
multiValued: boolean;
editable?: boolean;
protected?: boolean;
enforced?: boolean;
indexed?: boolean;
url?: string;
}
Expand Up @@ -168,6 +168,25 @@ describe('PropertyGroupTranslatorService', () => {
const cardViewProperty: CardViewTextItemModel = <CardViewTextItemModel> cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy('Property should be instance of CardViewTextItemModel');
});

it('should not edit the protected fields', () => {
property.name = 'FAKE:NAME';
property.title = 'Fake Title';
property.dataType = 'd:text';
property.defaultValue = 'Fake value';
property.protected = true;
propertyGroups.push({
title: 'Fake Title',
properties: [property]
});

propertyValues = { 'FAKE:NAME': 'API Fake response' };

const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
const cardViewProperty: CardViewTextItemModel = <CardViewTextItemModel> cardViewGroup[0].properties[0];
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy('Property should be instance of CardViewTextItemModel');
expect(cardViewProperty.editable).toBe(false);
});
});

describe('Different types attributes', () => {
Expand Down Expand Up @@ -381,5 +400,26 @@ describe('PropertyGroupTranslatorService', () => {
expect(cardViewProperty.value).toBe('default');
expect(cardViewProperty.key).toBe('properties.fk:brendonstare');
});

it('should not edit the protected fields', () => {
const propertyBase = <PropertyBase> {
'id': 'fk:emperor',
'title': 'Emperor',
'description': 'is watching the dark emperor',
'dataType': 'd:text',
'isMultiValued': true,
'isMandatory': true,
'defaultValue': 'default',
'isMandatoryEnforced': true,
'isProtected': true
};

const cardViewProperty = service.translateProperty(propertyBase, null, true);

expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy('Property should be instance of CardViewTextItemModel');
expect(cardViewProperty.value).toBe('default');
expect(cardViewProperty.key).toBe('properties.fk:emperor');
expect(cardViewProperty.editable).toBe(false);
});
});
});
Expand Up @@ -79,7 +79,7 @@ export class PropertyGroupTranslatorService {
value: startValue ? startValue : property.defaultValue,
key: `${prefix}${property.id}`,
default: property.defaultValue,
editable: !!allowEditing ? allowEditing : false,
editable: property.isProtected ? false : allowEditing,
constraints: property?.constraints
};

Expand Down Expand Up @@ -107,7 +107,7 @@ export class PropertyGroupTranslatorService {
value: propertyValue,
key: `${prefix}${property.name}`,
default: property.defaultValue,
editable: property.editable !== undefined ? property.editable : true,
editable: property.protected ? false : property.editable !== undefined ? property.editable : true,
constraints: constraints
};

Expand Down

0 comments on commit 4b3a7f4

Please sign in to comment.