-
Notifications
You must be signed in to change notification settings - Fork 366
/
dynamic-ng-bootstrap-calendar.component.spec.ts
107 lines (75 loc) · 3.46 KB
/
dynamic-ng-bootstrap-calendar.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
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 { NgbDatepicker, NgbDatepickerModule } from "@ng-bootstrap/ng-bootstrap";
import { DynamicDatePickerModel, DynamicFormsCoreModule, DynamicFormService } from "@ng-dynamic-forms/core";
import { DynamicNGBootstrapCalendarComponent } from "./dynamic-ng-bootstrap-calendar.component";
describe("DynamicNGBootstrapCalendarComponent test suite", () => {
let testModel = new DynamicDatePickerModel({id: "calendar"}),
formModel = [testModel],
formGroup: FormGroup,
fixture: ComponentFixture<DynamicNGBootstrapCalendarComponent>,
component: DynamicNGBootstrapCalendarComponent,
debugElement: DebugElement,
testElement: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
NoopAnimationsModule,
TextMaskModule,
NgbDatepickerModule,
DynamicFormsCoreModule
],
declarations: [DynamicNGBootstrapCalendarComponent]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(DynamicNGBootstrapCalendarComponent);
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(`ngb-datepicker[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 DynamicDatePickerModel).toBe(true);
expect(component.ngbCalendar instanceof NgbDatepicker).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 ngb-datepicker 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();
});
});