Skip to content

Commit

Permalink
Merge pull request #15604 from RogueTea/unit-test-input-text-area
Browse files Browse the repository at this point in the history
Input text area: fix unit test and expand on testing suite
  • Loading branch information
cetincakiroglu authored May 30, 2024
2 parents 81ccac4 + 7ee46df commit 5c5b2e9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/app/components/inputtextarea/inputtextarea.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,37 @@ describe('InputTextarea', () => {

const onResizeSpy = spyOn(component, 'onResize').and.callThrough();
const inputTextEl = fixture.debugElement.query(By.css('textarea'));
inputTextEl.nativeElement.dispatchEvent(new Event('focus'));
inputTextEl.nativeElement.value = 'primeng';
inputTextEl.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();

inputTextEl.nativeElement.value = 'primeng rocks!';
inputTextEl.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();

expect(onResizeSpy).toHaveBeenCalledTimes(2);
});

it('should change autoResize and resize scrollheight of textarea', () => {
component.autoResize = true;
fixture.detectChanges();

inputTextEl.nativeElement.dispatchEvent(new Event('blur'));
const onResizeSpy = spyOn(component, 'onResize').and.callThrough();
const inputTextEl = fixture.debugElement.query(By.css('textarea'));
const initialScrollHeight = inputTextEl.nativeElement.scrollHeight;

inputTextEl.nativeElement.value = 'primeng';
inputTextEl.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();

expect(inputTextEl.nativeElement.scrollHeight).toBeGreaterThan(initialScrollHeight);
const newScrollHeight = inputTextEl.nativeElement.scrollHeight;

inputTextEl.nativeElement.value = 'primeng rocks!';
inputTextEl.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();

expect(inputTextEl.nativeElement.scrollHeight).toBeGreaterThan(newScrollHeight);
expect(onResizeSpy).toHaveBeenCalledTimes(2);
});

Expand Down

0 comments on commit 5c5b2e9

Please sign in to comment.