Skip to content

test: Convert some material tests to zoneless #29309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/material/core/ripple/ripple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,6 @@ describe('MatRipple', () => {
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
});

it('does not run events inside the NgZone', () => {
const spy = jasmine.createSpy('zone unstable callback');
const subscription = fixture.ngZone!.onUnstable.subscribe(spy);

dispatchMouseEvent(rippleTarget, 'mousedown');
dispatchMouseEvent(rippleTarget, 'mouseup');

expect(spy).not.toHaveBeenCalled();
subscription.unsubscribe();
});

it('should only persist the latest ripple on pointer down', () => {
dispatchMouseEvent(rippleTarget, 'mousedown');
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
Expand Down
60 changes: 60 additions & 0 deletions src/material/core/ripple/ripple.zone.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {dispatchMouseEvent} from '@angular/cdk/testing/private';
import {Component, ViewChild} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {MatRippleModule} from '.';
import {MatRipple} from './ripple';

describe('MatRipple Zone.js integration', () => {
let fixture: ComponentFixture<any>;
let rippleTarget: HTMLElement;
let originalBodyMargin: string | null;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [MatRippleModule, BasicRippleContainer],
});
});

beforeEach(() => {
// Set body margin to 0 during tests so it doesn't mess up position calculations.
originalBodyMargin = document.body.style.margin;
document.body.style.margin = '0';
});

afterEach(() => {
document.body.style.margin = originalBodyMargin!;
});

describe('basic ripple', () => {
beforeEach(() => {
fixture = TestBed.createComponent(BasicRippleContainer);
fixture.detectChanges();

rippleTarget = fixture.nativeElement.querySelector('.mat-ripple');
});

it('does not run events inside the NgZone', () => {
const spy = jasmine.createSpy('zone unstable callback');
const subscription = fixture.ngZone!.onUnstable.subscribe(spy);

dispatchMouseEvent(rippleTarget, 'mousedown');
dispatchMouseEvent(rippleTarget, 'mouseup');

expect(spy).not.toHaveBeenCalled();
subscription.unsubscribe();
});
});
});

@Component({
template: `
<div id="container" #ripple="matRipple" matRipple
style="position: relative; width:300px; height:200px;">
</div>
`,
standalone: true,
imports: [MatRippleModule],
})
class BasicRippleContainer {
@ViewChild('ripple') ripple: MatRipple;
}
Loading