|
| 1 | +import { |
| 2 | + el, |
| 3 | + describe, |
| 4 | + ddescribe, |
| 5 | + beforeEach, |
| 6 | + it, |
| 7 | + iit, |
| 8 | + expect, |
| 9 | + inject, |
| 10 | + SpyObject |
| 11 | +} from 'angular2/testing_internal'; |
| 12 | +import {CssAnimationOptions} from 'angular2/src/animate/css_animation_options'; |
| 13 | +import {Animation} from 'angular2/src/animate/animation'; |
| 14 | +import {BrowserDetails} from 'angular2/src/animate/browser_details'; |
| 15 | +import {DOM} from 'angular2/src/platform/dom/dom_adapter'; |
| 16 | + |
| 17 | +export function main() { |
| 18 | + describe("Animation", () => { |
| 19 | + var element; |
| 20 | + |
| 21 | + beforeEach(() => { element = el('<div></div>'); }); |
| 22 | + |
| 23 | + describe('transition-duration', () => { |
| 24 | + it('should only be applied for the duration of the animation', () => { |
| 25 | + var data = new CssAnimationOptions(); |
| 26 | + data.duration = 1000; |
| 27 | + |
| 28 | + expect(element).not.toHaveCssStyle('transition-duration'); |
| 29 | + |
| 30 | + new Animation(element, data, new BrowserDetails()); |
| 31 | + expect(element).toHaveCssStyle({'transition-duration': '1000ms'}); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should be removed once the animation is over', () => { |
| 35 | + var data = new CssAnimationOptions(); |
| 36 | + data.duration = 1000; |
| 37 | + |
| 38 | + var animation = new Animation(element, data, new BrowserDetails()); |
| 39 | + expect(element).toHaveCssStyle({'transition-duration': '1000ms'}); |
| 40 | + |
| 41 | + animation.handleAnimationCompleted(); |
| 42 | + expect(element).not.toHaveCssStyle('transition-duration'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should be restore the pre-existing transition-duration once the animation is over if present', |
| 46 | + () => { |
| 47 | + DOM.setStyle(element, 'transition-duration', '5s'); |
| 48 | + expect(element).toHaveCssStyle({'transition-duration': '5s'}); |
| 49 | + |
| 50 | + var data = new CssAnimationOptions(); |
| 51 | + data.duration = 1000; |
| 52 | + |
| 53 | + var animation = new Animation(element, data, new BrowserDetails()); |
| 54 | + expect(element).toHaveCssStyle({'transition-duration': '1000ms'}); |
| 55 | + |
| 56 | + animation.handleAnimationCompleted(); |
| 57 | + |
| 58 | + expect(element).toHaveCssStyle({'transition-duration': '5s'}); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe('transition-delay', () => { |
| 63 | + it('should only be applied for the delay of the animation', () => { |
| 64 | + var data = new CssAnimationOptions(); |
| 65 | + data.delay = 1000; |
| 66 | + |
| 67 | + expect(element).not.toHaveCssStyle('transition-delay'); |
| 68 | + |
| 69 | + new Animation(element, data, new BrowserDetails()); |
| 70 | + expect(element).toHaveCssStyle({'transition-delay': '1000ms'}); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should be removed once the animation is over', () => { |
| 74 | + var data = new CssAnimationOptions(); |
| 75 | + data.delay = 1000; |
| 76 | + |
| 77 | + var animation = new Animation(element, data, new BrowserDetails()); |
| 78 | + expect(element).toHaveCssStyle({'transition-delay': '1000ms'}); |
| 79 | + |
| 80 | + animation.handleAnimationCompleted(); |
| 81 | + expect(element).not.toHaveCssStyle('transition-delay'); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should be restore the pre-existing transition-delay once the animation is over if present', |
| 85 | + () => { |
| 86 | + DOM.setStyle(element, 'transition-delay', '5s'); |
| 87 | + expect(element).toHaveCssStyle({'transition-delay': '5s'}); |
| 88 | + |
| 89 | + var data = new CssAnimationOptions(); |
| 90 | + data.delay = 1000; |
| 91 | + |
| 92 | + var animation = new Animation(element, data, new BrowserDetails()); |
| 93 | + expect(element).toHaveCssStyle({'transition-delay': '1000ms'}); |
| 94 | + |
| 95 | + animation.handleAnimationCompleted(); |
| 96 | + |
| 97 | + expect(element).toHaveCssStyle({'transition-delay': '5s'}); |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + describe('temporary animation styles', () => { |
| 102 | + it('should be applied temporarily for the duration of the animation', () => { |
| 103 | + var data = new CssAnimationOptions(); |
| 104 | + data.duration = 1000; |
| 105 | + data.animationStyles = {'width': '100px', 'opacity': '0.5'}; |
| 106 | + |
| 107 | + var animation = new Animation(element, data, new BrowserDetails()); |
| 108 | + expect(element) |
| 109 | + .toHaveCssStyle({'opacity': '0.5', 'width': '100px', 'transition-duration': '1000ms'}); |
| 110 | + |
| 111 | + animation.handleAnimationCompleted(); |
| 112 | + expect(element).not.toHaveCssStyle('width'); |
| 113 | + expect(element).not.toHaveCssStyle('opacity'); |
| 114 | + expect(element).not.toHaveCssStyle('transition-duration'); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should be restored back to the original styles on the element', () => { |
| 118 | + DOM.setStyle(element, 'height', '555px'); |
| 119 | + |
| 120 | + var data = new CssAnimationOptions(); |
| 121 | + data.duration = 1000; |
| 122 | + data.animationStyles = {'width': '100px', 'height': '999px'}; |
| 123 | + |
| 124 | + var animation = new Animation(element, data, new BrowserDetails()); |
| 125 | + expect(element).toHaveCssStyle({'width': '100px', 'height': '999px'}); |
| 126 | + |
| 127 | + animation.handleAnimationCompleted(); |
| 128 | + expect(element).not.toHaveCssStyle('width'); |
| 129 | + expect(element).toHaveCssStyle({'height': '555px'}); |
| 130 | + }); |
| 131 | + }); |
| 132 | + }); |
| 133 | +} |
0 commit comments