Skip to content

Commit

Permalink
fixed #6679 - InputTextArea Unit Test Improvement
Browse files Browse the repository at this point in the history
resize function controls added.
  • Loading branch information
yigitfindikli committed Oct 13, 2018
1 parent 9e2941f commit c4c5fa8
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/app/components/inputtextarea/inputtextarea.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Component, DebugElement } from '@angular/core';

@Component({
template: `<textarea (onResize)="onResize($event)" [autoResize]="autoResize" pInputTextarea></textarea>
template: `<textarea rows="1" cols="1" (onResize)="onResize($event)" [autoResize]="autoResize" pInputTextarea></textarea>
`
})
class TestInputTextArea {
Expand Down Expand Up @@ -55,4 +55,34 @@ describe('InputTextarea', () => {

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

it('should increment height', () => {
component.autoResize = true;
fixture.detectChanges();

const inputTextEl = fixture.debugElement.query(By.css('textarea'));
let cachedHeight = inputTextEl.nativeElement.style.height;
inputTextEl.nativeElement.value = "primeng";
inputTextEl.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();

expect(inputTextEl.nativeElement.style.height).toBeGreaterThan(cachedHeight);
expect(inputTextEl.nativeElement.style.overflow).toEqual("hidden");
});

it('should use resize with maxHeight', () => {
component.autoResize = true;
fixture.detectChanges();

const inputTextEl = fixture.debugElement.query(By.css('textarea'));
inputTextEl.nativeElement.style.maxHeight = 70+'px';
fixture.detectChanges();

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

expect(inputTextEl.nativeElement.style.height).toEqual(inputTextEl.nativeElement.style.maxHeight);
expect(inputTextEl.nativeElement.style.overflowY).toEqual("scroll");
});
});

0 comments on commit c4c5fa8

Please sign in to comment.