|
1 | 1 | import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
2 |
| -import {Component} from '@angular/core'; |
| 2 | +import {Component, DebugElement} from '@angular/core'; |
3 | 3 | import {By} from '@angular/platform-browser';
|
4 | 4 | import {MdButtonModule} from './index';
|
5 | 5 | import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
|
6 | 6 | import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler';
|
| 7 | +import {MdRipple} from '../core/ripple/index'; |
7 | 8 |
|
8 | 9 |
|
9 | 10 | describe('MdButton', () => {
|
@@ -156,41 +157,54 @@ describe('MdButton', () => {
|
156 | 157 | describe('button ripples', () => {
|
157 | 158 | let fixture: ComponentFixture<TestApp>;
|
158 | 159 | let testComponent: TestApp;
|
159 |
| - let buttonElement: HTMLButtonElement; |
160 |
| - let anchorElement: HTMLAnchorElement; |
| 160 | + let buttonDebugElement: DebugElement; |
| 161 | + let buttonRippleDebugElement: DebugElement; |
| 162 | + let buttonRippleInstance: MdRipple; |
| 163 | + let anchorDebugElement: DebugElement; |
| 164 | + let anchorRippleDebugElement: DebugElement; |
| 165 | + let anchorRippleInstance: MdRipple; |
161 | 166 |
|
162 | 167 | beforeEach(() => {
|
163 | 168 | fixture = TestBed.createComponent(TestApp);
|
164 | 169 | fixture.detectChanges();
|
165 | 170 |
|
166 | 171 | testComponent = fixture.componentInstance;
|
167 |
| - buttonElement = fixture.nativeElement.querySelector('button[md-button]'); |
168 |
| - anchorElement = fixture.nativeElement.querySelector('a[md-button]'); |
| 172 | + |
| 173 | + buttonDebugElement = fixture.debugElement.query(By.css('button[md-button]')); |
| 174 | + buttonRippleDebugElement = buttonDebugElement.query(By.directive(MdRipple)); |
| 175 | + buttonRippleInstance = buttonRippleDebugElement.injector.get<MdRipple>(MdRipple); |
| 176 | + |
| 177 | + anchorDebugElement = fixture.debugElement.query(By.css('a[md-button]')); |
| 178 | + anchorRippleDebugElement = anchorDebugElement.query(By.directive(MdRipple)); |
| 179 | + anchorRippleInstance = anchorRippleDebugElement.injector.get<MdRipple>(MdRipple); |
169 | 180 | });
|
170 | 181 |
|
171 |
| - it('should remove ripple if mdRippleDisabled input is set', () => { |
172 |
| - expect(buttonElement.querySelectorAll('[md-ripple]').length).toBe(1); |
| 182 | + it('should disable the ripple if mdRippleDisabled input is set', () => { |
| 183 | + expect(buttonRippleInstance.disabled).toBeFalsy(); |
173 | 184 |
|
174 | 185 | testComponent.rippleDisabled = true;
|
175 | 186 | fixture.detectChanges();
|
176 |
| - expect(buttonElement.querySelectorAll('[md-ripple]').length).toBe(0); |
177 |
| - }); |
178 | 187 |
|
179 |
| - it('should not have a ripple when the button is disabled', () => { |
180 |
| - let buttonRipple = buttonElement.querySelector('[md-ripple]'); |
181 |
| - let anchorRipple = anchorElement.querySelector('[md-ripple]'); |
| 188 | + expect(buttonRippleInstance.disabled).toBeTruthy(); |
| 189 | + }); |
182 | 190 |
|
183 |
| - expect(buttonRipple).toBeTruthy('Expected an enabled button[md-button] to have a ripple'); |
184 |
| - expect(anchorRipple).toBeTruthy('Expected an enabled a[md-button] to have a ripple'); |
| 191 | + it('should disable the ripple when the button is disabled', () => { |
| 192 | + expect(buttonRippleInstance.disabled).toBeFalsy( |
| 193 | + 'Expected an enabled button[md-button] to have an enabled ripple' |
| 194 | + ); |
| 195 | + expect(anchorRippleInstance.disabled).toBeFalsy( |
| 196 | + 'Expected an enabled a[md-button] to have an enabled ripple' |
| 197 | + ); |
185 | 198 |
|
186 | 199 | testComponent.isDisabled = true;
|
187 | 200 | fixture.detectChanges();
|
188 | 201 |
|
189 |
| - buttonRipple = buttonElement.querySelector('button [md-ripple]'); |
190 |
| - anchorRipple = anchorElement.querySelector('a [md-ripple]'); |
191 |
| - |
192 |
| - expect(buttonRipple).toBeFalsy('Expected a disabled button[md-button] not to have a ripple'); |
193 |
| - expect(anchorRipple).toBeFalsy('Expected a disabled a[md-button] not to have a ripple'); |
| 202 | + expect(buttonRippleInstance.disabled).toBeTruthy( |
| 203 | + 'Expected a disabled button[md-button] not to have an enabled ripple' |
| 204 | + ); |
| 205 | + expect(anchorRippleInstance.disabled).toBeTruthy( |
| 206 | + 'Expected a disabled a[md-button] not to have an enabled ripple' |
| 207 | + ); |
194 | 208 | });
|
195 | 209 | });
|
196 | 210 | });
|
|
0 commit comments