Skip to content

Commit

Permalink
Extend unit test for buildStyleInterpolator
Browse files Browse the repository at this point in the history
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 3e31038
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions Libraries/Utilities/__tests__/buildStyleInterpolator-test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -227,7 +227,97 @@ describe('buildStyleInterpolator', function() {
}); });
expect(res).toBe(false); 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() { it('should step', function() {
var testAnim = { var testAnim = {
opacity: { opacity: {
Expand Down

0 comments on commit 3e31038

Please sign in to comment.