Skip to content

Commit 2dc5227

Browse files
committed
fix tests
1 parent f585987 commit 2dc5227

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

src/lib/input/input-wrapper.spec.ts

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ describe('MdInputWrapper', function () {
4646

4747
it('should not be treated as empty if type is date', () => {
4848
let fixture = TestBed.createComponent(MdInputWrapperDateTestController);
49-
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
50-
inputEl.placeholder = 'Placeholder';
5149
fixture.detectChanges();
5250

5351
let el = fixture.debugElement.query(By.css('label')).nativeElement;
@@ -66,8 +64,6 @@ describe('MdInputWrapper', function () {
6664

6765
it('should treat password input type as empty at init', () => {
6866
let fixture = TestBed.createComponent(MdInputWrapperPasswordTestController);
69-
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
70-
inputEl.placeholder = 'Placeholder';
7167
fixture.detectChanges();
7268

7369
let el = fixture.debugElement.query(By.css('label')).nativeElement;
@@ -77,8 +73,6 @@ describe('MdInputWrapper', function () {
7773

7874
it('should treat number input type as empty at init', () => {
7975
let fixture = TestBed.createComponent(MdInputWrapperNumberTestController);
80-
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
81-
inputEl.placeholder = 'Placeholder';
8276
fixture.detectChanges();
8377

8478
let el = fixture.debugElement.query(By.css('label')).nativeElement;
@@ -90,7 +84,6 @@ describe('MdInputWrapper', function () {
9084
let fixture = TestBed.createComponent(MdInputWrapperTextTestController);
9185
fixture.detectChanges();
9286

93-
let inputWrapper = fixture.debugElement.query(By.directive(MdInputWrapper)).componentInstance;
9487
let inputEl = fixture.debugElement.query(By.css('input'));
9588
let el = fixture.debugElement.query(By.css('label')).nativeElement;
9689
expect(el).not.toBeNull();
@@ -99,7 +92,6 @@ describe('MdInputWrapper', function () {
9992
inputEl.nativeElement.value = 'hello';
10093
// Simulate input event.
10194
inputEl.triggerEventHandler('input', {target: inputEl.nativeElement});
102-
inputWrapper._inputListeners['input']();
10395
fixture.detectChanges();
10496

10597
el = fixture.debugElement.query(By.css('label')).nativeElement;
@@ -263,24 +255,26 @@ describe('MdInputWrapper', function () {
263255
});
264256

265257
@Component({
266-
template: `<md-input-wrapper><input id="test-id" placeholder="test"></md-input-wrapper>`
258+
template: `<md-input-wrapper><input md-input id="test-id" placeholder="test"></md-input-wrapper>`
267259
})
268260
class MdInputWrapperWithId {}
269261

270-
@Component({template: `<md-input [disabled]="disabled"></md-input>`})
262+
@Component({
263+
template: `<md-input-wrapper><input md-input [disabled]="disabled"></md-input-wrapper>`
264+
})
271265
class MdInputWrapperWithDisabled {
272266
disabled: boolean;
273267
}
274268

275269
@Component({
276-
template: `<md-input-wrapper><input required placeholder="hello"></md-input-wrapper>`
270+
template: `<md-input-wrapper><input md-input required placeholder="hello"></md-input-wrapper>`
277271
})
278272
class MdInputWrapperPlaceholderRequiredTestComponent {}
279273

280274
@Component({
281275
template: `
282276
<md-input-wrapper>
283-
<input>
277+
<input md-input>
284278
<md-placeholder>{{placeholder}}</md-placeholder>
285279
</md-input-wrapper>`
286280
})
@@ -289,35 +283,35 @@ class MdInputWrapperPlaceholderElementTestComponent {
289283
}
290284

291285
@Component({
292-
template: `<md-input-wrapper><input [placeholder]="placeholder"></md-input-wrapper>`
286+
template: `<md-input-wrapper><input md-input [placeholder]="placeholder"></md-input-wrapper>`
293287
})
294288
class MdInputWrapperPlaceholderAttrTestComponent {
295289
placeholder: string = '';
296290
}
297291

298292
@Component({
299-
template: `<md-input-wrapper><input><md-hint>{{label}}</md-hint></md-input-wrapper>`
293+
template: `<md-input-wrapper><input md-input><md-hint>{{label}}</md-hint></md-input-wrapper>`
300294
})
301295
class MdInputWrapperHintLabel2TestController {
302296
label: string = '';
303297
}
304298

305299
@Component({
306-
template: `<md-input-wrapper [hintLabel]="label"><input></md-input-wrapper>`
300+
template: `<md-input-wrapper [hintLabel]="label"><input md-input></md-input-wrapper>`
307301
})
308302
class MdInputWrapperHintLabelTestController {
309303
label: string = '';
310304
}
311305

312306
@Component({
313-
template: `<md-input-wrapper><input type="file"></md-input-wrapper>`
307+
template: `<md-input-wrapper><input md-input type="file"></md-input-wrapper>`
314308
})
315309
class MdInputWrapperInvalidTypeTestController {}
316310

317311
@Component({
318312
template: `
319313
<md-input-wrapper>
320-
<input placeholder="Hello">
314+
<input md-input placeholder="Hello">
321315
<md-placeholder>World</md-placeholder>
322316
</md-input-wrapper>`
323317
})
@@ -326,7 +320,7 @@ class MdInputWrapperInvalidPlaceholderTestController {}
326320
@Component({
327321
template: `
328322
<md-input-wrapper hintLabel="Hello">
329-
<input>
323+
<input md-input>
330324
<md-hint>World</md-hint>
331325
</md-input-wrapper>`
332326
})
@@ -335,53 +329,56 @@ class MdInputWrapperInvalidHint2TestController {}
335329
@Component({
336330
template: `
337331
<md-input-wrapper>
338-
<input>
332+
<input md-input>
339333
<md-hint>Hello</md-hint>
340334
<md-hint>World</md-hint>
341335
</md-input-wrapper>`
342336
})
343337
class MdInputWrapperInvalidHintTestController {}
344338

345339
@Component({
346-
template: `<md-input-wrapper><input [(ngModel)]="model"></md-input-wrapper>`
340+
template: `<md-input-wrapper><input md-input [(ngModel)]="model"></md-input-wrapper>`
347341
})
348342
class MdInputWrapperBaseTestController {
349343
model: any = '';
350344
}
351345

352346
@Component({
353-
template: `<md-input-wrapper><input type="date" [placeholder]="placeholder"></md-input-wrapper>`
347+
template: `
348+
<md-input-wrapper>
349+
<input md-input type="date" placeholder="Placeholder">
350+
</md-input-wrapper>`
354351
})
355-
class MdInputWrapperDateTestController {
356-
placeholder: string = '';
357-
}
352+
class MdInputWrapperDateTestController {}
358353

359354
@Component({
360-
template: `<md-input-wrapper><input type="text" placeholder="Placeholder"></md-input-wrapper>`
355+
template: `
356+
<md-input-wrapper>
357+
<input md-input type="text" placeholder="Placeholder">
358+
</md-input-wrapper>`
361359
})
362360
class MdInputWrapperTextTestController {}
363361

364362
@Component({
365363
template: `
366364
<md-input-wrapper>
367-
<input type="password" [placeholder]="placeholder">
365+
<input md-input type="password" placeholder="Placeholder">
368366
</md-input-wrapper>`
369367
})
370-
class MdInputWrapperPasswordTestController {
371-
placeholder: string = '';
372-
}
368+
class MdInputWrapperPasswordTestController {}
373369

374370
@Component({
375-
template: `<md-input-wrapper><input type="number" [placeholder]="placeholder"></md-input-wrapper>`
371+
template: `
372+
<md-input-wrapper>
373+
<input md-input type="number" placeholder="Placeholder">
374+
</md-input-wrapper>`
376375
})
377-
class MdInputWrapperNumberTestController {
378-
placeholder: string = '';
379-
}
376+
class MdInputWrapperNumberTestController {}
380377

381378
@Component({
382379
template: `
383380
<md-input-wrapper>
384-
<textarea [rows]="rows" [cols]="cols" [wrap]="wrap" placeholder="Snacks"></textarea>
381+
<textarea md-input [rows]="rows" [cols]="cols" [wrap]="wrap" placeholder="Snacks"></textarea>
385382
</md-input-wrapper>`
386383
})
387384
class MdTextareaWithBindings {

src/lib/input/input-wrapper.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const MD_INPUT_INVALID_TYPES = [
3434
const MD_INPUT_NEVER_EMPTY_TYPES = (() => {
3535
let featureTestInput = document.createElement('input');
3636
return [
37+
'date',
3738
'datetime',
3839
'datetime-local',
3940
'month',
@@ -106,7 +107,10 @@ export class MdHint {
106107
}
107108
})
108109
export class MdInputDirective implements AfterContentInit {
109-
@Input() disabled = false;
110+
@Input()
111+
get disabled() { return this._disabled; }
112+
set disabled(value: any) { this._disabled = coerceBooleanProperty(value); }
113+
private _disabled = false;
110114

111115
@Input()
112116
get id() { return this._id; };
@@ -123,7 +127,10 @@ export class MdInputDirective implements AfterContentInit {
123127
}
124128
private _placeholder = '';
125129

126-
@Input() required = false;
130+
@Input()
131+
get required() { return this._required; }
132+
set required(value: any) { this._required = coerceBooleanProperty(value); }
133+
private _required = false;
127134

128135
@Input()
129136
get type() { return this._type; }

0 commit comments

Comments
 (0)