File size: 1,963 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
import { Locator, Page } from 'playwright';

const selectors = {
	chooseButton: 'button:has-text("Choose")',
	startBlankButton: 'button:has-text("Start blank")',
	addBlockButton: 'button[aria-label="Add block"]',
};

/**
 * Represents a Template Part block in the full site editor.
 */
export class TemplatePartBlock {
	static blockName = 'Template Part';
	static blockEditorSelector = 'div[aria-label="Block: Template Part"]';

	/**
	 * Creates an instance of the component.
	 *
	 * @param {Page} page Object representing the base page.
	 * @param {Locator} block Frame-safe locator to the top element of the block.
	 */
	constructor(
		private page: Page,
		public block: Locator
	) {}

	/**
	 * Click the "Start blank" button from the initial state..
	 */
	async clickStartBlank(): Promise< void > {
		const locator = this.block.locator( selectors.startBlankButton );
		await locator.click();
	}

	/**
	 * Click the "Choose" button from the initial state.
	 */
	async clickChoose(): Promise< void > {
		const locator = this.block.locator( selectors.chooseButton );
		await locator.click();
	}

	/**
	 * Clicks the add block button within this parent Template Part
	 */
	async clickAddBlockButton(): Promise< void > {
		const locator = this.block.locator( selectors.addBlockButton );
		await locator.click();
	}
}

/**
 * Represents a Header block in the full site editor.
 * This is just a Template Part block with different name and slightly different parent element markup.
 */
export class HeaderBlock extends TemplatePartBlock {
	static blockName = 'Header';
	static blockEditorSelector = 'header[aria-label="Block: Header"]';
}

/**
 * Represents a Footer block in the full site editor.
 * This is just a Template Part block with different name and slightly different parent element markup.
 */
export class FooterBlock extends TemplatePartBlock {
	static blockName = 'Footer';
	static blockEditorSelector = 'footer[aria-label="Block: Template Part"]';
}