Permalink
Browse files

Extend unit test for buildStyleInterpolator

Reviewed By: vjeux

Differential Revision: D5950672

fbshipit-source-id: 921ed6ae6a2b307b050c721cedd4b51e880695ae
  • Loading branch information...
kodafb authored and facebook-github-bot committed Oct 3, 2017
1 parent c550f27 commit 3e31038301e9e3bf8a332b97ed869f8d9603d0b6
Showing with 90 additions and 0 deletions.
  1. +90 −0 Libraries/Utilities/__tests__/buildStyleInterpolator-test.js
@@ -227,7 +227,97 @@ describe('buildStyleInterpolator', function() {
});
expect(res).toBe(false);
});
it('should handle identity', function() {
var testAnim = {
opacity: {
type: 'identity',
},
};
var interpolator = buildStyleInterpolator(testAnim);
var obj = {};
var res = interpolator(obj, 0.5);
expect(obj).toEqual({
opacity: 0.5,
});
expect(res).toBe(true);
res = interpolator(obj, 0.5);
// No change detected
expect(obj).toEqual({
opacity: 0.5,
});
expect(res).toBe(false);
});
it('should translate', function() {
var testAnim = {
transformTranslate: {
from: {x: 1, y: 10, z: 100},
to: {x: 5, y: 50, z: 500},
min: 0,
max: 4,
type: 'linear',
},
};
var interpolator = buildStyleInterpolator(testAnim);
var obj = {};
var res = interpolator(obj, 1);
expect(obj).toEqual({
transform: [{matrix: [1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
2, 20, 200, 1]}]
});
expect(res).toBe(true);
});
it('should scale', function() {
var testAnim = {
transformScale: {
from: {x: 1, y: 10, z: 100},
to: {x: 5, y: 50, z: 500},
min: 0,
max: 4,
type: 'linear',
},
};
var interpolator = buildStyleInterpolator(testAnim);
var obj = {};
var res = interpolator(obj, 1);
expect(obj).toEqual({
transform: [{matrix: [2, 0, 0, 0,
0, 20, 0, 0,
0, 0, 200, 0,
0, 0, 0, 1]}]
});
expect(res).toBe(true);
});
it('should combine scale and translate', function() {
var testAnim = {
transformScale: {
from: {x: 1, y: 10, z: 100},
to: {x: 5, y: 50, z: 500},
min: 0,
max: 4,
type: 'linear',
},
transformTranslate: {
from: {x: 1, y: 10, z: 100},
to: {x: 5, y: 50, z: 500},
min: 0,
max: 4,
type: 'linear',
},
};
var interpolator = buildStyleInterpolator(testAnim);
var obj = {};
var res = interpolator(obj, 1);
expect(obj).toEqual({
transform: [{matrix: [2, 0, 0, 0,
0, 20, 0, 0,
0, 0, 200, 0,
4, 400, 40000, 1]}]
});
expect(res).toBe(true);
});
it('should step', function() {
var testAnim = {
opacity: {

0 comments on commit 3e31038

Please sign in to comment.