diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 4bd4c893..9de9b3ee 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -58,24 +58,34 @@ export class InboxPage { return assertDefined(address) } - public async subscribe(nth: number) { - const appCard = this.page.locator('.AppCard__body').nth(nth) - await appCard.locator('.AppCard__body__subscribe').click() + public async subscribe(appName: string) { + const appCard = this.page.locator('.AppCard', { + has: this.page.locator('.AppCard__body__title', { + hasText: appName + }) + }) + await appCard.locator('.AppCard__body > .AppCard__body__subscribe').click() await appCard - .locator('.AppCard__body__subscribed') + .locator('.AppCard__body > .AppCard__body__subscribed') .getByText('Subscribed', { exact: false }) .isVisible() } - public async navigateToNewSubscription(nth: number) { - await this.page.getByRole('button', { name: 'Subscribed' }).nth(nth).click() - await this.page.getByRole('button', { name: 'Subscribed' }).nth(nth).isHidden() + public async navigateToNewSubscription(appName: string) { + const appCard = this.page.locator('.AppCard', { + has: this.page.locator('.AppCard__body__title', { + hasText: appName + }) + }) + const subscribeButton = appCard.getByRole('button', { name: 'Subscribed' }) + await subscribeButton.click() + await subscribeButton.isHidden() } - public async subscribeAndNavigateToDapp(nth: number) { - await this.subscribe(nth) - await this.navigateToNewSubscription(nth) + async subscribeAndNavigateToDapp(appName: string) { + await this.subscribe(appName) + await this.navigateToNewSubscription(appName) } public async unsubscribe() { @@ -86,8 +96,12 @@ export class InboxPage { await this.page.waitForTimeout(2000) } - public async navigateToDappFromSidebar(nth: number) { - await this.page.locator('.AppSelector__notifications-link').nth(nth).click() + public async navigateToDappFromSidebar(appName: string) { + await this.page + .locator('.AppSelector__notifications-link', { + has: this.page.locator('.AppSelector__link__title', { hasText: appName }) + }) + .click() } public async countSubscribedDapps() { diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index ca9d5bc2..e00af5bb 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -19,6 +19,7 @@ test.afterEach(async ({ inboxValidator, walletValidator }) => { test('it should subscribe and unsubscribe', async ({ inboxPage, walletPage, + settingsPage, walletValidator, browserName }) => { @@ -30,13 +31,19 @@ test('it should subscribe and unsubscribe', async ({ await walletValidator.expectReceivedSign({}) await walletPage.handleRequest({ accept: true }) await inboxPage.rejectNotifications() - await inboxPage.subscribeAndNavigateToDapp(0) + + await settingsPage.goToNotificationSettings() + await settingsPage.displayCustomDapp(CUSTOM_TEST_DAPP.appDomain) + await inboxPage.gotoDiscoverPage() + + await inboxPage.subscribeAndNavigateToDapp(CUSTOM_TEST_DAPP.name) await inboxPage.unsubscribe() }) test('it should subscribe, update preferences and unsubscribe', async ({ inboxPage, walletPage, + settingsPage, walletValidator, browserName }) => { @@ -48,7 +55,12 @@ test('it should subscribe, update preferences and unsubscribe', async ({ await walletValidator.expectReceivedSign({}) await walletPage.handleRequest({ accept: true }) await inboxPage.rejectNotifications() - await inboxPage.subscribeAndNavigateToDapp(0) + + await settingsPage.goToNotificationSettings() + await settingsPage.displayCustomDapp(CUSTOM_TEST_DAPP.appDomain) + await inboxPage.gotoDiscoverPage() + + await inboxPage.subscribeAndNavigateToDapp(CUSTOM_TEST_DAPP.name) await inboxPage.updatePreferences() await inboxPage.unsubscribe() }) @@ -56,6 +68,7 @@ test('it should subscribe, update preferences and unsubscribe', async ({ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ inboxPage, walletPage, + settingsPage, walletValidator, browserName }) => { @@ -67,8 +80,13 @@ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ await walletValidator.expectReceivedSign({}) await walletPage.handleRequest({ accept: true }) await inboxPage.rejectNotifications() - await inboxPage.subscribe(0) - await inboxPage.subscribe(1) + + await settingsPage.goToNotificationSettings() + await settingsPage.displayCustomDapp(CUSTOM_TEST_DAPP.appDomain) + await inboxPage.gotoDiscoverPage() + + await inboxPage.subscribe(CUSTOM_TEST_DAPP.name) + await inboxPage.subscribe('GM Dapp') await inboxPage.waitForSubscriptions(2) @@ -82,7 +100,7 @@ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ expect(await inboxPage.countSubscribedDapps()).toEqual(2) - await inboxPage.navigateToDappFromSidebar(0) + await inboxPage.navigateToDappFromSidebar(CUSTOM_TEST_DAPP.name) await inboxPage.unsubscribe() expect(await inboxPage.countSubscribedDapps()).toEqual(1) @@ -90,7 +108,7 @@ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ * Select 0 again since we unsubscribed from the second dapp * so there is only one item */ - await inboxPage.navigateToDappFromSidebar(0) + await inboxPage.navigateToDappFromSidebar('GM Dapp') await inboxPage.unsubscribe() }) @@ -120,12 +138,8 @@ test('it should subscribe, receive messages and unsubscribe', async ({ await inboxPage.page.getByText('Notify Swift', { exact: false }).waitFor({ state: 'visible' }) expect(await inboxPage.page.getByText('Notify Swift', { exact: false }).isVisible()).toEqual(true) - - await inboxPage.subscribeAndNavigateToDapp(0) - - if (!CUSTOM_TEST_DAPP.projectId || !CUSTOM_TEST_DAPP.projectSecret) { - throw new Error('TEST_DAPP_SECRET and TEST_DAPP_ID are required') - } + + await inboxPage.subscribeAndNavigateToDapp(CUSTOM_TEST_DAPP.name) const address = await inboxPage.getAddress()