Skip to content

Commit

Permalink
[ADF-5204] Metadata - Error message still appears after exiting Edit …
Browse files Browse the repository at this point in the history
…form (#5922)

* show error only in editable mode

* reset errors when reset value

* update tests
  • Loading branch information
pionnegru committed Jul 29, 2020
1 parent 1581cfc commit 54df083
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Expand Up @@ -53,7 +53,7 @@

<mat-error [attr.data-automation-id]="'card-textitem-error-' + property.key"
class="adf-textitem-editable-error"
*ngIf="hasErrors">
*ngIf="isEditable && hasErrors">
<ul>
<li *ngFor="let error of errors">{{ error.message | translate: error }}</li>
</ul>
Expand Down
Expand Up @@ -454,6 +454,40 @@ describe('CardViewTextItemComponent', () => {
expect(component.errors).toBe(expectedErrorMessages);
});

it('should render the error when the editedValue is invalid', async () => {
const expectedErrorMessages = [{ message: 'Something went wrong' } as CardViewItemValidator];
component.property.isValid = () => false;
component.property.getValidationErrors = () => expectedErrorMessages;
component.editable = true;
component.ngOnChanges();
fixture.detectChanges();
await fixture.whenStable();

updateTextField(component.property.key, 'updated-value');
const errorMessage = fixture.debugElement.nativeElement.querySelector('.adf-textitem-editable-error').textContent;
expect(errorMessage).toBe('Something went wrong');
});

it('should reset erros when exiting editable mode', async () => {
let errorMessage: string;
const expectedErrorMessages = [{ message: 'Something went wrong' } as CardViewItemValidator];
component.property.isValid = () => false;
component.property.getValidationErrors = () => expectedErrorMessages;
component.editable = true;
component.ngOnChanges();
fixture.detectChanges();
await fixture.whenStable();

updateTextField(component.property.key, 'updated-value');

component.editable = false;
component.ngOnChanges();
fixture.detectChanges();
errorMessage = fixture.debugElement.nativeElement.querySelector('.adf-textitem-editable-error');
expect(errorMessage).toBe(null);
expect(component.errors).toEqual([]);
});

it('should update the property value after a successful update attempt', async () => {
component.property.isValid = () => true;
component.update();
Expand Down
Expand Up @@ -90,6 +90,8 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
} else {
this.editedValue = this.property.displayValue;
}

this.resetErrorMessages();
}

private resetErrorMessages() {
Expand Down

0 comments on commit 54df083

Please sign in to comment.