Skip to content

Commit f0cdc8f

Browse files
committed
Update the animation scaling factor test to cover all pan animations.
1 parent c54c56d commit f0cdc8f

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

extensions/amp-story/1.0/test/test-full-bleed-animations.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -250,34 +250,42 @@ describes.realWin(
250250
expect(calculatedKeyframes).to.deep.equal(expectedKeyframes);
251251
});
252252

253-
it('Should not scale the target if static scale is set.', () => {
254-
const staticFactor = 2;
253+
['pan-up', 'pan-down', 'pan-right', 'pan-left'].forEach((panAnimation) => {
254+
it(`Should scale the target for ${panAnimation}.`, () => {
255+
const dimensions = setDimensions(380, 580, 360, 580);
256+
expect(targetFitsWithinPage(dimensions)).to.be.true;
257+
258+
const factorThatWillMakeTargetFitPage = 380 / 360;
259+
const factor = factorThatWillMakeTargetFitPage * 1.25;
260+
expect(calculateTargetScalingFactor(dimensions)).to.equal(factor);
261+
262+
const calculatedKeyframes = presets[panAnimation].keyframes(
263+
dimensions,
264+
/* options */ {}
265+
);
255266

256-
const dimensions = setDimensions(380, 580, 360, 580);
257-
expect(targetFitsWithinPage(dimensions)).to.be.true;
267+
const expectedScaleFactorStr = `scale(${factor})`;
268+
calculatedKeyframes.forEach((keyframe) => {
269+
expect(keyframe.transform).to.contain(expectedScaleFactorStr);
270+
});
271+
});
258272

259-
const calculatedKeyframes = presets['pan-up'].keyframes(
260-
dimensions,
261-
/* options */ {'pan-static-scale': staticFactor}
262-
);
273+
it(`Should not scale the target if static scale is set for ${panAnimation}.`, () => {
274+
const staticFactor = 2;
263275

264-
const offsetX = -dimensions.targetWidth / 2;
265-
const offsetY = dimensions.pageHeight - dimensions.targetHeight;
276+
const dimensions = setDimensions(380, 580, 360, 580);
277+
expect(targetFitsWithinPage(dimensions)).to.be.true;
266278

267-
const expectedKeyframes = [
268-
{
269-
'transform': `translate(${offsetX}px, ${offsetY}px) scale(${staticFactor})`,
270-
'transform-origin': 'left top',
271-
},
272-
{
273-
'transform': `translate(${offsetX}px, 0px) scale(${staticFactor})`,
274-
'transform-origin': 'left top',
275-
},
276-
];
279+
const calculatedKeyframes = presets[panAnimation].keyframes(
280+
dimensions,
281+
/* options */ {'pan-static-scale': staticFactor}
282+
);
277283

278-
expect(calculatedKeyframes[0].transform).to.equal(
279-
expectedKeyframes[0].transform
280-
);
284+
const expectedScaleFactorStr = `scale(${staticFactor})`;
285+
calculatedKeyframes.forEach((keyframe) => {
286+
expect(keyframe.transform).to.contain(expectedScaleFactorStr);
287+
});
288+
});
281289
});
282290
}
283291
);

0 commit comments

Comments
 (0)