Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input text area: fix unit test and expand on testing suite #15604

Merged
merged 2 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading