Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(option): support for disableRipple binding (#5915)
- Loading branch information
1 parent
281de25
commit addf1ce
Showing
3 changed files
with
96 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component, DebugElement} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {dispatchFakeEvent} from '@angular/cdk/testing'; | ||
import {MdOption, MdOptionModule} from './index'; | ||
|
||
describe('MdOption component', () => { | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdOptionModule], | ||
declarations: [OptionWithDisableRipple] | ||
}).compileComponents(); | ||
})); | ||
|
||
describe('ripples', () => { | ||
let fixture: ComponentFixture<OptionWithDisableRipple>; | ||
let optionDebugElement: DebugElement; | ||
let optionNativeElement: HTMLElement; | ||
let optionInstance: MdOption; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(OptionWithDisableRipple); | ||
fixture.detectChanges(); | ||
|
||
optionDebugElement = fixture.debugElement.query(By.directive(MdOption)); | ||
optionNativeElement = optionDebugElement.nativeElement; | ||
optionInstance = optionDebugElement.componentInstance; | ||
}); | ||
|
||
it('should show ripples by default', () => { | ||
expect(optionInstance.disableRipple).toBe(false, 'Expected ripples to be enabled by default'); | ||
expect(optionNativeElement.querySelectorAll('.mat-ripple-element').length) | ||
.toBe(0, 'Expected no ripples to show up initially'); | ||
|
||
dispatchFakeEvent(optionNativeElement, 'mousedown'); | ||
dispatchFakeEvent(optionNativeElement, 'mouseup'); | ||
|
||
expect(optionNativeElement.querySelectorAll('.mat-ripple-element').length) | ||
.toBe(1, 'Expected one ripple to show up after a fake click.'); | ||
}); | ||
|
||
it('should not show ripples if the option is disabled', () => { | ||
expect(optionNativeElement.querySelectorAll('.mat-ripple-element').length) | ||
.toBe(0, 'Expected no ripples to show up initially'); | ||
|
||
fixture.componentInstance.disabled = true; | ||
fixture.detectChanges(); | ||
|
||
dispatchFakeEvent(optionNativeElement, 'mousedown'); | ||
dispatchFakeEvent(optionNativeElement, 'mouseup'); | ||
|
||
expect(optionNativeElement.querySelectorAll('.mat-ripple-element').length) | ||
.toBe(0, 'Expected no ripples to show up after click on a disabled option.'); | ||
}); | ||
|
||
it('should not show ripples if the ripples are disabled using disableRipple', () => { | ||
expect(optionNativeElement.querySelectorAll('.mat-ripple-element').length) | ||
.toBe(0, 'Expected no ripples to show up initially'); | ||
|
||
fixture.componentInstance.disableRipple = true; | ||
fixture.detectChanges(); | ||
|
||
dispatchFakeEvent(optionNativeElement, 'mousedown'); | ||
dispatchFakeEvent(optionNativeElement, 'mouseup'); | ||
|
||
expect(optionNativeElement.querySelectorAll('.mat-ripple-element').length) | ||
.toBe(0, 'Expected no ripples to show up after click when ripples are disabled.'); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
@Component({ | ||
template: `<md-option [disableRipple]="disableRipple" [disabled]="disabled"></md-option>` | ||
}) | ||
export class OptionWithDisableRipple { | ||
disableRipple: boolean; | ||
disabled: boolean; | ||
} |
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