Skip to content

Commit

Permalink
fixup! feat(material/button): make button ripples lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnermaciel committed Mar 14, 2023
1 parent 667d7cf commit 0079096
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/material/button/button.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {waitForAsync, ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/testing';
import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
import {ApplicationRef, Component, DebugElement} from '@angular/core';
import {By} from '@angular/platform-browser';
import {MatButtonModule, MatButton, MatFabDefaultOptions, MAT_FAB_DEFAULT_OPTIONS} from './index';
import {MatRipple, ThemePalette} from '@angular/material/core';
import {ThemePalette} from '@angular/material/core';
import {createMouseEvent, dispatchEvent} from '@angular/cdk/testing/private';
import {MatButtonRipple} from './button-ripple';

describe('MDC-based MatButton', () => {
beforeEach(waitForAsync(() => {
Expand Down Expand Up @@ -267,9 +268,11 @@ describe('MDC-based MatButton', () => {
let fixture: ComponentFixture<TestApp>;
let testComponent: TestApp;
let buttonDebugElement: DebugElement;
let buttonRippleInstance: MatRipple;
let buttonRippleDebugElement: DebugElement;
let buttonRippleInstance: MatButtonRipple;
let anchorDebugElement: DebugElement;
let anchorRippleInstance: MatRipple;
let anchorRippleDebugElement: DebugElement;
let anchorRippleInstance: MatButtonRipple;

beforeEach(() => {
fixture = TestBed.createComponent(TestApp);
Expand Down Expand Up @@ -313,35 +316,16 @@ describe('MDC-based MatButton', () => {
});
});

it('should not have a focus indicator before the user interacts', () => {
it('should have a focus indicator', () => {
const fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
const buttonNativeElements = [
...fixture.debugElement.nativeElement.querySelectorAll('a, button'),
];

expect(
buttonNativeElements.some(element => !!element.querySelector('.mat-mdc-focus-indicator')),
).toBe(false);
});

it('should have a focus indicator after the user interacts', fakeAsync(() => {
const fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
const buttonNativeElements = [
...fixture.debugElement.nativeElement.querySelectorAll('a, button'),
];

for (const element of buttonNativeElements) {
element.dispatchEvent(new Event('mouseenter'));
}

tick(50);

expect(
buttonNativeElements.every(element => !!element.querySelector('.mat-mdc-focus-indicator')),
).toBe(true);
}));
});
});

describe('MatFabDefaultOptions', () => {
Expand Down

0 comments on commit 0079096

Please sign in to comment.