OLD | NEW |
(Empty) | |
| 1 suite('transform-handler parsing', function() { |
| 2 test('parse skew values', function() { |
| 3 assert.deepEqual(parseTransform('skew(10deg) skew(12deg,45deg) skewX(0) skew
Y(1.5rad)'), [ |
| 4 {t: 'skew', d: [{deg: 10}, {deg: 0}]}, |
| 5 {t: 'skew', d: [{deg: 12}, {deg: 45}]}, |
| 6 {t: 'skewx', d: [{deg: 0}]}, |
| 7 {t: 'skewy', d: [{rad: 1.5}]} |
| 8 ]); |
| 9 }); |
| 10 |
| 11 test('parse scale values', function() { |
| 12 assert.deepEqual(parseTransform('scale(-2) scale(3,-4) scaleX(5) scaleY(-1)
scaleZ(-3)'), [ |
| 13 {t: 'scale', d: [-2, -2]}, |
| 14 {t: 'scale', d: [3, -4]}, |
| 15 {t: 'scalex', d: [5]}, |
| 16 {t: 'scaley', d: [-1]}, |
| 17 {t: 'scalez', d: [-3]} |
| 18 ]); |
| 19 assert.deepEqual(parseTransform('scale3d(-2, 0, 7)'), |
| 20 [{t: 'scale3d', d: [-2, 0, 7]}]); |
| 21 }); |
| 22 |
| 23 test('parse rotate values', function() { |
| 24 assert.deepEqual(parseTransform('rotate(10deg) rotateX(0) rotateY(1.5rad) ro
tateZ(50grad)'), [ |
| 25 {t: 'rotate', d: [{deg: 10}]}, |
| 26 {t: 'rotatex', d: [{deg: 0}]}, |
| 27 {t: 'rotatey', d: [{rad: 1.5}]}, |
| 28 {t: 'rotatez', d: [{grad: 50}]} |
| 29 ]); |
| 30 }); |
| 31 |
| 32 test('parse translate values', function() { |
| 33 assert.deepEqual(parseTransform('translate(20%, 30px) translate(30em, 40%) t
ranslate(50vw) translate(0)'), [ |
| 34 {t: 'translate', d: [{'%': 20}, {px: 30}]}, |
| 35 {t: 'translate', d: [{em: 30}, {'%': 40}]}, |
| 36 {t: 'translate', d: [{vw: 50}, {px: 0}]}, |
| 37 {t: 'translate', d: [{px: 0}, {px: 0}]} |
| 38 ]); |
| 39 assert.deepEqual(parseTransform('translateX(10px) translateX(20%) translateX
(0)'), [ |
| 40 {t: 'translatex', d: [{px: 10}]}, |
| 41 {t: 'translatex', d: [{'%': 20}]}, |
| 42 {t: 'translatex', d: [{px: 0}]} |
| 43 ]); |
| 44 assert.deepEqual(parseTransform('translateY(10px) translateY(20%) translateY
(0)'), [ |
| 45 {t: 'translatey', d: [{px: 10}]}, |
| 46 {t: 'translatey', d: [{'%': 20}]}, |
| 47 {t: 'translatey', d: [{px: 0}]} |
| 48 ]); |
| 49 assert.deepEqual(parseTransform('translateZ(10px) translateZ(0)'), [ |
| 50 {t: 'translatez', d: [{px: 10}]}, |
| 51 {t: 'translatez', d: [{px: 0}]} |
| 52 ]); |
| 53 assert.deepEqual(parseTransform('translate3d(10px, 20px, 30px) translate3d(0
, 40%, 0) translate3d(50%, 0, 60px)'), [ |
| 54 {t: 'translate3d', d: [{px: 10}, {px: 20}, {px: 30}]}, |
| 55 {t: 'translate3d', d: [{px: 0}, {'%': 40}, {px: 0}]}, |
| 56 {t: 'translate3d', d: [{'%': 50}, {px: 0}, {px: 60}]} |
| 57 ]); |
| 58 }); |
| 59 |
| 60 test('invalid transforms fail to parse', function() { |
| 61 assert.isUndefined(parseTransform('translate(10px')); |
| 62 assert.isUndefined(parseTransform('translate()')); |
| 63 assert.isUndefined(parseTransform('translatex()')); |
| 64 assert.isUndefined(parseTransform('translatex(5)')); |
| 65 assert.isUndefined(parseTransform('rotate(5)')); |
| 66 assert.isUndefined(parseTransform('skew(5)')); |
| 67 assert.isUndefined(parseTransform('scale(5px)')); |
| 68 assert.isUndefined(parseTransform('rotatex(5px)')); |
| 69 }); |
| 70 }); |
| 71 |
| 72 suite('transform-handler interpolation', function() { |
| 73 test('simple transform interpolations', function() { |
| 74 assert.equal( |
| 75 webAnimationsMinifill.propertyInterpolation( |
| 76 'transform', |
| 77 'translateX(10px)', |
| 78 'translateX(20px)')(0.2), |
| 79 'translatex(12px)'); |
| 80 assert.equal( |
| 81 webAnimationsMinifill.propertyInterpolation( |
| 82 'transform', |
| 83 'translate(10px, 10px) rotate(20deg)', |
| 84 'translate(20px, 20px) rotate(90deg)')(0.2), |
| 85 'translate(12px,12px) rotate(34deg)'); |
| 86 assert.equal( |
| 87 webAnimationsMinifill.propertyInterpolation( |
| 88 'transform', |
| 89 'translate(10px, 10em) rotate(20deg)', |
| 90 'translate(20em, 20px) rotate(90deg)')(0.5), |
| 91 'translate(calc(5px + 10em),calc(5em + 10px)) rotate(55deg)'); |
| 92 assert.equal( |
| 93 webAnimationsMinifill.propertyInterpolation( |
| 94 'transform', |
| 95 'rotateY(1000deg)', |
| 96 'rotateY(3000deg)')(0.4), |
| 97 'rotatey(1800deg)'); |
| 98 assert.equal( |
| 99 webAnimationsMinifill.propertyInterpolation( |
| 100 'transform', |
| 101 'scale(6)', |
| 102 'scale(1,-4)')(0.2), |
| 103 'scale(5,4)'); |
| 104 assert.equal( |
| 105 webAnimationsMinifill.propertyInterpolation( |
| 106 'transform', |
| 107 'skewX(5deg) translateY(5px)', |
| 108 'skewX(-35deg) translateY(45px)')(0.25), |
| 109 'skewx(-5deg) translatey(15px)'); |
| 110 }); |
| 111 |
| 112 test('transform interpolations with conversion to primitives', function() { |
| 113 assert.equal( |
| 114 webAnimationsMinifill.propertyInterpolation( |
| 115 'transform', |
| 116 'translateX(10px)', |
| 117 'translate(20px, 10px)')(0.2), |
| 118 'translate(12px,2px)'); |
| 119 assert.equal( |
| 120 webAnimationsMinifill.propertyInterpolation( |
| 121 'transform', |
| 122 'translateX(10px)', |
| 123 'translateY(10px)')(0.2), |
| 124 'translate(8px,2px)'); |
| 125 assert.equal( |
| 126 webAnimationsMinifill.propertyInterpolation( |
| 127 'transform', |
| 128 'translateX(10px)', |
| 129 'translateZ(10px)')(0.2), |
| 130 'translate3d(8px,0px,2px)'); |
| 131 assert.equal( |
| 132 webAnimationsMinifill.propertyInterpolation( |
| 133 'transform', |
| 134 'scaleX(6)', |
| 135 'scale(1,6)')(0.2), |
| 136 'scale(5,2)'); |
| 137 assert.equal( |
| 138 webAnimationsMinifill.propertyInterpolation( |
| 139 'transform', |
| 140 'skew(10deg)', |
| 141 'skewY(30deg)')(0.2), |
| 142 'skew(8deg,6deg)'); |
| 143 }); |
| 144 |
| 145 test('transform interpolations with none', function() { |
| 146 assert.equal( |
| 147 webAnimationsMinifill.propertyInterpolation( |
| 148 'transform', |
| 149 'none', |
| 150 'scale(5) translateX(100px) rotate(1000deg)')(0.25), |
| 151 'scale(2,2) translatex(25px) rotate(250deg)'); |
| 152 assert.equal( |
| 153 webAnimationsMinifill.propertyInterpolation( |
| 154 'transform', |
| 155 'scale(5) translateX(100px) rotate(1000deg)', |
| 156 'none')(0.75), |
| 157 'scale(2,2) translatex(25px) rotate(250deg)'); |
| 158 assert.equal( |
| 159 webAnimationsMinifill.propertyInterpolation( |
| 160 'transform', |
| 161 'none', |
| 162 'scaleX(5) skewY(100grad)')(0.25), |
| 163 'scalex(2) skewy(25grad)'); |
| 164 assert.equal( |
| 165 webAnimationsMinifill.propertyInterpolation( |
| 166 'transform', |
| 167 'none', |
| 168 'none')(0.4), |
| 169 'none'); |
| 170 }); |
| 171 }); |
OLD | NEW |