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

const selectors = {
	// Common selectors
	button: ( text: string ) => `button:text-is("${ text }")`,

	// Inputs
	siteTitleInput: ( title: string ) => `input#blogname[value="${ title }"]`,
	siteTaglineInput: ( tagline: string ) => `input#blogdescription[value="${ tagline }"]`,

	// Launch site
	launchSiteButton: 'a:text("Launch site")',

	// Site Tools
	deleteSiteLinkItem: 'p:text-is("Delete your site permanently")',
	deleteSiteConfirmInput: 'input[id="confirmDomainChangeInput"]',
	deleteSiteConfirmationSpan: 'span:has-text("is being deleted")',
};

/**
 * Represents the Settings > General Settings page.
 */
export class GeneralSettingsPage {
	private page: Page;

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

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

	/**
	 * Start the site launch process.
	 */
	async launchSite(): Promise< void > {
		await Promise.all( [
			this.page.waitForNavigation(),
			this.page.click( selectors.launchSiteButton ),
		] );
	}

	/**
	 * Performs steps related to site deletion.
	 *
	 * @param {string} url URL of the site to be deleted.
	 */
	async deleteSite( url: string ): Promise< void > {
		await this.page.click( selectors.deleteSiteLinkItem );
		await this.page.click( selectors.button( 'Delete site' ) );
		await this.page.fill( selectors.deleteSiteConfirmInput, url );

		// Once the confirmation button is clicked these things happen in short order:
		//	- site deletion confirmation toast is shown.
		//	- navigation to a new page, entering state where no site is selected.
		await Promise.all( [
			this.page.waitForNavigation(),
			this.page.waitForSelector( selectors.deleteSiteConfirmationSpan ),
			this.page.click( selectors.button( 'Delete this site' ) ),
		] );
	}

	/**
	 * Validates the provided value is in the Site title input field
	 *
	 * @param {string} title Expected Site title
	 */
	async validateSiteTitle( title: string ): Promise< void > {
		// Because of React state handling, we must wait for the expected input value rather than find the input and return its value.
		// This input is empty when first rendered, then updated with the state. Playwright can outpace React!
		await this.page.waitForSelector( selectors.siteTitleInput( title ) );
	}

	/**
	 * Validates the provided value is in the Site tagline input field
	 *
	 * @param {string} tagline Expected Site tagline
	 */
	async validateSiteTagline( tagline: string ): Promise< void > {
		// Because of React state handling, we must wait for the expected input value rather than find the input and return its value.
		// This input is empty when first rendered, then updated with the state. Playwright can outpace React!
		await this.page.waitForSelector( selectors.siteTaglineInput( tagline ) );
	}
}