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

const selectors = {
	// Domain actions
	addDomainButton: '.button:text("Add new domain")',
	searchForDomainButton: 'a:text-matches("search", "i")',
	useADomainIOwnButton: 'text=Use a domain I own',

	// Purchased domains
	purchasedDomains: ( domain: string ) => `div.card:has-text("${ domain }")`,
};

/**
 * Page representing the Upgrades > Domains page.
 */
export class DomainsPage {
	private page: Page;

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

	/* Initiate a domain action */

	/**
	 * Clicks on the button to add a domain to the site.
	 */
	async addDomain(): Promise< void > {
		await Promise.all( [ this.page.click( selectors.addDomainButton ) ] );
	}

	/**
	 * Click initial button to use a domain already owned by the user (make connection or transfer)
	 */
	async useADomainIOwn(): Promise< void > {
		await this.page.click( selectors.useADomainIOwnButton );
	}

	/* Interact with purchased domains */

	/**
	 * Given a partially matching string, locates and clicks on the matching purchased domain card.
	 *
	 * @param {string} domain Domain string to match on.
	 */
	async click( domain: string ): Promise< void > {
		await this.page.click( selectors.purchasedDomains( domain ) );
	}
}