mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-24 14:31:41 +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:
@@ -509,15 +509,26 @@ describe('CardViewTextItemComponent', () => {
|
|||||||
expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, 'updated-value');
|
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);
|
const cardViewUpdateService = TestBed.inject(CardViewUpdateService);
|
||||||
spyOn(cardViewUpdateService, 'update');
|
spyOn(cardViewUpdateService, 'update');
|
||||||
component.property.isValid = () => false;
|
component.property.isValid = () => false;
|
||||||
|
|
||||||
updateTextField(component.property.key, 'updated-value');
|
updateTextField(component.property.key, '@invalid-value');
|
||||||
await fixture.whenStable();
|
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 () => {
|
it('should set the errorMessages properly if the editedValue is invalid', async () => {
|
||||||
@@ -530,6 +541,15 @@ describe('CardViewTextItemComponent', () => {
|
|||||||
expect(component.errors).toBe(expectedErrorMessages);
|
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', () => {
|
it('should render the error', () => {
|
||||||
component.errors = expectedErrorMessages;
|
component.errors = expectedErrorMessages;
|
||||||
component.editable = true;
|
component.editable = true;
|
||||||
@@ -645,7 +665,7 @@ describe('CardViewTextItemComponent', () => {
|
|||||||
editable: true
|
editable: true
|
||||||
});
|
});
|
||||||
component.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) });
|
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
@@ -776,7 +796,7 @@ describe('CardViewTextItemComponent', () => {
|
|||||||
editable: true
|
editable: true
|
||||||
});
|
});
|
||||||
component.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) });
|
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
@@ -128,12 +128,13 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(): void {
|
update(): void {
|
||||||
|
this.resetErrorMessages();
|
||||||
if (this.property.isValid(this.editedValue)) {
|
if (this.property.isValid(this.editedValue)) {
|
||||||
this.property.value = this.prepareValueForUpload(this.property, this.editedValue);
|
this.property.value = this.prepareValueForUpload(this.property, this.editedValue);
|
||||||
this.cardViewUpdateService.update({ ...this.property } as CardViewTextItemModel, this.property.value);
|
this.cardViewUpdateService.update({ ...this.property } as CardViewTextItemModel, this.property.value);
|
||||||
this.resetErrorMessages();
|
|
||||||
} else {
|
} else {
|
||||||
this.errors = this.property.getValidationErrors(this.editedValue);
|
this.errors = this.property.getValidationErrors(this.editedValue);
|
||||||
|
this.cardViewUpdateService.update({ ...this.property } as CardViewTextItemModel, this.editedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user