8
8
9
9
import { dispatchMouseEvent , dispatchPointerEvent } from '@angular/cdk/testing/private' ;
10
10
import { Component , DebugElement , Type } from '@angular/core' ;
11
- import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
12
- import { RippleRef , RippleState } from '@angular/material/core' ;
11
+ import { ComponentFixture , fakeAsync , TestBed , tick , waitForAsync } from '@angular/core/testing' ;
13
12
import { By } from '@angular/platform-browser' ;
14
13
import { Thumb } from '@material/slider' ;
15
14
import { MatSliderModule } from './module' ;
@@ -165,9 +164,9 @@ describe('MDC-based MatSlider' , () => {
165
164
thumbY = thumbDimensions . top - ( thumbDimensions . height / 2 ) ;
166
165
} ) ) ;
167
166
168
- function isRippleVisible ( rippleRef : RippleRef ) {
169
- return rippleRef ?. state === RippleState . FADING_IN
170
- || rippleRef ?. state === RippleState . VISIBLE ;
167
+ function isRippleVisible ( selector : string ) {
168
+ tick ( 500 ) ;
169
+ return ! ! document . querySelector ( `.mat-mdc-slider- ${ selector } -ripple` ) ;
171
170
}
172
171
173
172
function blur ( ) {
@@ -190,83 +189,83 @@ describe('MDC-based MatSlider' , () => {
190
189
dispatchPointerEvent ( thumbElement , 'pointerup' , thumbX , thumbY ) ;
191
190
}
192
191
193
- it ( 'should show the hover ripple on mouseenter' , ( ) => {
194
- expect ( isRippleVisible ( thumbInstance . _hoverRippleRef ) ) . toBe ( false ) ;
192
+ it ( 'should show the hover ripple on mouseenter' , fakeAsync ( ( ) => {
193
+ expect ( isRippleVisible ( 'hover' ) ) . toBe ( false ) ;
195
194
mouseenter ( ) ;
196
- expect ( isRippleVisible ( thumbInstance . _hoverRippleRef ) ) . toBe ( true ) ;
197
- } ) ;
195
+ expect ( isRippleVisible ( 'hover' ) ) . toBe ( true ) ;
196
+ } ) ) ;
198
197
199
- it ( 'should hide the hover ripple on mouseleave' , ( ) => {
198
+ it ( 'should hide the hover ripple on mouseleave' , fakeAsync ( ( ) => {
200
199
mouseenter ( ) ;
201
200
mouseleave ( ) ;
202
- expect ( isRippleVisible ( thumbInstance . _hoverRippleRef ) ) . toBe ( false ) ;
203
- } ) ;
201
+ expect ( isRippleVisible ( 'hover' ) ) . toBe ( false ) ;
202
+ } ) ) ;
204
203
205
- it ( 'should show the focus ripple on pointerdown' , ( ) => {
206
- expect ( isRippleVisible ( thumbInstance . _focusRippleRef ) ) . toBe ( false ) ;
204
+ it ( 'should show the focus ripple on pointerdown' , fakeAsync ( ( ) => {
205
+ expect ( isRippleVisible ( 'focus' ) ) . toBe ( false ) ;
207
206
pointerdown ( ) ;
208
- expect ( isRippleVisible ( thumbInstance . _focusRippleRef ) ) . toBe ( true ) ;
209
- } ) ;
207
+ expect ( isRippleVisible ( 'focus' ) ) . toBe ( true ) ;
208
+ } ) ) ;
210
209
211
- it ( 'should continue to show the focus ripple on pointerup' , ( ) => {
210
+ it ( 'should continue to show the focus ripple on pointerup' , fakeAsync ( ( ) => {
212
211
pointerdown ( ) ;
213
212
pointerup ( ) ;
214
- expect ( isRippleVisible ( thumbInstance . _focusRippleRef ) ) . toBe ( true ) ;
215
- } ) ;
213
+ expect ( isRippleVisible ( 'focus' ) ) . toBe ( true ) ;
214
+ } ) ) ;
216
215
217
- it ( 'should hide the focus ripple on blur' , ( ) => {
216
+ it ( 'should hide the focus ripple on blur' , fakeAsync ( ( ) => {
218
217
pointerdown ( ) ;
219
218
pointerup ( ) ;
220
219
blur ( ) ;
221
- expect ( isRippleVisible ( thumbInstance . _focusRippleRef ) ) . toBe ( false ) ;
222
- } ) ;
220
+ expect ( isRippleVisible ( 'focus' ) ) . toBe ( false ) ;
221
+ } ) ) ;
223
222
224
- it ( 'should show the active ripple on pointerdown' , ( ) => {
225
- expect ( isRippleVisible ( thumbInstance . _activeRippleRef ) ) . toBe ( false ) ;
223
+ it ( 'should show the active ripple on pointerdown' , fakeAsync ( ( ) => {
224
+ expect ( isRippleVisible ( 'active' ) ) . toBe ( false ) ;
226
225
pointerdown ( ) ;
227
- expect ( isRippleVisible ( thumbInstance . _activeRippleRef ) ) . toBe ( true ) ;
228
- } ) ;
226
+ expect ( isRippleVisible ( 'active' ) ) . toBe ( true ) ;
227
+ } ) ) ;
229
228
230
- it ( 'should hide the active ripple on pointerup' , ( ) => {
229
+ it ( 'should hide the active ripple on pointerup' , fakeAsync ( ( ) => {
231
230
pointerdown ( ) ;
232
231
pointerup ( ) ;
233
- expect ( isRippleVisible ( thumbInstance . _activeRippleRef ) ) . toBe ( false ) ;
234
- } ) ;
232
+ expect ( isRippleVisible ( 'active' ) ) . toBe ( false ) ;
233
+ } ) ) ;
235
234
236
235
// Edge cases.
237
236
238
- it ( 'should not show the hover ripple if the thumb is already focused' , ( ) => {
237
+ it ( 'should not show the hover ripple if the thumb is already focused' , fakeAsync ( ( ) => {
239
238
pointerdown ( ) ;
240
239
mouseenter ( ) ;
241
- expect ( isRippleVisible ( thumbInstance . _hoverRippleRef ) ) . toBe ( false ) ;
242
- } ) ;
240
+ expect ( isRippleVisible ( 'hover' ) ) . toBe ( false ) ;
241
+ } ) ) ;
243
242
244
- it ( 'should hide the hover ripple if the thumb is focused' , ( ) => {
243
+ it ( 'should hide the hover ripple if the thumb is focused' , fakeAsync ( ( ) => {
245
244
mouseenter ( ) ;
246
245
pointerdown ( ) ;
247
- expect ( isRippleVisible ( thumbInstance . _hoverRippleRef ) ) . toBe ( false ) ;
248
- } ) ;
246
+ expect ( isRippleVisible ( 'hover' ) ) . toBe ( false ) ;
247
+ } ) ) ;
249
248
250
- it ( 'should not hide the focus ripple if the thumb is pressed' , ( ) => {
249
+ it ( 'should not hide the focus ripple if the thumb is pressed' , fakeAsync ( ( ) => {
251
250
pointerdown ( ) ;
252
251
blur ( ) ;
253
- expect ( isRippleVisible ( thumbInstance . _focusRippleRef ) ) . toBe ( true ) ;
254
- } ) ;
252
+ expect ( isRippleVisible ( 'focus' ) ) . toBe ( true ) ;
253
+ } ) ) ;
255
254
256
- it ( 'should not hide the hover ripple on blur if the cursor is thumb being hovered' , ( ) => {
255
+ it ( 'should not hide the hover ripple on blur if the thumb is hovered' , fakeAsync ( ( ) => {
257
256
mouseenter ( ) ;
258
257
pointerdown ( ) ;
259
258
pointerup ( ) ;
260
259
blur ( ) ;
261
- expect ( isRippleVisible ( thumbInstance . _hoverRippleRef ) ) . toBe ( true ) ;
262
- } ) ;
260
+ expect ( isRippleVisible ( 'hover' ) ) . toBe ( true ) ;
261
+ } ) ) ;
263
262
264
- it ( 'should hide the focus ripple on drag end if the thumb already lost focus' , ( ) => {
263
+ it ( 'should hide the focus ripple on drag end if the thumb already lost focus' , fakeAsync ( ( ) => {
265
264
pointerdown ( ) ;
266
265
blur ( ) ;
267
266
pointerup ( ) ;
268
- expect ( isRippleVisible ( thumbInstance . _focusRippleRef ) ) . toBe ( false ) ;
269
- } ) ;
267
+ expect ( isRippleVisible ( 'focus' ) ) . toBe ( false ) ;
268
+ } ) ) ;
270
269
} ) ;
271
270
} ) ;
272
271
0 commit comments