|
| 1 | +import {dispatchMouseEvent} from '@angular/cdk/testing/private'; |
| 2 | +import {Component, ViewChild} from '@angular/core'; |
| 3 | +import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 4 | +import {MatRippleModule} from '.'; |
| 5 | +import {MatRipple} from './ripple'; |
| 6 | + |
| 7 | +describe('MatRipple Zone.js integration', () => { |
| 8 | + let fixture: ComponentFixture<any>; |
| 9 | + let rippleTarget: HTMLElement; |
| 10 | + let originalBodyMargin: string | null; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + TestBed.configureTestingModule({ |
| 14 | + imports: [MatRippleModule, BasicRippleContainer], |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + beforeEach(() => { |
| 19 | + // Set body margin to 0 during tests so it doesn't mess up position calculations. |
| 20 | + originalBodyMargin = document.body.style.margin; |
| 21 | + document.body.style.margin = '0'; |
| 22 | + }); |
| 23 | + |
| 24 | + afterEach(() => { |
| 25 | + document.body.style.margin = originalBodyMargin!; |
| 26 | + }); |
| 27 | + |
| 28 | + describe('basic ripple', () => { |
| 29 | + beforeEach(() => { |
| 30 | + fixture = TestBed.createComponent(BasicRippleContainer); |
| 31 | + fixture.detectChanges(); |
| 32 | + |
| 33 | + rippleTarget = fixture.nativeElement.querySelector('.mat-ripple'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('does not run events inside the NgZone', () => { |
| 37 | + const spy = jasmine.createSpy('zone unstable callback'); |
| 38 | + const subscription = fixture.ngZone!.onUnstable.subscribe(spy); |
| 39 | + |
| 40 | + dispatchMouseEvent(rippleTarget, 'mousedown'); |
| 41 | + dispatchMouseEvent(rippleTarget, 'mouseup'); |
| 42 | + |
| 43 | + expect(spy).not.toHaveBeenCalled(); |
| 44 | + subscription.unsubscribe(); |
| 45 | + }); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +@Component({ |
| 50 | + template: ` |
| 51 | + <div id="container" #ripple="matRipple" matRipple |
| 52 | + style="position: relative; width:300px; height:200px;"> |
| 53 | + </div> |
| 54 | + `, |
| 55 | + standalone: true, |
| 56 | + imports: [MatRippleModule], |
| 57 | +}) |
| 58 | +class BasicRippleContainer { |
| 59 | + @ViewChild('ripple') ripple: MatRipple; |
| 60 | +} |
0 commit comments