Skip to content

Commit d24febf

Browse files
authored
PLANET-7633 Add e2e tests for Audio and Video blocks (#2447)
Since we recently enabled these two blocks in all sites, it's good to cover them
1 parent d1d02f5 commit d24febf

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/e2e/blocks/audio-video.spec.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {test, expect} from '../tools/lib/test-utils.js';
2+
import {publishPostAndVisit, createPostWithFeaturedImage} from '../tools/lib/post.js';
3+
import {searchAndInsertBlock} from '../tools/lib/editor.js';
4+
5+
const YOUTUBE_TEST = 'https://www.youtube.com/watch?v=-CwkccAgKrs';
6+
const VIMEO_TEST = 'https://vimeo.com/120680405';
7+
const MP4_TEST = 'https://www.greenpeace.org/static/planet4-assets/tests/edge_of_the_wrold.mp4';
8+
9+
const SOUNDCLOUD_TEST = 'https://soundcloud.com/greenpeaceuk-1/04-and-we-will-defend-requiem';
10+
const MP3_TEST = 'https://www.greenpeace.org/static/planet4-assets/tests/wochenserie_greenpeace.mp3';
11+
12+
/**
13+
* Add a Video or Audio block to a page with a specific link.
14+
*
15+
* @param {{Page}} page - The page object for interacting with the browser.
16+
* @param {string} mediaType - The type of media added (Audio or Video).
17+
* @param {string} mediaLink - The media file link (can be YouTube, Vimeo, mp4, mp3, SoundCloud).
18+
*/
19+
const addVideoOrAudioBlock = async ({page}, mediaType, mediaLink) => {
20+
await searchAndInsertBlock({page}, mediaType, mediaType);
21+
22+
// Make sure the block has been added.
23+
const insertUrl = await page.getByRole('button', {name: 'Insert from URL'});
24+
await expect(insertUrl).toBeVisible();
25+
26+
// We should close the sidebar before editing the block.
27+
const closeSidebar = await page.getByRole('button', {name: 'Close block inserter'});
28+
if (await closeSidebar.isVisible()) {
29+
await closeSidebar.click();
30+
await expect(closeSidebar).toBeHidden();
31+
}
32+
33+
// Add the media URL.
34+
await insertUrl.click();
35+
await page.getByPlaceholder('Paste or type URL').fill(mediaLink);
36+
await page.keyboard.press('Enter');
37+
};
38+
39+
test.useAdminLoggedIn();
40+
41+
test('check the Audio and Video blocks', async ({page, admin, editor}) => {
42+
// Create a post for the test.
43+
await createPostWithFeaturedImage({page, admin, editor}, {title: 'Test Audio and Video blocks'});
44+
45+
// Add Video blocks with the various examples.
46+
await addVideoOrAudioBlock({page}, 'video', YOUTUBE_TEST);
47+
await addVideoOrAudioBlock({page}, 'video', VIMEO_TEST);
48+
await addVideoOrAudioBlock({page}, 'video', MP4_TEST);
49+
50+
// Add Audio blocks with the various examples.
51+
await addVideoOrAudioBlock({page}, 'audio', SOUNDCLOUD_TEST);
52+
await addVideoOrAudioBlock({page}, 'audio', MP3_TEST);
53+
54+
// Publish page.
55+
await publishPostAndVisit({page, editor});
56+
57+
// Check on the frontend that the blocks are present.
58+
await expect(page.locator('.wp-block-embed-youtube')).toBeVisible();
59+
await expect(page.locator('.wp-block-embed-vimeo')).toBeVisible();
60+
await expect(page.locator('.wp-block-video > video')).toHaveAttribute('src', MP4_TEST);
61+
await expect(page.locator('.wp-block-embed-soundcloud')).toBeVisible();
62+
await expect(page.locator('.wp-block-audio > audio')).toHaveAttribute('src', MP3_TEST);
63+
});

0 commit comments

Comments
 (0)