|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | +import {DOMAnimation} from '../../../src/render/web_animations/dom_animation'; |
| 9 | +import {WebAnimationsPlayer} from '../../../src/render/web_animations/web_animations_player'; |
| 10 | + |
| 11 | +export function main() { |
| 12 | + let element: any; |
| 13 | + let innerPlayer: MockDomAnimation|null = null; |
| 14 | + beforeEach(() => { |
| 15 | + element = {}; |
| 16 | + element['animate'] = () => { return innerPlayer = new MockDomAnimation(); }; |
| 17 | + }); |
| 18 | + |
| 19 | + describe('WebAnimationsPlayer tests', () => { |
| 20 | + it('should automatically pause the player when created and initialized', () => { |
| 21 | + const keyframes = [ |
| 22 | + {opacity: 0, offset: 0}, |
| 23 | + {opacity: 1, offset: 1}, |
| 24 | + ]; |
| 25 | + |
| 26 | + const player = new WebAnimationsPlayer(element, keyframes, {duration: 1000}); |
| 27 | + |
| 28 | + player.init(); |
| 29 | + const p = innerPlayer !; |
| 30 | + expect(p.log).toEqual(['pause']); |
| 31 | + |
| 32 | + player.play(); |
| 33 | + expect(p.log).toEqual(['pause', 'play']); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should not pause the player if created and started before initialized', () => { |
| 37 | + const keyframes = [ |
| 38 | + {opacity: 0, offset: 0}, |
| 39 | + {opacity: 1, offset: 1}, |
| 40 | + ]; |
| 41 | + |
| 42 | + const player = new WebAnimationsPlayer(element, keyframes, {duration: 1000}); |
| 43 | + |
| 44 | + player.play(); |
| 45 | + const p = innerPlayer !; |
| 46 | + expect(p.log).toEqual(['play']); |
| 47 | + }); |
| 48 | + }); |
| 49 | +} |
| 50 | + |
| 51 | +class MockDomAnimation implements DOMAnimation { |
| 52 | + log: string[] = []; |
| 53 | + cancel(): void { this.log.push('cancel'); } |
| 54 | + play(): void { this.log.push('play'); } |
| 55 | + pause(): void { this.log.push('pause'); } |
| 56 | + finish(): void { this.log.push('finish'); } |
| 57 | + onfinish: Function = () => {}; |
| 58 | + position: number = 0; |
| 59 | + currentTime: number = 0; |
| 60 | + addEventListener(eventName: string, handler: (event: any) => any): any {} |
| 61 | + dispatchEvent(eventName: string): any {} |
| 62 | +} |
0 commit comments