Skip to content

Commit

Permalink
[amp-vimeo] add unit tests (#32814)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanek committed Feb 23, 2021
1 parent 6cad6f0 commit 5cb3446
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions extensions/amp-vimeo/0.1/test/test-amp-vimeo.js
Expand Up @@ -15,6 +15,7 @@
*/

import '../amp-vimeo';
import {VideoUtils} from '../../../../src/utils/video';

describes.realWin(
'amp-vimeo',
Expand All @@ -24,14 +25,21 @@ describes.realWin(
},
},
(env) => {
let win, doc;
let win, doc, videoUtilsMock;

beforeEach(() => {
win = env.win;
doc = win.document;
videoUtilsMock = env.sandbox.stub(VideoUtils, 'isAutoplaySupported');
videoUtilsMock.returns(Promise.resolve(true));
});

async function getVimeo(videoId, opt_responsive, opt_doNotTrack) {
async function getVimeo(
videoId,
opt_responsive,
opt_doNotTrack,
opt_isAutoPlay
) {
const vimeo = doc.createElement('amp-vimeo');
vimeo.setAttribute('data-videoid', videoId);
vimeo.setAttribute('width', '111');
Expand All @@ -42,6 +50,9 @@ describes.realWin(
if (opt_doNotTrack) {
vimeo.setAttribute('do-not-track', '');
}
if (opt_isAutoPlay) {
vimeo.setAttribute('autoplay', '');
}
doc.body.appendChild(vimeo);
await vimeo.buildInternal();
await vimeo.layoutCallback();
Expand Down Expand Up @@ -74,5 +85,19 @@ describes.realWin(
const iframe = vimeo.querySelector('iframe');
expect(iframe.src).to.equal('https://player.vimeo.com/video/2323?dnt=1');
});

it('should append muted=1 if video is autoplay', async () => {
const vimeo = await getVimeo('0123', true, false, true);
const iframe = vimeo.querySelector('iframe');
expect(iframe.src).to.equal(
'https://player.vimeo.com/video/0123?muted=1'
);
});

it('unlayoutCallback', async () => {
const vimeo = await getVimeo('0123', true, false, true);
vimeo.unlayoutCallback();
expect(vimeo.querySelector('iframe')).to.be.null;
});
}
);

0 comments on commit 5cb3446

Please sign in to comment.