Skip to content
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
51 changes: 41 additions & 10 deletions src/material-experimental/mdc-progress-bar/progress-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {Component, DebugElement, Provider, Type} from '@angular/core';
import {ApplicationRef, Component, DebugElement, Provider, Type} from '@angular/core';
import {By} from '@angular/platform-browser';
import {dispatchFakeEvent} from '../../cdk/testing/private';
import {MatProgressBarModule, MAT_PROGRESS_BAR_DEFAULT_OPTIONS} from './index';
Expand Down Expand Up @@ -231,14 +231,16 @@ describe('MDC-based MatProgressBar', () => {

it('should trigger output event on primary value bar animation end', () => {
fixture.detectChanges();
spyOn(progressComponent.animationEnd, 'next');

const animationEndSpy = jasmine.createSpy();
progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();
expect(animationEndSpy).not.toHaveBeenCalled();

// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40});
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});
});

Expand Down Expand Up @@ -267,27 +269,56 @@ describe('MDC-based MatProgressBar', () => {

it('should trigger output event on primary value bar animation end', () => {
fixture.detectChanges();
spyOn(progressComponent.animationEnd, 'next');

const animationEndSpy = jasmine.createSpy();
progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();
expect(animationEndSpy).not.toHaveBeenCalled();

// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40});
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});

it('should trigger output event with value not bufferValue', () => {
fixture.detectChanges();
spyOn(progressComponent.animationEnd, 'next');

const animationEndSpy = jasmine.createSpy();
progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
progressComponent.bufferValue = 70;
expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();
expect(animationEndSpy).not.toHaveBeenCalled();

// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40});
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});

it('should not run change detection if there are no `animationEnd` observers', () => {
fixture.detectChanges();

const animationEndSpy = jasmine.createSpy();
const appRef = TestBed.inject(ApplicationRef);
spyOn(appRef, 'tick');

progressComponent.value = 30;
progressComponent.bufferValue = 60;
// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');

expect(appRef.tick).not.toHaveBeenCalled();

progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
progressComponent.bufferValue = 70;
// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');

expect(appRef.tick).toHaveBeenCalled();
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/material-experimental/mdc-progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ export class MatProgressBar
)
.pipe(filter((e: TransitionEvent) => e.target === this._primaryBar))
.subscribe(() => {
Comment thread
arturovt marked this conversation as resolved.
Resolved
if (this.animationEnd.observers.length === 0) {
return;
}

if (this.mode === 'determinate' || this.mode === 'buffer') {
this._ngZone.run(() => this.animationEnd.next({value: this.value}));
}
Expand Down
51 changes: 41 additions & 10 deletions src/material/progress-bar/progress-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {Component, DebugElement, Provider, Type} from '@angular/core';
import {ApplicationRef, Component, DebugElement, Provider, Type} from '@angular/core';
import {By} from '@angular/platform-browser';
import {dispatchFakeEvent} from '../../cdk/testing/private';
import {MatProgressBarModule, MAT_PROGRESS_BAR_LOCATION} from './index';
Expand Down Expand Up @@ -270,14 +270,16 @@ describe('MatProgressBar', () => {

it('should trigger output event on primary value bar animation end', () => {
fixture.detectChanges();
spyOn(progressComponent.animationEnd, 'next');

const animationEndSpy = jasmine.createSpy();
progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();
expect(animationEndSpy).not.toHaveBeenCalled();

// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40});
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});
});

Expand Down Expand Up @@ -306,27 +308,56 @@ describe('MatProgressBar', () => {

it('should trigger output event on primary value bar animation end', () => {
fixture.detectChanges();
spyOn(progressComponent.animationEnd, 'next');

const animationEndSpy = jasmine.createSpy();
progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();
expect(animationEndSpy).not.toHaveBeenCalled();

// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40});
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});

it('should trigger output event with value not bufferValue', () => {
fixture.detectChanges();
spyOn(progressComponent.animationEnd, 'next');

const animationEndSpy = jasmine.createSpy();
progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
progressComponent.bufferValue = 70;
expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();
expect(animationEndSpy).not.toHaveBeenCalled();

// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40});
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});

it('should not run change detection if there are no `animationEnd` observers', () => {
fixture.detectChanges();

const animationEndSpy = jasmine.createSpy();
const appRef = TestBed.inject(ApplicationRef);
spyOn(appRef, 'tick');

progressComponent.value = 30;
progressComponent.bufferValue = 60;
// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');

expect(appRef.tick).not.toHaveBeenCalled();

progressComponent.animationEnd.subscribe(animationEndSpy);

progressComponent.value = 40;
progressComponent.bufferValue = 70;
// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');

expect(appRef.tick).toHaveBeenCalled();
expect(animationEndSpy).toHaveBeenCalledWith({value: 40});
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/material/progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export class MatProgressBar
)
.pipe(filter((e: TransitionEvent) => e.target === element))
.subscribe(() => {
if (this.animationEnd.observers.length === 0) {
return;
}

if (this.mode === 'determinate' || this.mode === 'buffer') {
this._ngZone.run(() => this.animationEnd.next({value: this.value}));
}
Expand Down