File size: 2,168 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
import { Page } from 'playwright';
import { EditorComponent } from '../components';

/**
 * Represents the VideoPress block.
 */
export class VideoPressBlock {
	static blockName = 'VideoPress';
	static blockEditorSelector = `div[aria-label="Block: ${ VideoPressBlock.blockName }"]`;

	private page: Page;
	private editor: EditorComponent;

	/**
	 * Constructs an instance of this block.
	 *
	 * @param {Page} page The underlying page object.
	 */
	constructor( page: Page ) {
		this.page = page;
		this.editor = new EditorComponent( page );
	}

	/**
	 * Uplaods the target file.
	 *
	 * @param {string} path Path to the file on disk.
	 */
	async upload( path: string ) {
		const editorCanvas = await this.editor.canvas();
		const block = editorCanvas.getByRole( 'document', {
			name: `Block: ${ VideoPressBlock.blockName }`,
		} );

		await block.locator( 'input' ).setInputFiles( path );

		// We reduced it to 10 seconds because it is taking too long when it fails and is causing
		// some execution timeout tests. (p1716579913775549/1716577210.067319-slack-CBTN58FTJ)
		await block.getByText( 'Upload Complete!' ).waitFor( { timeout: 10 * 1000 } );
		await block.getByRole( 'button', { name: 'Done' } ).click();

		await block.getByText( 'We are converting this video for optimal playback' ).waitFor( {
			timeout: 15 * 1000,
			state: 'hidden',
		} );
	}

	/**
	 * Clicks a matching button on the block.
	 *
	 * @param {string} text Text of the button to click.
	 */
	async clickButton( text: string ) {
		const editorCanvas = await this.editor.canvas();
		const block = editorCanvas.getByRole( 'document', {
			name: `Block: ${ VideoPressBlock.blockName }`,
		} );

		await block.frameLocator( '.components-sandbox' ).getByRole( 'button', { name: text } ).click();
	}

	/**
	 * Validates block on the page.
	 *
	 * @param {Page} page Page on which to verify the presence of the block.
	 */
	static async validatePublishedContent( page: Page ) {
		// According to p1692879768772799/1692861705.317909-slack-C02LT75D3, it is
		// not necessary to check whether the video can actually playback.
		await page.locator( '.wp-block-jetpack-videopress' ).waitFor();
	}
}