2017-04-26 13:44:28 -04: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
|
|
|
|
*/
|
2020-04-13 19:40:21 -04:00
|
|
|
import {animate, AnimationBuilder, style} from '@angular/animations';
|
2017-04-26 13:44:28 -04:00
|
|
|
import {AnimationDriver} from '@angular/animations/browser';
|
|
|
|
import {MockAnimationDriver} from '@angular/animations/browser/testing';
|
|
|
|
import {Component, ViewChild} from '@angular/core';
|
2020-04-13 19:40:21 -04:00
|
|
|
import {fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing';
|
2018-12-05 08:39:54 -05:00
|
|
|
import {NoopAnimationsModule, ɵBrowserAnimationBuilder as BrowserAnimationBuilder} from '@angular/platform-browser/animations';
|
2017-04-26 13:44:28 -04:00
|
|
|
|
|
|
|
import {el} from '../../testing/src/browser_util';
|
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2017-04-26 13:44:28 -04:00
|
|
|
describe('BrowserAnimationBuilder', () => {
|
2017-12-18 01:18:50 -05:00
|
|
|
if (isNode) return;
|
2017-04-26 13:44:28 -04:00
|
|
|
let element: any;
|
|
|
|
beforeEach(() => {
|
|
|
|
element = el('<div></div>');
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
imports: [NoopAnimationsModule],
|
|
|
|
providers: [{provide: AnimationDriver, useClass: MockAnimationDriver}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should inject AnimationBuilder into a component', () => {
|
|
|
|
@Component({
|
|
|
|
selector: 'ani-cmp',
|
|
|
|
template: '...',
|
|
|
|
})
|
|
|
|
class Cmp {
|
|
|
|
constructor(public builder: AnimationBuilder) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({declarations: [Cmp]});
|
|
|
|
|
|
|
|
const fixture = TestBed.createComponent(Cmp);
|
|
|
|
const cmp = fixture.componentInstance;
|
|
|
|
|
|
|
|
fixture.detectChanges();
|
|
|
|
expect(cmp.builder instanceof BrowserAnimationBuilder).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen on start and done on the animation builder\'s player', fakeAsync(() => {
|
|
|
|
@Component({
|
|
|
|
selector: 'ani-cmp',
|
|
|
|
template: '...',
|
|
|
|
})
|
|
|
|
class Cmp {
|
2019-10-05 04:04:54 -04:00
|
|
|
@ViewChild('target') public target: any;
|
2017-04-26 13:44:28 -04:00
|
|
|
|
|
|
|
constructor(public builder: AnimationBuilder) {}
|
|
|
|
|
|
|
|
build() {
|
|
|
|
const definition =
|
|
|
|
this.builder.build([style({opacity: 0}), animate(1000, style({opacity: 1}))]);
|
|
|
|
|
|
|
|
return definition.create(this.target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({declarations: [Cmp]});
|
|
|
|
|
|
|
|
const fixture = TestBed.createComponent(Cmp);
|
|
|
|
const cmp = fixture.componentInstance;
|
|
|
|
fixture.detectChanges();
|
|
|
|
|
|
|
|
const player = cmp.build();
|
|
|
|
|
|
|
|
let started = false;
|
|
|
|
player.onStart(() => started = true);
|
|
|
|
|
|
|
|
let finished = false;
|
|
|
|
player.onDone(() => finished = true);
|
|
|
|
|
|
|
|
let destroyed = false;
|
|
|
|
player.onDestroy(() => destroyed = true);
|
|
|
|
|
|
|
|
player.init();
|
|
|
|
flushMicrotasks();
|
|
|
|
expect(started).toBeFalsy();
|
|
|
|
expect(finished).toBeFalsy();
|
|
|
|
expect(destroyed).toBeFalsy();
|
|
|
|
|
|
|
|
player.play();
|
|
|
|
flushMicrotasks();
|
|
|
|
expect(started).toBeTruthy();
|
|
|
|
expect(finished).toBeFalsy();
|
|
|
|
expect(destroyed).toBeFalsy();
|
|
|
|
|
|
|
|
player.finish();
|
|
|
|
flushMicrotasks();
|
|
|
|
expect(started).toBeTruthy();
|
|
|
|
expect(finished).toBeTruthy();
|
|
|
|
expect(destroyed).toBeFalsy();
|
|
|
|
|
|
|
|
player.destroy();
|
|
|
|
flushMicrotasks();
|
|
|
|
expect(started).toBeTruthy();
|
|
|
|
expect(finished).toBeTruthy();
|
|
|
|
expect(destroyed).toBeTruthy();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|