2017-02-23 11:51:00 -05:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2017-02-28 20:49:37 -05:00
|
|
|
import {animate, style, transition, trigger} from '@angular/animations';
|
2017-05-02 18:45:48 -04:00
|
|
|
import {ɵAnimationEngine} from '@angular/animations/browser';
|
2017-02-23 11:51:00 -05:00
|
|
|
import {Component} from '@angular/core';
|
|
|
|
import {TestBed} from '@angular/core/testing';
|
2018-12-05 08:39:54 -05:00
|
|
|
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
|
2017-02-23 11:51:00 -05:00
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2017-02-24 12:36:58 -05:00
|
|
|
describe('NoopAnimationsModule', () => {
|
2017-02-28 02:08:19 -05:00
|
|
|
beforeEach(() => { TestBed.configureTestingModule({imports: [NoopAnimationsModule]}); });
|
2017-02-23 11:51:00 -05:00
|
|
|
|
2018-12-06 18:57:52 -05:00
|
|
|
it('should flush and fire callbacks when the zone becomes stable', (async) => {
|
|
|
|
@Component({
|
|
|
|
selector: 'my-cmp',
|
|
|
|
template:
|
|
|
|
'<div [@myAnimation]="exp" (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>',
|
|
|
|
animations: [trigger(
|
|
|
|
'myAnimation',
|
|
|
|
[transition(
|
|
|
|
'* => state', [style({'opacity': '0'}), animate(500, style({'opacity': '1'}))])])],
|
|
|
|
})
|
|
|
|
class Cmp {
|
|
|
|
exp: any;
|
|
|
|
startEvent: any;
|
|
|
|
doneEvent: any;
|
|
|
|
onStart(event: any) { this.startEvent = event; }
|
|
|
|
onDone(event: any) { this.doneEvent = event; }
|
|
|
|
}
|
2018-12-05 08:39:54 -05:00
|
|
|
|
2018-12-06 18:57:52 -05:00
|
|
|
TestBed.configureTestingModule({declarations: [Cmp]});
|
2017-02-23 11:51:00 -05:00
|
|
|
|
2018-12-06 18:57:52 -05:00
|
|
|
const fixture = TestBed.createComponent(Cmp);
|
|
|
|
const cmp = fixture.componentInstance;
|
|
|
|
cmp.exp = 'state';
|
|
|
|
fixture.detectChanges();
|
|
|
|
fixture.whenStable().then(() => {
|
|
|
|
expect(cmp.startEvent.triggerName).toEqual('myAnimation');
|
|
|
|
expect(cmp.startEvent.phaseName).toEqual('start');
|
|
|
|
expect(cmp.doneEvent.triggerName).toEqual('myAnimation');
|
|
|
|
expect(cmp.doneEvent.phaseName).toEqual('done');
|
|
|
|
async();
|
|
|
|
});
|
|
|
|
});
|
2017-02-23 11:51:00 -05:00
|
|
|
|
2018-12-06 18:57:52 -05:00
|
|
|
it('should handle leave animation callbacks even if the element is destroyed in the process',
|
|
|
|
(async) => {
|
|
|
|
@Component({
|
|
|
|
selector: 'my-cmp',
|
|
|
|
template:
|
|
|
|
'<div *ngIf="exp" @myAnimation (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>',
|
|
|
|
animations: [trigger(
|
|
|
|
'myAnimation',
|
|
|
|
[transition(
|
|
|
|
':leave', [style({'opacity': '0'}), animate(500, style({'opacity': '1'}))])])],
|
|
|
|
})
|
|
|
|
class Cmp {
|
|
|
|
exp: any;
|
|
|
|
startEvent: any;
|
|
|
|
doneEvent: any;
|
|
|
|
onStart(event: any) { this.startEvent = event; }
|
|
|
|
onDone(event: any) { this.doneEvent = event; }
|
|
|
|
}
|
2017-02-23 12:41:00 -05:00
|
|
|
|
2018-12-06 18:57:52 -05:00
|
|
|
TestBed.configureTestingModule({declarations: [Cmp]});
|
2019-08-28 19:22:36 -04:00
|
|
|
const engine = TestBed.inject(ɵAnimationEngine);
|
2018-12-06 18:57:52 -05:00
|
|
|
const fixture = TestBed.createComponent(Cmp);
|
|
|
|
const cmp = fixture.componentInstance;
|
2017-02-23 12:41:00 -05:00
|
|
|
|
2018-12-06 18:57:52 -05:00
|
|
|
cmp.exp = true;
|
|
|
|
fixture.detectChanges();
|
|
|
|
fixture.whenStable().then(() => {
|
|
|
|
cmp.startEvent = null;
|
|
|
|
cmp.doneEvent = null;
|
2017-02-23 12:41:00 -05:00
|
|
|
|
2018-12-06 18:57:52 -05:00
|
|
|
cmp.exp = false;
|
|
|
|
fixture.detectChanges();
|
|
|
|
fixture.whenStable().then(() => {
|
|
|
|
expect(cmp.startEvent.triggerName).toEqual('myAnimation');
|
|
|
|
expect(cmp.startEvent.phaseName).toEqual('start');
|
|
|
|
expect(cmp.startEvent.toState).toEqual('void');
|
|
|
|
expect(cmp.doneEvent.triggerName).toEqual('myAnimation');
|
|
|
|
expect(cmp.doneEvent.phaseName).toEqual('done');
|
|
|
|
expect(cmp.doneEvent.toState).toEqual('void');
|
|
|
|
async();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-02-23 11:51:00 -05:00
|
|
|
});
|
|
|
|
}
|