This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(textfield): Add
setValid
method to set a custom validity (#190)
* feat(textfield): Add `setValid` method, so developers can set custom validity. * test(textfield): Add initial test coverage * test: Add test coverage for mdc-textfield-box * feat(textfield): Add return type to each property BREAKING CHANGE: `updateErrorState` method was renamed to `setValid` keeping with MDC foundation naming.
- Loading branch information
Showing
6 changed files
with
284 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Component, DebugElement } from '@angular/core'; | ||
import { async, ComponentFixture, fakeAsync, flushMicrotasks, TestBed } from '@angular/core/testing'; | ||
import { FormControl, FormsModule, NgModel, ReactiveFormsModule } from '@angular/forms'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { | ||
MdcTextareaComponent, | ||
MdcTextfieldModule | ||
} from '../../../src/lib/public_api'; | ||
|
||
describe('MdcTextareaComponent', () => { | ||
let fixture: ComponentFixture<any>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdcTextfieldModule, FormsModule, ReactiveFormsModule], | ||
declarations: [ | ||
SimpleTextfield, | ||
] | ||
}); | ||
TestBed.compileComponents(); | ||
})); | ||
|
||
describe('basic behaviors', () => { | ||
let textFieldDebugElement: DebugElement; | ||
let textFieldNativeElement: HTMLElement; | ||
let textFieldInstance: MdcTextareaComponent; | ||
let testComponent: SimpleTextfield; | ||
let inputElement: HTMLInputElement; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SimpleTextfield); | ||
fixture.detectChanges(); | ||
|
||
textFieldDebugElement = fixture.debugElement.query(By.directive(MdcTextareaComponent)); | ||
textFieldNativeElement = textFieldDebugElement.nativeElement; | ||
textFieldInstance = textFieldDebugElement.componentInstance; | ||
testComponent = fixture.debugElement.componentInstance; | ||
}); | ||
|
||
it('#should apply class multiline on property', () => { | ||
testComponent.isMultiline = true; | ||
fixture.detectChanges(); | ||
expect(textFieldDebugElement.nativeElement.classList.contains('mdc-textfield--multiline')).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
||
/** Simple component for testing. */ | ||
@Component({ | ||
template: | ||
` | ||
<mdc-textarea | ||
[(ngModel)]="comments" | ||
label="Comments" | ||
[required]="isRequired" | ||
[multiline]="isMultiline" | ||
[disabled]="isDisabled"> | ||
</mdc-textarea> | ||
<p mdc-textfield-helptext | ||
[validation]="true" | ||
[persistent]="false">Comments are required</p> | ||
`, | ||
}) | ||
class SimpleTextfield { | ||
username: string = ''; | ||
isDisabled: boolean = false; | ||
isRequired: boolean = false; | ||
isMultiline: boolean = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Component, DebugElement } from '@angular/core'; | ||
import { async, ComponentFixture, fakeAsync, flushMicrotasks, TestBed } from '@angular/core/testing'; | ||
import { FormControl, FormsModule, NgModel, ReactiveFormsModule } from '@angular/forms'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { | ||
MdcTextfieldBoxComponent, | ||
MdcTextfieldInputDirective, | ||
MdcTextfieldModule | ||
} from '../../../src/lib/public_api'; | ||
|
||
describe('MdcTextfieldBoxComponent', () => { | ||
let fixture: ComponentFixture<any>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdcTextfieldModule, FormsModule, ReactiveFormsModule], | ||
declarations: [ | ||
SimpleTextfield, | ||
] | ||
}); | ||
TestBed.compileComponents(); | ||
})); | ||
|
||
describe('basic behaviors', () => { | ||
let textFieldDebugElement: DebugElement; | ||
let textFieldNativeElement: HTMLElement; | ||
let textFieldInstance: MdcTextfieldBoxComponent; | ||
let testComponent: SimpleTextfield; | ||
let inputElement: HTMLInputElement; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SimpleTextfield); | ||
fixture.detectChanges(); | ||
|
||
textFieldDebugElement = fixture.debugElement.query(By.directive(MdcTextfieldBoxComponent)); | ||
textFieldNativeElement = textFieldDebugElement.nativeElement; | ||
textFieldInstance = textFieldDebugElement.componentInstance; | ||
testComponent = fixture.debugElement.componentInstance; | ||
inputElement = textFieldInstance.inputText.elementRef.nativeElement; | ||
}); | ||
|
||
it('#should have mdc-textfield--box by default', () => { | ||
expect(textFieldDebugElement.nativeElement.classList) | ||
.toContain('mdc-textfield--box', 'Expected to have mdc-textfield--box class'); | ||
}); | ||
|
||
it('#should preserve the user-provided id', () => { | ||
fixture.detectChanges(); | ||
expect(inputElement.id).toBe('simple-check'); | ||
}); | ||
}); | ||
}); | ||
|
||
/** Simple component for testing. */ | ||
@Component({ | ||
template: | ||
` | ||
<mdc-textfield-box | ||
[id]="boxId" | ||
[(ngModel)]="username" | ||
label="Username" | ||
[required]="isRequired" | ||
[disabled]="isDisabled"> | ||
</mdc-textfield-box> | ||
<p mdc-textfield-helptext | ||
[validation]="true" | ||
[persistent]="false">Username is required</p> | ||
`, | ||
}) | ||
class SimpleTextfield { | ||
boxId: string = 'simple-check'; | ||
username: string = ''; | ||
isDisabled: boolean = false; | ||
isRequired: boolean = false; | ||
} |
Oops, something went wrong.