Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Mar 28, 2017
1 parent a06b76c commit 83dbaf0
Showing 1 changed file with 66 additions and 32 deletions.
98 changes: 66 additions & 32 deletions src/lib/input/input-container.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,52 +18,53 @@ 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';


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,
],
});

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -927,7 +951,6 @@ class MdInputContainerWithFormErrorMessages {
renderError = true;
}


@Component({
template: `
<form [formGroup]="formGroup" novalidate>
Expand All @@ -945,3 +968,14 @@ class MdInputContainerWithFormGroupErrorMessages {
name: new FormControl('', Validators.required)
});
}

@Component({
template: `
<md-input-container>
<div mdPrefix>Prefix</div>
<input mdInput>
<div mdSuffix>Suffix</div>
</md-input-container>
`
})
class MdInputContainerWithPrefixAndSuffix {}

0 comments on commit 83dbaf0

Please sign in to comment.