aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/form-elements/dropdown/dropdown.component.spec.ts
blob: 1c0cb4de6ab24321c60dc975e7faf138100b5842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DropDownComponent } from './dropdown.component';
import { IDropDownOption, DropDownTypes } from "./dropdown-models";
import { FormsModule } from "@angular/forms";
import {SvgIconModule} from "../../svg-icon/svg-icon.module";


const label:string = "DropDown example";
const placeHolder:string = "Please choose option";
const options:IDropDownOption[] = [
    {
        label:'First Option',
        value: 'First Option'
    },
    {
        label:'Second Option',
        value: 'Second Option'
    },
    {
        label:'Third Option',
        value: 'Third Option'
    }
];

describe('DropDown component', () => {
    let fixture: ComponentFixture<DropDownComponent>;
    let component: DropDownComponent;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [ DropDownComponent ],
            imports:[
                FormsModule,
                SvgIconModule
            ]
        }).compileComponents();
        fixture = TestBed.createComponent(DropDownComponent);
        component = fixture.componentInstance;

    }));

    beforeEach(()=>{
        component.label = label;
        component.placeHolder = placeHolder;
        component.options = options;
        component.type = DropDownTypes.Regular;
        console.log('herer we got component', component)
        fixture.detectChanges();
    });

    it('component should be created', () => {
        expect(component).toBeTruthy();
    });

    it('component should export the selected value', () => {
        const option = options[1];
        component.selectOption(option);
        fixture.detectChanges();
        expect(component.selectedOption).toEqual(option);
    });

    it('component should have autocomplite', () => {
        expect(component.options.length).toEqual(3);
        component.type = DropDownTypes.Auto;
        component.filterValue = 'testERrorotesttresadfadfasdfasf';
        fixture.detectChanges();
        component.filterOptions(component.filterValue);
        expect(component.options.length).toEqual(0);
    });

});