|
1 | 1 | import {Platform} from '@angular/cdk/platform'; |
2 | 2 | import { |
| 3 | + createTouchEvent, |
3 | 4 | createMouseEvent, |
4 | 5 | dispatchEvent, |
5 | 6 | dispatchMouseEvent, |
@@ -130,6 +131,43 @@ describe('MatRipple', () => { |
130 | 131 | expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
131 | 132 | })); |
132 | 133 |
|
| 134 | + it('should clear ripples if the touch sequence is cancelled', fakeAsync(() => { |
| 135 | + dispatchTouchEvent(rippleTarget, 'touchstart'); |
| 136 | + tick(enterDuration); |
| 137 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1); |
| 138 | + |
| 139 | + dispatchTouchEvent(rippleTarget, 'touchcancel'); |
| 140 | + tick(exitDuration); |
| 141 | + |
| 142 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
| 143 | + })); |
| 144 | + |
| 145 | + it('should launch multiple ripples for multi-touch', fakeAsync(() => { |
| 146 | + const touchEvent = createTouchEvent('touchstart'); |
| 147 | + |
| 148 | + Object.defineProperties(touchEvent, { |
| 149 | + changedTouches: { |
| 150 | + value: [ |
| 151 | + {pageX: 0, pageY: 0}, |
| 152 | + {pageX: 10, pageY: 10}, |
| 153 | + {pageX: 20, pageY: 20} |
| 154 | + ] |
| 155 | + } |
| 156 | + }); |
| 157 | + |
| 158 | + dispatchEvent(rippleTarget, touchEvent); |
| 159 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(3); |
| 160 | + |
| 161 | + tick(enterDuration); |
| 162 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(3); |
| 163 | + |
| 164 | + dispatchTouchEvent(rippleTarget, 'touchend'); |
| 165 | + |
| 166 | + tick(exitDuration); |
| 167 | + |
| 168 | + expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0); |
| 169 | + })); |
| 170 | + |
133 | 171 | it('should ignore synthetic mouse events after touchstart', () => fakeAsync(() => { |
134 | 172 | dispatchTouchEvent(rippleTarget, 'touchstart'); |
135 | 173 | dispatchTouchEvent(rippleTarget, 'mousedown'); |
|
0 commit comments