@@ -2,7 +2,7 @@ import { type Locator, type Page, expect } from '@playwright/test'
22
33import { BASE_URL } from '../constants'
44
5- export class ModalPage {
5+ export class InboxPage {
66 private readonly baseURL = BASE_URL
77
88 private readonly connectButton : Locator
@@ -15,6 +15,13 @@ export class ModalPage {
1515 await this . page . goto ( this . baseURL )
1616 }
1717
18+ async gotoDiscoverPage ( ) {
19+ await this . page . locator ( '.Sidebar__Navigation__Link[href="/notifications"]' ) . click ( )
20+ await this . page . getByText ( 'Discover Apps' ) . click ( ) ;
21+
22+ await this . page . getByText ( 'Discover Web3Inbox' ) . isVisible ( ) ;
23+ }
24+
1825 async copyConnectUriToClipboard ( ) {
1926 await this . page . goto ( this . baseURL )
2027 await this . connectButton . click ( )
@@ -40,21 +47,89 @@ export class ModalPage {
4047 await this . page . locator ( '.NotificationPwaModal__close-button' ) . first ( ) . click ( )
4148 }
4249
50+ async getAddress ( ) {
51+ await this . page . locator ( '.Avatar' ) . first ( ) . click ( )
52+ const address = await this . page . locator ( 'wui-avatar' ) . getAttribute ( 'alt' )
53+ await this . page . locator ( 'wui-icon[name=close]' ) . first ( ) . click ( ) ;
54+
55+ return address ;
56+ }
57+
4358 async subscribe ( nth : number ) {
44- await this . page . locator ( '.AppCard__body > .AppCard__body__subscribe' ) . nth ( nth ) . click ( )
45- await this . page . getByText ( 'Subscribed to' , { exact : false } ) . isVisible ( )
59+ const appCard = this . page . locator ( '.AppCard__body' ) . nth ( nth )
60+ await appCard . locator ( '.AppCard__body__subscribe' ) . click ( )
61+
62+ await appCard . locator ( '.AppCard__body__subscribed' ) . getByText ( 'Subscribed' , { exact : false } ) . isVisible ( )
4663 }
4764
48- async unsubscribe ( nth : number ) {
65+ async navigateToNewSubscription ( nth : number ) {
4966 await this . page . getByRole ( 'button' , { name : 'Subscribed' } ) . nth ( nth ) . click ( )
5067 await this . page . getByRole ( 'button' , { name : 'Subscribed' } ) . nth ( nth ) . isHidden ( )
68+ }
69+
70+ async subscribeAndNavigateToDapp ( nth : number ) {
71+ await this . subscribe ( nth ) ;
72+ await this . navigateToNewSubscription ( nth ) ;
73+ }
74+
75+ async unsubscribe ( ) {
5176 await this . page . locator ( '.AppNotificationsHeader__wrapper > .Dropdown' ) . click ( )
5277 await this . page . getByRole ( 'button' , { name : 'Unsubscribe' } ) . click ( )
5378 await this . page . getByRole ( 'button' , { name : 'Unsubscribe' } ) . nth ( 1 ) . click ( )
5479 await this . page . getByText ( 'Unsubscribed from' , { exact : false } ) . isVisible ( )
5580 await this . page . waitForTimeout ( 2000 )
5681 }
5782
83+ async navigateToDappFromSidebar ( nth : number ) {
84+ await this . page . locator ( '.AppSelector__notifications-link' ) . nth ( nth ) . click ( )
85+ }
86+
87+ async countSubscribedDapps ( ) {
88+ const notificationsCount = await this . page . locator ( '.AppSelector__notifications' ) . count ( )
89+
90+ return notificationsCount - 1 ;
91+ }
92+
93+ /**
94+ * Waits for a specific number of dApps to be subscribed.
95+ *
96+ * @param {number } expectedCount - The expected number of dApps to wait for.
97+ * @returns {Promise<void> }
98+ */
99+ async waitForSubscriptions ( expectedCount : number ) : Promise < void > {
100+ // Wait for a function that checks the length of a list or a set of elements
101+ // matching a certain condition to equal the expectedCount.
102+ await this . page . waitForFunction ( ( [ className , count ] ) => {
103+ const elements = document . getElementsByClassName ( className ) [ 1 ] . children ; ;
104+ return elements . length === count ;
105+ } , [ 'AppSelector__list' , expectedCount ] as const , { timeout : 5000 } ) ;
106+ }
107+
108+ async updatePreferences ( ) {
109+ await this . page . locator ( '.AppNotificationsHeader__wrapper > .Dropdown' ) . click ( )
110+ await this . page . getByRole ( 'button' , { name : 'Preferences' } ) . click ( )
111+ // Ensure the modal is visible
112+ await this . page . getByText ( 'Preferences' ) . nth ( 1 ) . isVisible ( )
113+ await this . page . getByText ( 'Preferences' ) . nth ( 1 ) . click ( )
114+
115+ const firstCheckBoxIsChecked = await this . page . isChecked ( '.Toggle__checkbox:nth-of-type(1)' )
116+ await expect ( this . page . locator ( '.Toggle__label' ) . first ( ) ) . toBeVisible ( )
117+
118+ await this . page . locator ( '.Toggle' ) . first ( ) . click ( )
119+
120+ await this . page . getByRole ( 'button' , { name : 'Update' } ) . click ( )
121+
122+
123+ await this . page . locator ( '.AppNotificationsHeader__wrapper > .Dropdown' ) . click ( )
124+ await this . page . getByRole ( 'button' , { name : 'Preferences' } ) . click ( )
125+
126+ const firstCheckBoxIsCheckedAfterUpdating = await this . page . isChecked ( '.Toggle__checkbox:nth-of-type(1)' )
127+
128+ expect ( firstCheckBoxIsChecked ) . not . toEqual ( firstCheckBoxIsCheckedAfterUpdating )
129+
130+ await this . page . locator ( '.PreferencesModal__close' ) . click ( ) ;
131+ }
132+
58133 async cancelSiwe ( ) {
59134 await this . page . getByTestId ( 'w3m-connecting-siwe-cancel' ) . click ( )
60135 }
0 commit comments