Skip to content

Commit 09de981

Browse files
committed
test(MdInput): Add tests for empty check
1 parent 06ec202 commit 09de981

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

src/components/input/input.spec.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,62 @@ describe('MdInput', function () {
3838
});
3939
});
4040

41+
it('should not be treated as empty if type is date', () => {
42+
return builder.createAsync(MdInputDateTestController)
43+
.then(fixture => {
44+
fakeAsync(() => {
45+
fixture.componentInstance.placeholder = 'Placeholder';
46+
fixture.detectChanges();
47+
48+
let el = fixture.debugElement.query(By.css('label')).nativeElement;
49+
expect(el).not.toBeNull();
50+
expect(el.className.includes('md-empty')).toBe(false);
51+
})();
52+
});
53+
});
54+
55+
it('should treat text input type as empty at init', () => {
56+
return builder.createAsync(MdInputTextTestController)
57+
.then(fixture => {
58+
fakeAsync(() => {
59+
fixture.componentInstance.placeholder = 'Placeholder';
60+
fixture.detectChanges();
61+
62+
let el = fixture.debugElement.query(By.css('label')).nativeElement;
63+
expect(el).not.toBeNull();
64+
expect(el.className.includes('md-empty')).toBe(true);
65+
})();
66+
});
67+
});
68+
69+
it('should treat password input type as empty at init', () => {
70+
return builder.createAsync(MdInputPasswordTestController)
71+
.then(fixture => {
72+
fakeAsync(() => {
73+
fixture.componentInstance.placeholder = 'Placeholder';
74+
fixture.detectChanges();
75+
76+
let el = fixture.debugElement.query(By.css('label')).nativeElement;
77+
expect(el).not.toBeNull();
78+
expect(el.className.includes('md-empty')).toBe(true);
79+
})();
80+
});
81+
});
82+
83+
it('should treat number input type as empty at init', () => {
84+
return builder.createAsync(MdInputNumberTestController)
85+
.then(fixture => {
86+
fakeAsync(() => {
87+
fixture.componentInstance.placeholder = 'Placeholder';
88+
fixture.detectChanges();
89+
90+
let el = fixture.debugElement.query(By.css('label')).nativeElement;
91+
expect(el).not.toBeNull();
92+
expect(el.className.includes('md-empty')).toBe(true);
93+
})();
94+
});
95+
});
96+
4197
it('support ngModel', () => {
4298
return builder.createAsync(MdInputBaseTestController)
4399
.then(fixture => {
@@ -838,3 +894,39 @@ class MdInputOptionalAttributeController {}
838894
directives: [MdInput]
839895
})
840896
class MdInputWithNameTestController {}
897+
898+
@Component({
899+
selector: 'test-input-controller',
900+
template: `
901+
<md-input type="date" [placeholder]="placeholder"></md-input>
902+
`,
903+
directives: [MdInput]
904+
})
905+
class MdInputDateTestController {}
906+
907+
@Component({
908+
selector: 'test-input-controller',
909+
template: `
910+
<md-input type="text" [placeholder]="placeholder"></md-input>
911+
`,
912+
directives: [MdInput]
913+
})
914+
class MdInputTextTestController {}
915+
916+
@Component({
917+
selector: 'test-input-controller',
918+
template: `
919+
<md-input type="password" [placeholder]="placeholder"></md-input>
920+
`,
921+
directives: [MdInput]
922+
})
923+
class MdInputPasswordTestController {}
924+
925+
@Component({
926+
selector: 'test-input-controller',
927+
template: `
928+
<md-input type="number" [placeholder]="placeholder"></md-input>
929+
`,
930+
directives: [MdInput]
931+
})
932+
class MdInputNumberTestController {}

0 commit comments

Comments
 (0)