2023-05-23 15:02:54 -07:00
|
|
|
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
|
|
|
|
import {
|
|
|
|
|
FormsModule,
|
|
|
|
|
NG_VALUE_ACCESSOR,
|
2024-12-13 00:27:30 -08:00
|
|
|
ReactiveFormsModule,
|
2023-05-23 15:02:54 -07:00
|
|
|
} from '@angular/forms'
|
|
|
|
|
import { TextComponent } from './text.component'
|
|
|
|
|
|
|
|
|
|
describe('TextComponent', () => {
|
|
|
|
|
let component: TextComponent
|
|
|
|
|
let fixture: ComponentFixture<TextComponent>
|
|
|
|
|
let input: HTMLInputElement
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
|
providers: [],
|
2025-01-01 22:26:53 -08:00
|
|
|
imports: [FormsModule, ReactiveFormsModule, TextComponent],
|
2023-05-23 15:02:54 -07:00
|
|
|
}).compileComponents()
|
|
|
|
|
|
|
|
|
|
fixture = TestBed.createComponent(TextComponent)
|
|
|
|
|
fixture.debugElement.injector.get(NG_VALUE_ACCESSOR)
|
|
|
|
|
component = fixture.componentInstance
|
|
|
|
|
fixture.detectChanges()
|
|
|
|
|
input = component.inputField.nativeElement
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should support use of input field', () => {
|
|
|
|
|
expect(component.value).toBeUndefined()
|
2025-04-19 22:52:46 -07:00
|
|
|
input.value = 'foo'
|
|
|
|
|
input.dispatchEvent(new Event('input'))
|
|
|
|
|
fixture.detectChanges()
|
|
|
|
|
expect(component.value).toBe('foo')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should support suggestion', () => {
|
|
|
|
|
component.value = 'foo'
|
|
|
|
|
component.suggestion = 'foo'
|
|
|
|
|
expect(component.getSuggestion()).toBe('')
|
|
|
|
|
component.value = 'bar'
|
|
|
|
|
expect(component.getSuggestion()).toBe('foo')
|
|
|
|
|
component.applySuggestion()
|
|
|
|
|
fixture.detectChanges()
|
|
|
|
|
expect(component.value).toBe('foo')
|
2023-05-23 15:02:54 -07:00
|
|
|
})
|
|
|
|
|
})
|