mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[AAE-14699] Improved card view text item component update (#8597)
* AAE-14699: Improved card view text item component update * AAE-14699: updated unit tests
This commit is contained in:
parent
9bf30a6b66
commit
6ec394da5f
@ -509,15 +509,26 @@ describe('CardViewTextItemComponent', () => {
|
||||
expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, 'updated-value');
|
||||
});
|
||||
|
||||
it('should NOT trigger the update event if the editedValue is invalid', async () => {
|
||||
it('should trigger the update event if the editedValue is NOT invalid', async () => {
|
||||
const cardViewUpdateService = TestBed.inject(CardViewUpdateService);
|
||||
spyOn(cardViewUpdateService, 'update');
|
||||
component.property.isValid = () => false;
|
||||
|
||||
updateTextField(component.property.key, 'updated-value');
|
||||
updateTextField(component.property.key, '@invalid-value');
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(cardViewUpdateService.update).not.toHaveBeenCalled();
|
||||
expect(cardViewUpdateService.update).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should trigger the update event if the editedValue is valid', async () => {
|
||||
const cardViewUpdateService = TestBed.inject(CardViewUpdateService);
|
||||
spyOn(cardViewUpdateService, 'update');
|
||||
component.property.isValid = () => true;
|
||||
|
||||
updateTextField(component.property.key, 'valid-value');
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(cardViewUpdateService.update).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set the errorMessages properly if the editedValue is invalid', async () => {
|
||||
@ -530,6 +541,15 @@ describe('CardViewTextItemComponent', () => {
|
||||
expect(component.errors).toBe(expectedErrorMessages);
|
||||
});
|
||||
|
||||
it('should set the errorMessages properly if the editedValue is valid', async () => {
|
||||
component.property.isValid = () => true;
|
||||
|
||||
updateTextField(component.property.key, 'updated-value');
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.errors).toEqual([]);
|
||||
});
|
||||
|
||||
it('should render the error', () => {
|
||||
component.errors = expectedErrorMessages;
|
||||
component.editable = true;
|
||||
@ -645,7 +665,7 @@ describe('CardViewTextItemComponent', () => {
|
||||
editable: true
|
||||
});
|
||||
component.editable = true;
|
||||
component.property.validators.push(new CardViewItemIntValidator());
|
||||
component.property.validators?.push(new CardViewItemIntValidator());
|
||||
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
|
||||
fixture.detectChanges();
|
||||
});
|
||||
@ -776,7 +796,7 @@ describe('CardViewTextItemComponent', () => {
|
||||
editable: true
|
||||
});
|
||||
component.editable = true;
|
||||
component.property.validators.push(new CardViewItemFloatValidator());
|
||||
component.property.validators?.push(new CardViewItemFloatValidator());
|
||||
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
@ -128,12 +128,13 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
||||
}
|
||||
|
||||
update(): void {
|
||||
this.resetErrorMessages();
|
||||
if (this.property.isValid(this.editedValue)) {
|
||||
this.property.value = this.prepareValueForUpload(this.property, this.editedValue);
|
||||
this.cardViewUpdateService.update({ ...this.property } as CardViewTextItemModel, this.property.value);
|
||||
this.resetErrorMessages();
|
||||
} else {
|
||||
this.errors = this.property.getValidationErrors(this.editedValue);
|
||||
this.cardViewUpdateService.update({ ...this.property } as CardViewTextItemModel, this.editedValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user