-
Notifications
You must be signed in to change notification settings - Fork 368
/
dynamic-primeng-dropdown.component.spec.ts
108 lines (76 loc) · 3.5 KB
/
dynamic-primeng-dropdown.component.spec.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { TestBed, async, inject, ComponentFixture } from "@angular/core/testing";
import { DebugElement } from "@angular/core";
import { ReactiveFormsModule, FormGroup, FormControl } from "@angular/forms";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { By } from "@angular/platform-browser";
import { TextMaskModule } from "angular2-text-mask";
import { Dropdown, DropdownModule } from "primeng/primeng";
import { DynamicFormsCoreModule, DynamicFormService, DynamicSelectModel } from "@ng-dynamic-forms/core";
import { DynamicPrimeNGDropdownComponent } from "./dynamic-primeng-dropdown.component";
describe("DynamicPrimeNGDropdownComponent test suite", () => {
let testModel = new DynamicSelectModel({id: "select", options: [{value: "One"}, {value: "Two"}], value: "One"}),
formModel = [testModel],
formGroup: FormGroup,
fixture: ComponentFixture<DynamicPrimeNGDropdownComponent>,
component: DynamicPrimeNGDropdownComponent,
debugElement: DebugElement,
testElement: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
NoopAnimationsModule,
TextMaskModule,
DropdownModule,
DynamicFormsCoreModule
],
declarations: [DynamicPrimeNGDropdownComponent]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(DynamicPrimeNGDropdownComponent);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
});
}));
beforeEach(inject([DynamicFormService], (service: DynamicFormService) => {
formGroup = service.createFormGroup(formModel);
component.group = formGroup;
component.model = testModel;
fixture.detectChanges();
testElement = debugElement.query(By.css(`p-dropdown[id="${testModel.id}"]`));
}));
it("should initialize correctly", () => {
expect(component.control instanceof FormControl).toBe(true);
expect(component.group instanceof FormGroup).toBe(true);
expect(component.model instanceof DynamicSelectModel).toBe(true);
expect(component.pDropdown instanceof Dropdown).toBe(true);
expect(component.viewChild instanceof Dropdown).toBe(true);
expect(component.blur).toBeDefined();
expect(component.change).toBeDefined();
expect(component.focus).toBeDefined();
expect(component.onBlur).toBeDefined();
expect(component.onChange).toBeDefined();
expect(component.onFocus).toBeDefined();
expect(component.hasFocus).toBe(false);
expect(component.isValid).toBe(true);
expect(component.isInvalid).toBe(false);
expect(component.showErrorMessages).toBe(false);
});
it("should have an p-dropdown element", () => {
expect(testElement instanceof DebugElement).toBe(true);
});
it("should emit blur event", () => {
spyOn(component.blur, "emit");
component.onBlur(null);
expect(component.blur.emit).toHaveBeenCalled();
});
it("should emit change event", () => {
spyOn(component.change, "emit");
component.onChange(null);
expect(component.change.emit).toHaveBeenCalled();
});
it("should emit focus event", () => {
spyOn(component.focus, "emit");
component.onFocus(null);
expect(component.focus.emit).toHaveBeenCalled();
});
});