| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0 |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| |
| import {async, ComponentFixture, TestBed} from "@angular/core/testing"; |
| import {TextFieldComponent} from "./text-field.component"; |
| import {TextInputFieldModule} from "./text-field.module"; |
| |
| describe("TextFieldComponent", () => { |
| let component: TextFieldComponent; |
| let fixture: ComponentFixture<TextFieldComponent>; |
| |
| beforeEach(async(() => { |
| TestBed.configureTestingModule({ |
| imports: [ |
| TextInputFieldModule |
| ] |
| }).compileComponents(); |
| })); |
| |
| beforeEach(() => { |
| fixture = TestBed.createComponent(TextFieldComponent); |
| component = fixture.componentInstance; |
| fixture.detectChanges(); |
| }); |
| |
| it("should be created", () => { |
| expect(component).toBeTruthy(); |
| }); |
| |
| it("should resize the textarea to always show all text", () => { |
| component.inputElement.nativeElement.style.height = "1px"; |
| component.inputElement.nativeElement.value = |
| "A text that has to be of a certain length so it needs multiple lines to display. This should be enough."; |
| component.resize(); |
| expect(component.inputElement.nativeElement.style.height).toEqual(component.inputElement.nativeElement.scrollHeight + "px"); |
| }); |
| |
| it("should emit appFocusOut", () => { |
| spyOn(component.appFocusOut, "emit").and.callThrough(); |
| component.onFocusOut(); |
| expect(component.appFocusOut.emit).toHaveBeenCalled(); |
| }); |
| |
| it("should call resize() and emit value on appInputValue", () => { |
| spyOn(component.appInputValue, "emit").and.callThrough(); |
| spyOn(component, "resize").and.callThrough(); |
| const value = "value"; |
| component.onInput(value); |
| expect(component.resize).toHaveBeenCalled(); |
| expect(component.appInputValue.emit).toHaveBeenCalledWith(value); |
| }); |
| |
| }); |