Skip to content

Commit

Permalink
🐛 Fix Animation.animate breakage caused by missing import. (#30264)
Browse files Browse the repository at this point in the history
* fix

* added lint and test for bug

* weird space

* rename test

* dupe test

* comment

Co-authored-by: Derek Tse <derektse@google.com>
(cherry picked from commit d83351b)
  • Loading branch information
xiexr151e authored and ampprojectbot committed Sep 18, 2020
1 parent 63e64fe commit 07856de
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -187,7 +187,7 @@ module.exports = {
'no-lone-blocks': 2,
'no-native-reassign': 2,
'no-redeclare': 2,
'no-restricted-globals': [2, 'error', 'event'],
'no-restricted-globals': [2, 'error', 'event', 'Animation'],
'no-script-url': 2,
'no-self-compare': 2,
'no-sequences': 2,
Expand Down
1 change: 1 addition & 0 deletions src/service/fixed-layer.js
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import {Animation} from '../animation';
import {Pass} from '../pass';
import {Services} from '../services';
import {
Expand Down
54 changes: 54 additions & 0 deletions test/unit/test-fixed-layer.js
Expand Up @@ -15,6 +15,7 @@
*/

import {AmpDocSingle, installDocService} from '../../src/service/ampdoc-impl';
import {Animation} from '../../src/animation';
import {FakeMutationObserver, FakeWindow} from '../../testing/fake-dom';
import {FixedLayer} from '../../src/service/fixed-layer';
import {Services} from '../../src/services';
Expand Down Expand Up @@ -1832,3 +1833,56 @@ describes.sandboxed(
});
}
);

describes.sandboxed(
'FixedLayer bug due to calling browser native instead of AMP implementation',
{},
() => {
let win;
let ampdoc;
let viewer;
let vsyncApi;

beforeEach(() => {
win = new FakeWindow();
window.__AMP_MODE = {
localDev: true,
development: false,
minified: false,
test: false,
version: '$internalRuntimeVersion$',
};

const vsyncTasks = [];
vsyncApi = {
runPromise: async (task) => {
vsyncTasks.push(task);
},
mutate: (mutator) => {
vsyncTasks.push({mutate: mutator});
},
};
});

it('should call Animation.animate in animateFixedElements', () => {
const animateSpy = window.sandbox.spy(Animation, 'animate');

ampdoc = new AmpDocSingle(win);
installPlatformService(win);
installTimerService(win);
installViewerServiceForDoc(ampdoc);
viewer = Services.viewerForDoc(ampdoc);
viewer.isEmbedded = () => true;

const fixedLayer = new FixedLayer(
ampdoc,
vsyncApi,
/* borderTop */ 0,
/* paddingTop */ 11,
/* transfer */ false
);
fixedLayer.animateFixedElements(123, 456, 789, 'ease-in', false);
expect(animateSpy).to.be.calledOnce;
});
}
);

0 comments on commit 07856de

Please sign in to comment.