File size: 1,601 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
import { Page } from 'playwright';
import { envVariables } from '../..';
import { getCalypsoURL } from '../../data-helper';

/**
 * Represents the Sites > Site > Settings page.
 */
export class SiteSettingsPage {
	private page: Page;

	/**
	 * Constructs an instance of the component.
	 *
	 * @param {Page} page The underlying page.
	 */
	constructor( page: Page ) {
		this.page = page;
	}

	/**
	 * Visits the `/sites/settings/$tab` endpoint.
	 *
	 * @param {string} siteSlug Site URL.
	 * @param {string} tab      Settings tab.
	 */
	async visit( siteSlug: string, tab: string = 'site' ): Promise< void > {
		// Patch for redirectToHostingDashboardBackportIfEnabled bug that doesn't account for tabs.
		await this.page.goto( getCalypsoURL( `sites/settings/v2/${ siteSlug }/${ tab }` ), {
			timeout: 20 * 1000,
		} );
	}

	/**
	 * Start the site launch process.
	 */
	async launchSite(): Promise< void > {
		const launchSite = this.page.getByRole( 'button', { name: 'Launch site' } ).first();
		await launchSite.click();
	}

	/**
	 * Navigates to a given item in the sidebar.
	 *
	 * @param {string} item Item to navigate to.
	 */
	async navigateToSubmenu( item: string ) {
		if ( envVariables.VIEWPORT_NAME === 'mobile' ) {
			await this.page.getByRole( 'button', { name: 'General' } ).click();
		}

		await this.page.getByRole( 'link', { name: item } ).click();
	}

	/**
	 * Given text, clicks on a button with matching text.
	 *
	 * @param {string} text Text to search on the button.
	 */
	async clickButton( text: string ) {
		await this.page.getByRole( 'button', { name: text } ).click();
	}
}