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

const selectors = {
	guidedTourContainer: '.guided-tour__popover',
	guidedTourGotItButton: ( locator: Locator ) => locator.getByRole( 'button', { name: 'Got it' } ),
};

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

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

	/**
	 * Visits the `/sites/$siteSlug` endpoint.
	 *
	 * @param {string} siteSlug Site URL.
	 */
	async visit( siteSlug: string ): Promise< void > {
		await this.page.goto( getCalypsoURL( `sites/${ siteSlug }` ), {
			timeout: 20 * 1000,
		} );
	}

	/**
	 * Closes the guided tour if it is visible.
	 */
	async maybeCloseGuidedTour(): Promise< void > {
		const guidedTourContainer = this.page.locator( selectors.guidedTourContainer );

		try {
			await guidedTourContainer.waitFor( {
				timeout: 5 * 1000,
			} );
		} catch ( error ) {
			// The guided tour is not visible.
			return;
		}

		await selectors.guidedTourGotItButton( guidedTourContainer ).click();
	}
}