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

const selectors = {
	// Buttons on navbar
	mySiteButton: '[data-tip-target="my-sites"]',
	mobileMenuButton: '[data-tip-target="mobile-menu"]',
	editorBackButton: '[data-tip-target="back-home"]',
	notificationsButton: 'a[href="/notifications"]',
	meButton: 'a[data-tip-target="me"]',
};
/**
 * Component representing the navbar/masterbar at top of WPCOM.
 */
export class NavbarComponent {
	private page: Page;

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

	/**
	 * Clicks on `My Sites` on the top left of Home dashboard.
	 *
	 * @returns {Promise<void>} No return value.
	 */
	async clickMySites(): Promise< void > {
		await this.page.click( selectors.mySiteButton );
	}

	/**
	 * Clicks on hamburger menu icon in the top left of the masterbar shown only to mobile users of calypso.
	 *
	 * @returns {Promise<void>} No return value.
	 */
	async clickMobileMenu(): Promise< void > {
		await this.page.click( selectors.mobileMenuButton );
	}

	/**
	 * Clicks on `<` back button on the top left of the masterbar shown only to mobile users of the editor.
	 *
	 * @returns {Promise<void>} No return value.
	 */
	async clickEditorBackButton(): Promise< void > {
		await this.page.click( selectors.editorBackButton );
	}

	/**
	 * Click on `Me` on top right of the Home dashboard.
	 */
	async clickMe(): Promise< void > {
		await Promise.all( [ this.page.waitForNavigation(), this.page.click( selectors.meButton ) ] );
	}

	/**
	 * Opens the notification panel.
	 *
	 * Optionally, set the `keyboard` parameter to trigger this action using keyboard shortcut.
	 *
	 * @param {{[key: string]: string}} [param0] Object assembled by the caller.
	 * @param {string} param0.useKeyboard Set to true to use keyboard shortcut to open the notifications panel. Defaults to false.
	 * @returns {Promise<void>} No return value.
	 */
	async openNotificationsPanel( {
		useKeyboard = false,
	}: { useKeyboard?: boolean } = {} ): Promise< void > {
		if ( useKeyboard ) {
			return await this.page.keyboard.type( 'n' );
		}

		const notificationsButtonLocator = this.page.locator( selectors.notificationsButton );

		return await notificationsButtonLocator.click();
	}
}