Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pionnegru committed Jul 28, 2020
1 parent 80d2ea7 commit a9f7155
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
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

0 comments on commit a9f7155

Please sign in to comment.