From 25915e753e6cdb17b55e080941410c4451eb9a21 Mon Sep 17 00:00:00 2001 From: "Lisa Flinn (She/Her)" Date: Fri, 17 May 2024 12:02:42 +0100 Subject: [PATCH 1/2] fix broken unit test and add new test --- .../inputtextarea/inputtextarea.spec.ts | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/app/components/inputtextarea/inputtextarea.spec.ts b/src/app/components/inputtextarea/inputtextarea.spec.ts index b3de182602e..5fa4e1394b9 100755 --- a/src/app/components/inputtextarea/inputtextarea.spec.ts +++ b/src/app/components/inputtextarea/inputtextarea.spec.ts @@ -3,6 +3,7 @@ import { By } from '@angular/platform-browser'; import { InputTextarea } from './inputtextarea'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { Component, DebugElement } from '@angular/core'; +import e from 'express'; @Component({ template: ` ` @@ -13,7 +14,7 @@ class TestInputTextArea { onResize(event) {} } -describe('InputTextarea', () => { +fdescribe('InputTextarea', () => { let fixture: ComponentFixture; let component: TestInputTextArea; beforeEach(() => { @@ -38,12 +39,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 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); }); From 7ee46dfb3c7822de5cbbdba42d4d9bf3163aca1c Mon Sep 17 00:00:00 2001 From: "Lisa Flinn (She/Her)" Date: Fri, 17 May 2024 12:04:54 +0100 Subject: [PATCH 2/2] format rm fdescribe change test description --- src/app/components/inputtextarea/inputtextarea.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/components/inputtextarea/inputtextarea.spec.ts b/src/app/components/inputtextarea/inputtextarea.spec.ts index 5fa4e1394b9..1cb0e249900 100755 --- a/src/app/components/inputtextarea/inputtextarea.spec.ts +++ b/src/app/components/inputtextarea/inputtextarea.spec.ts @@ -3,7 +3,6 @@ import { By } from '@angular/platform-browser'; import { InputTextarea } from './inputtextarea'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { Component, DebugElement } from '@angular/core'; -import e from 'express'; @Component({ template: ` ` @@ -14,7 +13,7 @@ class TestInputTextArea { onResize(event) {} } -fdescribe('InputTextarea', () => { +describe('InputTextarea', () => { let fixture: ComponentFixture; let component: TestInputTextArea; beforeEach(() => { @@ -50,7 +49,7 @@ fdescribe('InputTextarea', () => { expect(onResizeSpy).toHaveBeenCalledTimes(2); }); - it('should change autoResize and resize textarea', () => { + it('should change autoResize and resize scrollheight of textarea', () => { component.autoResize = true; fixture.detectChanges();