Skip to content

Commit 984aa95

Browse files
author
Michael Seemann
committed
fix dialog spec
1 parent 22dacbe commit 984aa95

25 files changed

+1805
-1522
lines changed

projects/core/src/lib/checkbox/mdl-checkbox.component.spec.ts

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ class MdlTestCheckboxComponent {
2828
}
2929

3030
describe("Component: MdlCheckbox", () => {
31-
beforeEach(waitForAsync(() => {
32-
TestBed.configureTestingModule({
33-
imports: [MdlCheckboxModule.forRoot(), FormsModule],
34-
declarations: [MdlTestCheckboxComponent],
35-
});
36-
}));
31+
beforeEach(
32+
waitForAsync(() => {
33+
TestBed.configureTestingModule({
34+
imports: [MdlCheckboxModule.forRoot(), FormsModule],
35+
declarations: [MdlTestCheckboxComponent],
36+
});
37+
})
38+
);
3739

3840
it("should add the css class mdl-checkbox to the host element", () => {
3941
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
@@ -43,26 +45,29 @@ describe("Component: MdlCheckbox", () => {
4345
expect(checkboxEl.classList.contains("mdl-checkbox")).toBe(true);
4446
});
4547

46-
it("should support ngModel", waitForAsync(() => {
47-
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
48-
fixture.detectChanges();
49-
fixture.whenStable().then(() => {
50-
const testInstance = fixture.componentInstance;
48+
it(
49+
"should support ngModel",
50+
waitForAsync(() => {
51+
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
52+
fixture.detectChanges();
53+
fixture.whenStable().then(() => {
54+
const testInstance = fixture.componentInstance;
5155

52-
// let el = <HTMLInputElement> fixture.debugElement.query(By.css('input')).nativeElement;
53-
const checkboxComponent = fixture.debugElement.query(
54-
By.directive(MdlCheckboxComponent)
55-
).componentInstance;
56+
// let el = <HTMLInputElement> fixture.debugElement.query(By.css('input')).nativeElement;
57+
const checkboxComponent = fixture.debugElement.query(
58+
By.directive(MdlCheckboxComponent)
59+
).componentInstance;
5660

57-
testInstance.checkboxValue1 = true;
61+
testInstance.checkboxValue1 = true;
5862

59-
fixture.detectChanges();
60-
fixture.whenStable().then(() => {
61-
// but el.checked is not true ?
62-
expect(checkboxComponent.value).toEqual(true);
63+
fixture.detectChanges();
64+
fixture.whenStable().then(() => {
65+
// but el.checked is not true ?
66+
expect(checkboxComponent.value).toEqual(true);
67+
});
6368
});
64-
});
65-
}));
69+
})
70+
);
6671

6772
it("should change the value on click", () => {
6873
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
@@ -107,43 +112,49 @@ describe("Component: MdlCheckbox", () => {
107112
expect(checkboxEl.classList.contains("is-focused")).toBe(false);
108113
});
109114

110-
it("should fire a change event if the state changed", waitForAsync(() => {
111-
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
112-
fixture.detectChanges();
113-
114-
const instance = fixture.componentInstance;
115+
it(
116+
"should fire a change event if the state changed",
117+
waitForAsync(() => {
118+
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
119+
fixture.detectChanges();
115120

116-
spyOn(instance, "onChange");
121+
const instance = fixture.componentInstance;
117122

118-
fixture.debugElement
119-
.query(By.directive(MdlCheckboxComponent))
120-
.nativeElement.click();
123+
spyOn(instance, "onChange");
121124

122-
expect(instance.onChange).toHaveBeenCalledWith(true);
123-
}));
125+
fixture.debugElement
126+
.query(By.directive(MdlCheckboxComponent))
127+
.nativeElement.click();
124128

125-
it("should be possible to disable the checkbox", waitForAsync(() => {
126-
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
127-
fixture.detectChanges();
129+
expect(instance.onChange).toHaveBeenCalledWith(true);
130+
})
131+
);
128132

129-
const instance = fixture.componentInstance;
130-
const cbDebugElem = fixture.debugElement.query(
131-
By.directive(MdlCheckboxComponent)
132-
);
133+
it(
134+
"should be possible to disable the checkbox",
135+
waitForAsync(() => {
136+
const fixture = TestBed.createComponent(MdlTestCheckboxComponent);
137+
fixture.detectChanges();
133138

134-
cbDebugElem.componentInstance.setDisabledState(true);
135-
fixture.detectChanges();
139+
const instance = fixture.componentInstance;
140+
const cbDebugElem = fixture.debugElement.query(
141+
By.directive(MdlCheckboxComponent)
142+
);
136143

137-
const checkboxEl: HTMLElement = cbDebugElem.nativeElement;
138-
expect(checkboxEl.classList.contains("is-disabled")).toBe(
139-
true,
140-
"should have css is-disabled"
141-
);
144+
cbDebugElem.componentInstance.setDisabledState(true);
145+
fixture.detectChanges();
142146

143-
// should not change on click
144-
cbDebugElem.nativeElement.click();
145-
expect(instance.checkboxValue1).toEqual(false);
146-
}));
147+
const checkboxEl: HTMLElement = cbDebugElem.nativeElement;
148+
expect(checkboxEl.classList.contains("is-disabled")).toBe(
149+
true,
150+
"should have css is-disabled"
151+
);
152+
153+
// should not change on click
154+
cbDebugElem.nativeElement.click();
155+
expect(instance.checkboxValue1).toEqual(false);
156+
})
157+
);
147158

148159
it("should be possible to set a tabindex", () => {
149160
TestBed.overrideComponent(MdlTestCheckboxComponent, {

projects/core/src/lib/dialog-outlet/mdl-dialog-outlet.component.spec.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,34 @@ describe("MdlDialogOutletComponent", () => {
2525
let el: HTMLElement | undefined;
2626

2727
// create the tesbed
28-
beforeEach(waitForAsync(() => {
29-
TestBed.configureTestingModule({
30-
declarations: [],
31-
imports: [MdlDialogOutletModule.forRoot()],
32-
});
33-
}));
28+
beforeEach(
29+
waitForAsync(() => {
30+
TestBed.configureTestingModule({
31+
declarations: [],
32+
imports: [MdlDialogOutletModule.forRoot()],
33+
});
34+
})
35+
);
3436

3537
// now modify the dom and add a dialog-outlet element direct under the body
36-
beforeEach(waitForAsync(
37-
inject([DOCUMENT], (doc: Document) => {
38-
el = doc.createElement("dialog-outlet");
39-
doc.body.appendChild(el);
40-
})
41-
));
38+
beforeEach(
39+
waitForAsync(
40+
inject([DOCUMENT], (doc: Document) => {
41+
el = doc.createElement("dialog-outlet");
42+
doc.body.appendChild(el);
43+
})
44+
)
45+
);
4246

43-
afterEach(waitForAsync(
44-
inject([DOCUMENT], (doc: Document) => {
45-
if (el) {
46-
doc.body.removeChild(el);
47-
}
48-
})
49-
));
47+
afterEach(
48+
waitForAsync(
49+
inject([DOCUMENT], (doc: Document) => {
50+
if (el) {
51+
doc.body.removeChild(el);
52+
}
53+
})
54+
)
55+
);
5056

5157
// now we can boostrap our MdlDialogOutletComponent component
5258
it("should create the dialog-outlet outside the app-root", async () => {
@@ -61,12 +67,14 @@ describe("MdlDialogOutletComponent", () => {
6167
});
6268

6369
describe("MdlDialogInnerOutletComponent", () => {
64-
beforeEach(waitForAsync(() => {
65-
TestBed.configureTestingModule({
66-
declarations: [],
67-
imports: [TestDialogModul],
68-
});
69-
}));
70+
beforeEach(
71+
waitForAsync(() => {
72+
TestBed.configureTestingModule({
73+
declarations: [],
74+
imports: [TestDialogModul],
75+
});
76+
})
77+
);
7078

7179
it("should create the dialog-outlet if within the app-root", () => {
7280
const fixture = TestBed.createComponent(MdlTestViewComponent);

projects/core/src/lib/dialog/mdl-alert.component.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ class MdlTestComponent {
2525
}
2626

2727
describe("MdlAlert", () => {
28-
beforeEach(waitForAsync(() => {
29-
TestBed.configureTestingModule({
30-
imports: [MdlDialogModule.forRoot(), MdlDialogOutletModule],
31-
declarations: [MdlTestComponent],
32-
});
33-
}));
28+
beforeEach(
29+
waitForAsync(() => {
30+
TestBed.configureTestingModule({
31+
imports: [MdlDialogModule.forRoot(), MdlDialogOutletModule],
32+
declarations: [MdlTestComponent],
33+
});
34+
})
35+
);
3436

3537
it("should create, show and close the dialog", async () => {
3638
const fixture = TestBed.createComponent(MdlTestComponent);

projects/core/src/lib/dialog/mdl-dialog.component.spec.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,39 @@ class ModalComponent {
7777
}
7878

7979
describe("MdlDialog (embedded/declarative)", () => {
80-
beforeEach(waitForAsync(() => {
81-
TestBed.configureTestingModule({
82-
imports: [MdlDialogModule.forRoot(), MdlDialogOutletModule],
83-
declarations: [
84-
MdlTestComponent,
85-
ModalTrueConfigFalseComponent,
86-
ModalFalseConfigTrueComponent,
87-
ModalComponent,
88-
],
89-
});
90-
}));
91-
92-
it("should create, show and close the embedded dialog", waitForAsync(() => {
93-
const fixture = TestBed.createComponent(MdlTestComponent);
94-
fixture.detectChanges();
95-
const dialog = fixture.componentInstance.dialog;
96-
expect(dialog).toBeDefined("mdldialog should be created");
97-
98-
spyOn(fixture.componentInstance, "onDialogShow").and.callThrough();
99-
spyOn(fixture.componentInstance, "onDialogHide");
100-
101-
dialog?.show().subscribe(() => {
102-
dialog.close();
103-
104-
expect(fixture.componentInstance.onDialogShow).toHaveBeenCalled();
105-
expect(fixture.componentInstance.onDialogHide).toHaveBeenCalled();
106-
});
107-
}));
80+
beforeEach(
81+
waitForAsync(() => {
82+
TestBed.configureTestingModule({
83+
imports: [MdlDialogModule.forRoot(), MdlDialogOutletModule],
84+
declarations: [
85+
MdlTestComponent,
86+
ModalTrueConfigFalseComponent,
87+
ModalFalseConfigTrueComponent,
88+
ModalComponent,
89+
],
90+
});
91+
})
92+
);
93+
94+
it(
95+
"should create, show and close the embedded dialog",
96+
waitForAsync(() => {
97+
const fixture = TestBed.createComponent(MdlTestComponent);
98+
fixture.detectChanges();
99+
const dialog = fixture.componentInstance.dialog;
100+
expect(dialog).toBeDefined("mdldialog should be created");
101+
102+
spyOn(fixture.componentInstance, "onDialogShow").and.callThrough();
103+
spyOn(fixture.componentInstance, "onDialogHide");
104+
105+
dialog?.show().subscribe(() => {
106+
dialog.close();
107+
108+
expect(fixture.componentInstance.onDialogShow).toHaveBeenCalled();
109+
expect(fixture.componentInstance.onDialogHide).toHaveBeenCalled();
110+
});
111+
})
112+
);
108113

109114
it("should not be possible to create a second embedded dialog", () => {
110115
const fixture = TestBed.createComponent(MdlTestComponent);
@@ -118,7 +123,7 @@ describe("MdlDialog (embedded/declarative)", () => {
118123
}).toThrow();
119124
});
120125

121-
it("should open a modal dialog if no config for modal is set", () => {
126+
it("should open a modal dialog if no config for modal is set", (done) => {
122127
const fixture = TestBed.createComponent(ModalComponent);
123128
fixture.detectChanges();
124129

@@ -131,6 +136,7 @@ describe("MdlDialog (embedded/declarative)", () => {
131136
expect(backdrop.display).toBeDefined(
132137
"should open as modal - because there is no config provided"
133138
);
139+
done();
134140
});
135141
});
136142

0 commit comments

Comments
 (0)