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

/**
 * Component representing the notifications panel and notifications themselves.
 */
export class NotificationsComponent {
	private page: Page;
	private anchor: Locator;

	/**
	 * Constructs an instance of the component.
	 *
	 * @param {Page} page The underlying page.
	 */
	constructor( page: Page ) {
		this.page = page;
		// There is no accessible locator for this panel.
		this.anchor = page.locator( 'div[id=wpnc-panel]' );
	}

	/**
	 * Given a string of text, locate and click on the notification containing the text.
	 *
	 * @param {string} text Text contained in the notification.
	 * @returns {Promise<void>} No return value.
	 */
	async openNotification( text: string ): Promise< void > {
		await this.anchor.getByText( text ).click();
	}

	/**
	 * Given a string of text, click on the button in expanded single notification view to execute the action.
	 *
	 * eg. 'Trash' -> Clicks on the 'Trash' button when viewing a single notification.
	 *
	 * @param {string} action Action to perform on the notification.
	 */
	async clickNotificationAction( action: string ): Promise< void > {
		await this.anchor
			.getByRole( 'list' )
			.getByRole( 'button' )
			.filter( { hasText: action } )
			.click();
	}

	/**
	 * Clicks the undo link to undo the previous action.
	 */
	async clickUndo(): Promise< void > {
		await this.anchor.getByRole( 'button', { name: 'Undo', exact: true } ).click();
		await this.anchor.getByText( 'Comment trashed' ).waitFor( { state: 'detached' } );
	}
}