File size: 5,419 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
 * @group calypso-pr
 * @group gutenberg
 * @group jetpack-wpcom-integration
 */

import {
	DataHelper,
	MediaHelper,
	EditorPage,
	ImageBlock,
	AudioBlock,
	FileBlock,
	VideoPressBlock,
	TestFile,
	TestAccount,
	envVariables,
	getTestAccountByFeature,
	envToFeatureKey,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import { TEST_IMAGE_PATH, TEST_AUDIO_PATH, TEST_VIDEO_PATH } from '../constants';

declare const browser: Browser;

/**
 * Tests the media-related blocks.
 *
 * Keywords: Media, Video, VideoPress, Image, Audio, File
 */
describe( DataHelper.createSuiteTitle( 'Blocks: Media (Upload)' ), function () {
	const features = envToFeatureKey( envVariables );

	// Default to `defaultUser` as it has WordPress.com Premium enabled, which is required
	// for VideoPress block testing.
	const accountName = getTestAccountByFeature( features, [
		{
			gutenberg: 'stable',
			siteType: 'simple',
			accountName: 'defaultUser',
		},
		{
			gutenberg: 'edge',
			siteType: 'simple',
			accountName: 'defaultUser',
		},
	] );

	let page: Page;
	let testAccount: TestAccount;
	let editorPage: EditorPage;
	let testFiles: {
		image: TestFile;
		imageReservedName: TestFile;
		audio: TestFile;
		video: TestFile;
	};

	beforeAll( async () => {
		page = await browser.newPage();

		testFiles = {
			image: await MediaHelper.createTestFile( TEST_IMAGE_PATH ),
			imageReservedName: await MediaHelper.createTestFile( TEST_IMAGE_PATH, {
				postfix: 'filewith#?#?reservedurlchars',
			} ),
			audio: await MediaHelper.createTestFile( TEST_AUDIO_PATH ),
			video: await MediaHelper.createTestFile( TEST_VIDEO_PATH ),
		};

		testAccount = new TestAccount( accountName );
		await testAccount.authenticate( page );
	} );

	it( 'Start new post', async function () {
		editorPage = new EditorPage( page );

		await editorPage.visit( 'post', { siteSlug: testAccount.getSiteURL( { protocol: false } ) } );
		await editorPage.enterTitle( DataHelper.getRandomPhrase() );
	} );

	describe( 'Populate post with media blocks', function () {
		it( `${ ImageBlock.blockName } block: upload image file with reserved URL characters`, async function () {
			const blockHandle = await editorPage.addBlockFromSidebar(
				ImageBlock.blockName,
				ImageBlock.blockEditorSelector,
				{ noSearch: true }
			);
			const imageBlock = new ImageBlock( page, blockHandle );
			await imageBlock.upload( testFiles.imageReservedName.fullpath );
		} );

		it( `${ ImageBlock.blockName } block: upload image file using Calypso media modal `, async function () {
			const blockHandle = await editorPage.addBlockFromSidebar(
				ImageBlock.blockName,
				ImageBlock.blockEditorSelector,
				{ noSearch: true }
			);
			const imageBlock = new ImageBlock( page, blockHandle );
			await imageBlock.uploadThroughMediaLibrary( testFiles.image.fullpath );
		} );

		it( `${ AudioBlock.blockName } block: upload audio file`, async function () {
			const blockHandle = await editorPage.addBlockFromSidebar(
				AudioBlock.blockName,
				AudioBlock.blockEditorSelector,
				{ noSearch: true }
			);
			const audioBlock = new AudioBlock( blockHandle );
			await audioBlock.upload( testFiles.audio.fullpath );
		} );

		it( `${ FileBlock.blockName } block: upload audio file`, async function () {
			const blockHandle = await editorPage.addBlockFromSidebar(
				FileBlock.blockName,
				FileBlock.blockEditorSelector,
				{ noSearch: true }
			);
			const fileBlock = new FileBlock( page, blockHandle );
			await fileBlock.upload( testFiles.audio.fullpath );
		} );

		// If this starts failing, check whether Premium or higher plan is enabled.
		// 2024-09-16: Skipping. This has been failing all year, seems to be a problem with the backend and the way the test sites get cleaned up. p1707923887553869-slack-C034JEXD1RD
		it.skip( `${ VideoPressBlock.blockName } block: upload video file`, async function () {
			await editorPage.addBlockFromSidebar(
				VideoPressBlock.blockName,
				VideoPressBlock.blockEditorSelector,
				{ noSearch: true }
			);

			const videoPressBlock = new VideoPressBlock( page );
			await videoPressBlock.upload( testFiles.video.fullpath );
		} );

		it( 'Publish and visit post', async function () {
			await editorPage.saveDraft();
			await editorPage.publish( { visit: true } );
		} );
	} );

	describe( 'Validate published post', function () {
		it( 'Image with reserved characters in filename is visible', async function () {
			await Promise.any( [
				// WP < 6.6
				ImageBlock.validatePublishedContent( page, [
					testFiles.imageReservedName.filename.replace( /[^a-zA-Z ]/g, '' ),
				] ),
				// WP 6.6+, see https://github.com/WordPress/wordpress-develop/commit/2358de1767168232ff0e7c17e550b8a99f96002e
				ImageBlock.validatePublishedContent( page, [ testFiles.imageReservedName.filename ] ),
			] );
		} );

		it( 'Image added via Calypso modal is visible', async function () {
			await ImageBlock.validatePublishedContent( page, [ testFiles.image.filename ] );
		} );

		it( 'Audio block is visible', async function () {
			await AudioBlock.validatePublishedContent( page );
		} );

		it( 'File block is visible', async function () {
			await FileBlock.validatePublishedContent( page, [ testFiles.audio.filename ] );
		} );

		// Skipped above.
		it.skip( 'VideoPress block is visible', async function () {
			await VideoPressBlock.validatePublishedContent( page );
		} );
	} );
} );