Skip to content

Commit

Permalink
test(MdInput): Add tests for empty check
Browse files Browse the repository at this point in the history
  • Loading branch information
drager committed Jul 14, 2016
1 parent 06ec202 commit 09de981
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/components/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,62 @@ describe('MdInput', function () {
});
});

it('should not be treated as empty if type is date', () => {
return builder.createAsync(MdInputDateTestController)
.then(fixture => {
fakeAsync(() => {
fixture.componentInstance.placeholder = 'Placeholder';
fixture.detectChanges();

let el = fixture.debugElement.query(By.css('label')).nativeElement;
expect(el).not.toBeNull();
expect(el.className.includes('md-empty')).toBe(false);
})();
});
});

it('should treat text input type as empty at init', () => {
return builder.createAsync(MdInputTextTestController)
.then(fixture => {
fakeAsync(() => {
fixture.componentInstance.placeholder = 'Placeholder';
fixture.detectChanges();

let el = fixture.debugElement.query(By.css('label')).nativeElement;
expect(el).not.toBeNull();
expect(el.className.includes('md-empty')).toBe(true);
})();
});
});

it('should treat password input type as empty at init', () => {
return builder.createAsync(MdInputPasswordTestController)
.then(fixture => {
fakeAsync(() => {
fixture.componentInstance.placeholder = 'Placeholder';
fixture.detectChanges();

let el = fixture.debugElement.query(By.css('label')).nativeElement;
expect(el).not.toBeNull();
expect(el.className.includes('md-empty')).toBe(true);
})();
});
});

it('should treat number input type as empty at init', () => {
return builder.createAsync(MdInputNumberTestController)
.then(fixture => {
fakeAsync(() => {
fixture.componentInstance.placeholder = 'Placeholder';
fixture.detectChanges();

let el = fixture.debugElement.query(By.css('label')).nativeElement;
expect(el).not.toBeNull();
expect(el.className.includes('md-empty')).toBe(true);
})();
});
});

it('support ngModel', () => {
return builder.createAsync(MdInputBaseTestController)
.then(fixture => {
Expand Down Expand Up @@ -838,3 +894,39 @@ class MdInputOptionalAttributeController {}
directives: [MdInput]
})
class MdInputWithNameTestController {}

@Component({
selector: 'test-input-controller',
template: `
<md-input type="date" [placeholder]="placeholder"></md-input>
`,
directives: [MdInput]
})
class MdInputDateTestController {}

@Component({
selector: 'test-input-controller',
template: `
<md-input type="text" [placeholder]="placeholder"></md-input>
`,
directives: [MdInput]
})
class MdInputTextTestController {}

@Component({
selector: 'test-input-controller',
template: `
<md-input type="password" [placeholder]="placeholder"></md-input>
`,
directives: [MdInput]
})
class MdInputPasswordTestController {}

@Component({
selector: 'test-input-controller',
template: `
<md-input type="number" [placeholder]="placeholder"></md-input>
`,
directives: [MdInput]
})
class MdInputNumberTestController {}

0 comments on commit 09de981

Please sign in to comment.