1 import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
2 import { DEBOUNCE_TIMER, DynamicInputComboboxDirective } from './dynamic-input-combobox.directive';
3 import { Subject } from 'rxjs';
4 import { Component, EventEmitter } from '@angular/core';
5 import { ComboBoxItem } from '../models/combo-box.model';
8 template: `<div cdDynamicInputCombobox
12 items: ComboBoxItem[] = [{ content: 'Item1', name: 'Item1' }];
13 searchSubject = new Subject<string>();
14 selectedItems: ComboBoxItem[] = [];
15 updatedItems = new EventEmitter<ComboBoxItem[]>();
18 describe('DynamicInputComboboxDirective', () => {
20 let component: MockComponent;
21 let fixture: ComponentFixture<MockComponent>;
22 let directive: DynamicInputComboboxDirective;
25 TestBed.configureTestingModule({
26 declarations: [DynamicInputComboboxDirective, MockComponent],
27 }).compileComponents();
29 fixture = TestBed.createComponent(MockComponent);
30 component = fixture.componentInstance;
32 directive = fixture.debugElement.children[0].injector.get(DynamicInputComboboxDirective);
33 fixture.detectChanges();
37 directive.ngOnDestroy();
40 it('should create an instance', () => {
41 expect(directive).toBeTruthy();
44 it('should update items when input is given', fakeAsync(() => {
45 const newItem = 'NewItem';
46 directive.onInput(newItem);
49 expect(directive.items[0].content).toBe(newItem);
52 it('should not unselect selected items', fakeAsync(() => {
53 const selectedItems: ComboBoxItem[] = [{
54 content: 'selectedItem',
59 directive.items = selectedItems;
61 directive.onSelected(selectedItems);
64 directive.onInput(selectedItems[0].content);
67 expect(directive.items[0].content).toBe(selectedItems[0].content);
68 expect(directive.items[0].selected).toBeTruthy();