diff --git a/src/lib/input/input-container.spec.ts b/src/lib/input/input-container.spec.ts index cfff09e68786..1953bd522e17 100644 --- a/src/lib/input/input-container.spec.ts +++ b/src/lib/input/input-container.spec.ts @@ -1,13 +1,13 @@ -import {async, TestBed, inject, ComponentFixture} from '@angular/core/testing'; +import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing'; import {Component, ViewChild} from '@angular/core'; import { - FormsModule, - ReactiveFormsModule, FormControl, - NgForm, - Validators, - FormGroupDirective, FormGroup, + FormGroupDirective, + FormsModule, + NgForm, + ReactiveFormsModule, + Validators } from '@angular/forms'; import {By} from '@angular/platform-browser'; import {NoopAnimationsModule} from '@angular/platform-browser/animations'; @@ -18,9 +18,9 @@ import {PlatformModule} from '../core/platform/index'; import {wrappedErrorMessage} from '../core/testing/wrapped-error-message'; import {dispatchFakeEvent} from '../core/testing/dispatch-events'; import { + MdInputContainerDuplicatedHintError, MdInputContainerMissingMdInputError, - MdInputContainerPlaceholderConflictError, - MdInputContainerDuplicatedHintError + MdInputContainerPlaceholderConflictError } from './input-container-errors'; @@ -28,42 +28,43 @@ describe('MdInputContainer', function () { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ - MdInputModule.forRoot(), - PlatformModule.forRoot(), FormsModule, + MdInputModule, + NoopAnimationsModule, + PlatformModule, ReactiveFormsModule, - NoopAnimationsModule ], declarations: [ - MdInputContainerPlaceholderRequiredTestComponent, - MdInputContainerPlaceholderElementTestComponent, - MdInputContainerPlaceholderAttrTestComponent, + MdInputContainerBaseTestController, + MdInputContainerDateTestController, MdInputContainerHintLabel2TestController, MdInputContainerHintLabelTestController, - MdInputContainerInvalidTypeTestController, - MdInputContainerInvalidPlaceholderTestController, MdInputContainerInvalidHint2TestController, MdInputContainerInvalidHintTestController, - MdInputContainerBaseTestController, - MdInputContainerWithId, - MdInputContainerDateTestController, - MdInputContainerTextTestController, - MdInputContainerPasswordTestController, + MdInputContainerInvalidPlaceholderTestController, + MdInputContainerInvalidTypeTestController, + MdInputContainerMissingMdInputTestController, + MdInputContainerMultipleHintMixedTestController, + MdInputContainerMultipleHintTestController, MdInputContainerNumberTestController, - MdInputContainerZeroTestController, - MdTextareaWithBindings, + MdInputContainerPasswordTestController, + MdInputContainerPlaceholderAttrTestComponent, + MdInputContainerPlaceholderElementTestComponent, + MdInputContainerPlaceholderRequiredTestComponent, + MdInputContainerTextTestController, MdInputContainerWithDisabled, + MdInputContainerWithDynamicPlaceholder, + MdInputContainerWithFormControl, + MdInputContainerWithFormErrorMessages, + MdInputContainerWithFormGroupErrorMessages, + MdInputContainerWithId, + MdInputContainerWithPrefixAndSuffix, MdInputContainerWithRequired, + MdInputContainerWithStaticPlaceholder, MdInputContainerWithType, MdInputContainerWithValueBinding, - MdInputContainerWithFormControl, - MdInputContainerWithStaticPlaceholder, - MdInputContainerMissingMdInputTestController, - MdInputContainerMultipleHintTestController, - MdInputContainerMultipleHintMixedTestController, - MdInputContainerWithDynamicPlaceholder, - MdInputContainerWithFormErrorMessages, - MdInputContainerWithFormGroupErrorMessages + MdInputContainerZeroTestController, + MdTextareaWithBindings, ], }); @@ -685,6 +686,29 @@ describe('MdInputContainer', function () { }); + it('should not have prefix and suffix elements when none are specified', () => { + let fixture = TestBed.createComponent(MdInputContainerWithId); + fixture.detectChanges(); + + let prefixEl = fixture.debugElement.query(By.css('.mat-input-prefix')); + let suffixEl = fixture.debugElement.query(By.css('.mat-input-suffix')); + + expect(prefixEl).toBeNull(); + expect(suffixEl).toBeNull(); + }); + + it('should add prefix and suffix elements when specified', () => { + let fixture = TestBed.createComponent(MdInputContainerWithPrefixAndSuffix); + fixture.detectChanges(); + + let prefixEl = fixture.debugElement.query(By.css('.mat-input-prefix')); + let suffixEl = fixture.debugElement.query(By.css('.mat-input-suffix')); + + expect(prefixEl).not.toBeNull(); + expect(suffixEl).not.toBeNull(); + expect(prefixEl.nativeElement.innerText.trim()).toEqual('Prefix'); + expect(suffixEl.nativeElement.innerText.trim()).toEqual('Suffix'); + }); }); @Component({ @@ -927,7 +951,6 @@ class MdInputContainerWithFormErrorMessages { renderError = true; } - @Component({ template: `
@@ -945,3 +968,14 @@ class MdInputContainerWithFormGroupErrorMessages { name: new FormControl('', Validators.required) }); } + +@Component({ + template: ` + +
Prefix
+ +
Suffix
+
+ ` +}) +class MdInputContainerWithPrefixAndSuffix {}