From 0e2267c56dd83ca59bdbba84bb835d6ae06e8fc3 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Mon, 26 Feb 2024 15:54:47 +0100 Subject: [PATCH 01/20] chore: rename modalPage as it is not a modalPage --- tests/shared/fixtures/fixture.ts | 10 +++++----- tests/shared/pages/InboxPage.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/shared/fixtures/fixture.ts b/tests/shared/fixtures/fixture.ts index 08f28131..1d6611cf 100644 --- a/tests/shared/fixtures/fixture.ts +++ b/tests/shared/fixtures/fixture.ts @@ -1,22 +1,22 @@ import { test as base } from '@playwright/test' -import { ModalPage } from '../pages/InboxPage' +import { InboxPage } from '../pages/InboxPage' import { ModalValidator } from '../validators/ModalValidator' // Declare the types of fixtures to use export interface ModalFixture { - modalPage: ModalPage - modalValidator: ModalValidator + inboxPage: InboxPage + inboxValidator: ModalValidator library: string } export const test = base.extend({ - modalPage: async ({ page }, use) => { + inboxPage: async ({ page }, use) => { const modalPage = new ModalPage(page) await modalPage.load() await use(modalPage) }, - modalValidator: async ({ modalPage }, use) => { + inboxValidator: async ({ modalPage }, use) => { const modalValidator = new ModalValidator(modalPage.page) await use(modalValidator) } diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index fbff74f3..571a0f46 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -2,7 +2,7 @@ import { type Locator, type Page, expect } from '@playwright/test' import { BASE_URL } from '../constants' -export class ModalPage { +export class InboxPage { private readonly baseURL = BASE_URL private readonly connectButton: Locator From aafbb5499f97d1b766cd93dad5d3a17fbf5da985 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 14:23:56 +0100 Subject: [PATCH 02/20] test: add updatePreferences test --- tests/shared/fixtures/fixture.ts | 14 ++++----- tests/shared/pages/InboxPage.ts | 37 ++++++++++++++++++++++- tests/shared/validators/ModalValidator.ts | 2 +- tests/subscribe.spec.ts | 37 +++++++++++++++++------ 4 files changed, 72 insertions(+), 18 deletions(-) diff --git a/tests/shared/fixtures/fixture.ts b/tests/shared/fixtures/fixture.ts index 1d6611cf..304ee498 100644 --- a/tests/shared/fixtures/fixture.ts +++ b/tests/shared/fixtures/fixture.ts @@ -1,23 +1,23 @@ import { test as base } from '@playwright/test' import { InboxPage } from '../pages/InboxPage' -import { ModalValidator } from '../validators/ModalValidator' +import { InboxValidator } from '../validators/ModalValidator' // Declare the types of fixtures to use export interface ModalFixture { inboxPage: InboxPage - inboxValidator: ModalValidator + inboxValidator: InboxValidator library: string } export const test = base.extend({ inboxPage: async ({ page }, use) => { - const modalPage = new ModalPage(page) - await modalPage.load() - await use(modalPage) + const inboxPage = new InboxPage(page) + await inboxPage.load() + await use(inboxPage) }, - inboxValidator: async ({ modalPage }, use) => { - const modalValidator = new ModalValidator(modalPage.page) + inboxValidator: async ({ inboxPage }, use) => { + const modalValidator = new InboxValidator(inboxPage.page) await use(modalValidator) } }) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 571a0f46..9ab7792c 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -45,9 +45,17 @@ export class InboxPage { await this.page.getByText('Subscribed to', { exact: false }).isVisible() } - async unsubscribe(nth: number) { + async navigateToNewSubscription(nth: number) { await this.page.getByRole('button', { name: 'Subscribed' }).nth(nth).click() await this.page.getByRole('button', { name: 'Subscribed' }).nth(nth).isHidden() + } + + async subscribeAndNavigateToDapp(nth: number) { + await this.subscribe(nth); + await this.navigateToNewSubscription(nth); + } + + async unsubscribe() { await this.page.locator('.AppNotificationsHeader__wrapper > .Dropdown').click() await this.page.getByRole('button', { name: 'Unsubscribe' }).click() await this.page.getByRole('button', { name: 'Unsubscribe' }).nth(1).click() @@ -55,6 +63,33 @@ export class InboxPage { await this.page.waitForTimeout(2000) } + async updatePreferences() { + await this.page.locator('.AppNotificationsHeader__wrapper > .Dropdown').click() + await this.page.getByRole('button', { name: 'Preferences' }).click() + // Ensure the modal is visible + await this.page.getByText('Preferences').nth(1).isVisible() + await this.page.getByText('Preferences').nth(1).click() + + const firstCheckBoxIsChecked = await this.page.isChecked('.Toggle__checkbox:nth-of-type(1)') + console.log({firstCheckBoxIsChecked}) + await expect(this.page.locator('.Toggle__label').first()).toBeVisible() + + await this.page.locator('.Toggle').first().click() + + await this.page.getByRole('button', { name: 'Update' }).click() + + + await this.page.locator('.AppNotificationsHeader__wrapper > .Dropdown').click() + await this.page.getByRole('button', { name: 'Preferences' }).click() + + const firstCheckBoxIsCheckedAfterUpdating = await this.page.isChecked('.Toggle__checkbox:nth-of-type(1)') + + expect(firstCheckBoxIsChecked).not.toEqual(firstCheckBoxIsCheckedAfterUpdating) + + await this.page.locator('.PreferencesModal__close').click(); + + } + async cancelSiwe() { await this.page.getByTestId('w3m-connecting-siwe-cancel').click() } diff --git a/tests/shared/validators/ModalValidator.ts b/tests/shared/validators/ModalValidator.ts index 6405b8bc..b043219d 100644 --- a/tests/shared/validators/ModalValidator.ts +++ b/tests/shared/validators/ModalValidator.ts @@ -1,7 +1,7 @@ import { expect } from '@playwright/test' import type { Page } from '@playwright/test' -export class ModalValidator { +export class InboxValidator { constructor(public readonly page: Page) {} async expectConnected() { diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index aa792158..0dae68cd 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -1,23 +1,23 @@ import { DEFAULT_SESSION_PARAMS } from './shared/constants' import { testWallet as test } from './shared/fixtures/wallet-fixture' -test.beforeEach(async ({ modalPage, walletPage, browserName }) => { +test.beforeEach(async ({ inboxPage, walletPage, browserName }) => { if (browserName === 'webkit') { // Clipboard doesn't work here. Remove this when we moved away from Clipboard in favor of links test.skip() } - await modalPage.copyConnectUriToClipboard() + await inboxPage.copyConnectUriToClipboard() await walletPage.connect() await walletPage.handleSessionProposal(DEFAULT_SESSION_PARAMS) }) -test.afterEach(async ({ modalValidator, walletValidator }) => { - await modalValidator.expectDisconnected() +test.afterEach(async ({ inboxValidator, walletValidator }) => { + await inboxValidator.expectDisconnected() await walletValidator.expectDisconnected() }) test('it should subscribe and unsubscribe', async ({ - modalPage, + inboxPage, walletPage, walletValidator, browserName @@ -26,10 +26,29 @@ test('it should subscribe and unsubscribe', async ({ // Clipboard doesn't work here. Remove this when we moved away from Clipboard in favor of links test.skip() } - await modalPage.promptSiwe() + await inboxPage.promptSiwe() await walletValidator.expectReceivedSign({}) await walletPage.handleRequest({ accept: true }) - await modalPage.rejectNotifications() - await modalPage.subscribe(0) - await modalPage.unsubscribe(0) + await inboxPage.rejectNotifications() + await inboxPage.subscribeAndNavigateToDapp(0) + await inboxPage.unsubscribe() +}) + +test('it should subscribe, update preferences and unsubscribe', async ({ + inboxPage, + walletPage, + walletValidator, + browserName +}) => { + if (browserName === 'webkit') { + // Clipboard doesn't work here. Remove this when we moved away from Clipboard in favor of links + test.skip() + } + await inboxPage.promptSiwe() + await walletValidator.expectReceivedSign({}) + await walletPage.handleRequest({ accept: true }) + await inboxPage.rejectNotifications() + await inboxPage.subscribeAndNavigateToDapp(0) + await inboxPage.updatePreferences() + await inboxPage.unsubscribe() }) From f5ee66c4deee98a43e56be1e406b046ad1496eec Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 16:31:42 +0100 Subject: [PATCH 03/20] chore: count subscribed dapps --- tests/shared/pages/InboxPage.ts | 22 ++++++++++++++++++++-- tests/subscribe.spec.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 9ab7792c..1bedc16b 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -41,8 +41,15 @@ export class InboxPage { } async subscribe(nth: number) { - await this.page.locator('.AppCard__body > .AppCard__body__subscribe').nth(nth).click() - await this.page.getByText('Subscribed to', { exact: false }).isVisible() + const appCard = this.page.locator('.AppCard__body').nth(nth) + await appCard.locator('.AppCard__body__subscribe').click() + + console.log({appCardText: await appCard.innerText()}) + + await appCard.locator('.AppCard__body__subscribed').getByText('Subscribed', { exact: false }).isVisible() + + await this.page.waitForTimeout(3000); + } async navigateToNewSubscription(nth: number) { @@ -63,6 +70,17 @@ export class InboxPage { await this.page.waitForTimeout(2000) } + async navigateToDappFromSidebar(nth: number) { + await this.page.locator('.AppSelector__notifications-link').nth(nth).click() + } + + async countSubscribedDapps() { + + const selected = await this.page.locator('AppSelector__list').all() + console.log({selected}) + return (await this.page.locator('.AppSelector__notifications').count() - 1) + } + async updatePreferences() { await this.page.locator('.AppNotificationsHeader__wrapper > .Dropdown').click() await this.page.getByRole('button', { name: 'Preferences' }).click() diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index 0dae68cd..82892207 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -1,5 +1,5 @@ import { DEFAULT_SESSION_PARAMS } from './shared/constants' -import { testWallet as test } from './shared/fixtures/wallet-fixture' +import { expect, testWallet as test } from './shared/fixtures/wallet-fixture' test.beforeEach(async ({ inboxPage, walletPage, browserName }) => { if (browserName === 'webkit') { @@ -52,3 +52,31 @@ test('it should subscribe, update preferences and unsubscribe', async ({ await inboxPage.updatePreferences() await inboxPage.unsubscribe() }) + +test('it should subscribe and unsubscribe to and from multiple dapps', async ({ + inboxPage, + walletPage, + walletValidator, + browserName +}) => { + if (browserName === 'webkit') { + // Clipboard doesn't work here. Remove this when we moved away from Clipboard in favor of links + test.skip() + } + await inboxPage.promptSiwe() + await walletValidator.expectReceivedSign({}) + await walletPage.handleRequest({ accept: true }) + await inboxPage.rejectNotifications() + await inboxPage.subscribe(0) + await inboxPage.subscribe(1) + expect(await inboxPage.countSubscribedDapps()).toEqual(2); + + await inboxPage.navigateToDappFromSidebar(0); + await inboxPage.unsubscribe() + expect(await inboxPage.countSubscribedDapps()).toEqual(1); + + // select 0 again since we unsubscribed from the second dapp + // so there is only one item + await inboxPage.navigateToDappFromSidebar(0); + await inboxPage.unsubscribe() +}) From 873843643ff8785f4fcc228228f87b629d5fb928 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 20:02:33 +0100 Subject: [PATCH 04/20] test: add message test --- tests/shared/constants/index.ts | 10 ++++++ tests/shared/fixtures/fixture.ts | 16 ++++++++- tests/shared/helpers/notifyServer.ts | 46 +++++++++++++++++++++++++ tests/shared/pages/InboxPage.ts | 17 ++++++++-- tests/shared/pages/SettingsPage.ts | 23 +++++++++++++ tests/subscribe.spec.ts | 51 +++++++++++++++++++++++++++- 6 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 tests/shared/helpers/notifyServer.ts create mode 100644 tests/shared/pages/SettingsPage.ts diff --git a/tests/shared/constants/index.ts b/tests/shared/constants/index.ts index 27c19328..606051f4 100644 --- a/tests/shared/constants/index.ts +++ b/tests/shared/constants/index.ts @@ -8,3 +8,13 @@ export const DEFAULT_SESSION_PARAMS: SessionParams = { optAccounts: ['1', '2'], accept: true } + +export const CUSTOM_TEST_DAPP = { + description: "Test description", + icons: ["https://i.imgur.com/q9QDRXc.png"], + name: "Notify Swift Integration Tests Prod", + appDomain: "wc-notify-swift-integration-tests-prod.pages.dev", + projectSecret: process.env['TEST_DAPP_SECRET'], + projectId: process.env['TEST_DAPP_ID'], + messageType: "f173f231-a45c-4dc0-aa5d-956eb04f7360" +} as const; diff --git a/tests/shared/fixtures/fixture.ts b/tests/shared/fixtures/fixture.ts index 304ee498..9fd3c270 100644 --- a/tests/shared/fixtures/fixture.ts +++ b/tests/shared/fixtures/fixture.ts @@ -2,11 +2,15 @@ import { test as base } from '@playwright/test' import { InboxPage } from '../pages/InboxPage' import { InboxValidator } from '../validators/ModalValidator' +import { SettingsPage } from '../pages/SettingsPage' +import { NotifyServer } from '../helpers/notifyServer' // Declare the types of fixtures to use export interface ModalFixture { inboxPage: InboxPage inboxValidator: InboxValidator + settingsPage: SettingsPage + notifyServer: NotifyServer library: string } @@ -19,6 +23,16 @@ export const test = base.extend({ inboxValidator: async ({ inboxPage }, use) => { const modalValidator = new InboxValidator(inboxPage.page) await use(modalValidator) - } + }, + // Have to pass same page object to maintain state between pages + settingsPage: async({ inboxPage }, use) => { + const settingsPage = new SettingsPage(inboxPage.page) + settingsPage.load() + use(settingsPage) + }, + notifyServer: async(_, use) => { + const notifyServer = new NotifyServer(); + use(notifyServer) + }, }) export { expect } from '@playwright/test' diff --git a/tests/shared/helpers/notifyServer.ts b/tests/shared/helpers/notifyServer.ts new file mode 100644 index 00000000..b19cda9e --- /dev/null +++ b/tests/shared/helpers/notifyServer.ts @@ -0,0 +1,46 @@ +export class NotifyServer { + private notifyBaseUrl = "https://notify.walletconnect.com" + + public async sendMessage({ + projectId, + projectSecret, + accounts, + url, + title, + body, + icon, + type + }: { + projectId: string, + projectSecret: string, + accounts: string[] + title: string, + body: string, + icon: string, + url: string + type: string + }) { + const request = JSON.stringify({ + accounts, + notification: { + title, + body, + icon, + url, + type + } + }) + + const fetchUrl = `${this.notifyBaseUrl}/${projectId}/notify` + + const headers = new Headers({ + Authorization: `Bearer ${projectSecret}`, + "Content-Type": "application/json" + }) + + await fetch(fetchUrl, { + headers, + body: request, + }) + } +} diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 1bedc16b..438b2edd 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -12,7 +12,11 @@ export class InboxPage { } async load() { - await this.page.goto(this.baseURL) + await this.page.goto(`${this.baseURL}`) + } + + async gotoDiscoverPage() { + await this.page.goto(`${this.baseURL}notifications/new-app`) } async copyConnectUriToClipboard() { @@ -40,6 +44,15 @@ export class InboxPage { await this.page.locator('.NotificationPwaModal__close-button').first().click() } + async getAddress() { + await this.page.locator('.Avatar').click() + await this.page.locator('wui-icon[name=copy]').first().click(); + const copiedAddress: string = this.page.evaluate('navigator.clipboard.readText()') as any + await this.page.locator('wui-icon[name=close]').first().click(); + + return copiedAddress; + } + async subscribe(nth: number) { const appCard = this.page.locator('.AppCard__body').nth(nth) await appCard.locator('.AppCard__body__subscribe').click() @@ -49,7 +62,6 @@ export class InboxPage { await appCard.locator('.AppCard__body__subscribed').getByText('Subscribed', { exact: false }).isVisible() await this.page.waitForTimeout(3000); - } async navigateToNewSubscription(nth: number) { @@ -105,7 +117,6 @@ export class InboxPage { expect(firstCheckBoxIsChecked).not.toEqual(firstCheckBoxIsCheckedAfterUpdating) await this.page.locator('.PreferencesModal__close').click(); - } async cancelSiwe() { diff --git a/tests/shared/pages/SettingsPage.ts b/tests/shared/pages/SettingsPage.ts new file mode 100644 index 00000000..fa3236a2 --- /dev/null +++ b/tests/shared/pages/SettingsPage.ts @@ -0,0 +1,23 @@ +import { type Locator, type Page, expect } from '@playwright/test' + +import { BASE_URL } from '../../shared/constants' + +export class SettingsPage { + private readonly baseURL = BASE_URL + + constructor(public readonly page: Page) {} + + async load() { + await this.page.goto(`${this.baseURL}`) + } + + async goToNotificationSettings() { + await this.page.goto(`${this.baseURL}settings/notifications`) + } + + async displayCustomDapp(dappUrl: string) { + await this.page.getByPlaceholder('app.example.com').fill(dappUrl) + await this.page.getByRole('button', { name: "Save", exact: true}).click() + } + +} diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index 82892207..3f14a153 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -1,4 +1,4 @@ -import { DEFAULT_SESSION_PARAMS } from './shared/constants' +import { CUSTOM_TEST_DAPP, DEFAULT_SESSION_PARAMS } from './shared/constants' import { expect, testWallet as test } from './shared/fixtures/wallet-fixture' test.beforeEach(async ({ inboxPage, walletPage, browserName }) => { @@ -80,3 +80,52 @@ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ await inboxPage.navigateToDappFromSidebar(0); await inboxPage.unsubscribe() }) + + +test('it should subscribe, recieve messages and unsubscribe', async ({ + inboxPage, + walletPage, + settingsPage, + walletValidator, + browserName, + notifyServer +}) => { + if (browserName === 'webkit') { + // Clipboard doesn't work here. Remove this when we moved away from Clipboard in favor of links + test.skip() + } + await inboxPage.promptSiwe() + await walletValidator.expectReceivedSign({}) + await walletPage.handleRequest({ accept: true }) + await inboxPage.rejectNotifications() + + await settingsPage.goToNotificationSettings() + await settingsPage.displayCustomDapp(CUSTOM_TEST_DAPP.appDomain) + + await inboxPage.gotoDiscoverPage() + + // Ensure the custom dapp is the one subscribed to + expect(await inboxPage.page.getByText(CUSTOM_TEST_DAPP.appDomain).isVisible()).toEqual(true) + + await inboxPage.subscribe(0) + + if(!CUSTOM_TEST_DAPP.projectId || !(CUSTOM_TEST_DAPP.projectSecret)) { + throw new Error("TEST_DAPP_SECRET and TEST_DAPP_ID are required") + } + + const address = await inboxPage.getAddress() + + await notifyServer.sendMessage({ + accounts: [address], + body: "Test Body", + title: "Test Title", + type: CUSTOM_TEST_DAPP.messageType, + url: CUSTOM_TEST_DAPP.appDomain, + icon: CUSTOM_TEST_DAPP.icons[0], + projectId: CUSTOM_TEST_DAPP.projectId, + projectSecret: CUSTOM_TEST_DAPP.projectSecret, + }) + + expect(await inboxPage.page.getByText("Test Body").isVisible()).toEqual(true) + +}) From f919317b9306785049ee0d69df3f6592d8b8cbac Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 21:40:08 +0100 Subject: [PATCH 05/20] chore: fix bugs in tests --- tests/shared/fixtures/fixture.ts | 2 +- tests/shared/helpers/notifyServer.ts | 20 ++++++++++++++++++-- tests/shared/pages/InboxPage.ts | 7 +++++-- tests/shared/pages/SettingsPage.ts | 6 ++---- tests/subscribe.spec.ts | 12 ++++++++---- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/tests/shared/fixtures/fixture.ts b/tests/shared/fixtures/fixture.ts index 9fd3c270..837cc8b1 100644 --- a/tests/shared/fixtures/fixture.ts +++ b/tests/shared/fixtures/fixture.ts @@ -30,7 +30,7 @@ export const test = base.extend({ settingsPage.load() use(settingsPage) }, - notifyServer: async(_, use) => { + notifyServer: async({}, use) => { const notifyServer = new NotifyServer(); use(notifyServer) }, diff --git a/tests/shared/helpers/notifyServer.ts b/tests/shared/helpers/notifyServer.ts index b19cda9e..c5e48184 100644 --- a/tests/shared/helpers/notifyServer.ts +++ b/tests/shared/helpers/notifyServer.ts @@ -1,3 +1,5 @@ +import { expect } from "@playwright/test" + export class NotifyServer { private notifyBaseUrl = "https://notify.walletconnect.com" @@ -34,13 +36,27 @@ export class NotifyServer { const fetchUrl = `${this.notifyBaseUrl}/${projectId}/notify` const headers = new Headers({ + Authorization: `Bearer ${projectSecret}`, "Content-Type": "application/json" + }) - await fetch(fetchUrl, { + const stream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode(request)); + controller.close(); // Close the stream after enqueueing the data + } + }) + + const fetchResults = await fetch(fetchUrl, { + method: "POST", headers, - body: request, + body: stream, }) + + console.log(">>>> FETCH", await fetchResults.text(), fetchResults.status) + + expect(fetchResults.status).toEqual(200) } } diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 438b2edd..6769ea07 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -16,7 +16,10 @@ export class InboxPage { } async gotoDiscoverPage() { - await this.page.goto(`${this.baseURL}notifications/new-app`) + await this.page.locator('.Sidebar__Navigation__Link[href="/notifications"]').click() + await this.page.getByText('Discover Apps').click(); + + await this.page.getByText('Discover Web3Inbox').isVisible(); } async copyConnectUriToClipboard() { @@ -45,7 +48,7 @@ export class InboxPage { } async getAddress() { - await this.page.locator('.Avatar').click() + await this.page.locator('.Avatar').first().click() await this.page.locator('wui-icon[name=copy]').first().click(); const copiedAddress: string = this.page.evaluate('navigator.clipboard.readText()') as any await this.page.locator('wui-icon[name=close]').first().click(); diff --git a/tests/shared/pages/SettingsPage.ts b/tests/shared/pages/SettingsPage.ts index fa3236a2..cbb46e70 100644 --- a/tests/shared/pages/SettingsPage.ts +++ b/tests/shared/pages/SettingsPage.ts @@ -7,12 +7,10 @@ export class SettingsPage { constructor(public readonly page: Page) {} - async load() { - await this.page.goto(`${this.baseURL}`) - } + async load() {} async goToNotificationSettings() { - await this.page.goto(`${this.baseURL}settings/notifications`) + await this.page.locator('.Sidebar__Navigation__Link[href="/settings"]').click() } async displayCustomDapp(dappUrl: string) { diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index 3f14a153..2a9dd3c7 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -98,6 +98,7 @@ test('it should subscribe, recieve messages and unsubscribe', async ({ await walletValidator.expectReceivedSign({}) await walletPage.handleRequest({ accept: true }) await inboxPage.rejectNotifications() + await inboxPage.subscribe(0) await settingsPage.goToNotificationSettings() await settingsPage.displayCustomDapp(CUSTOM_TEST_DAPP.appDomain) @@ -105,9 +106,11 @@ test('it should subscribe, recieve messages and unsubscribe', async ({ await inboxPage.gotoDiscoverPage() // Ensure the custom dapp is the one subscribed to - expect(await inboxPage.page.getByText(CUSTOM_TEST_DAPP.appDomain).isVisible()).toEqual(true) + await inboxPage.page.getByText("Notify Swift", {exact: false}).waitFor({ state: 'visible' }) - await inboxPage.subscribe(0) + 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") @@ -116,7 +119,7 @@ test('it should subscribe, recieve messages and unsubscribe', async ({ const address = await inboxPage.getAddress() await notifyServer.sendMessage({ - accounts: [address], + accounts: [`eip155:1:${address}`], body: "Test Body", title: "Test Title", type: CUSTOM_TEST_DAPP.messageType, @@ -126,6 +129,7 @@ test('it should subscribe, recieve messages and unsubscribe', async ({ projectSecret: CUSTOM_TEST_DAPP.projectSecret, }) - expect(await inboxPage.page.getByText("Test Body").isVisible()).toEqual(true) + await inboxPage.page.getByText("Test Body").waitFor({state: 'visible'}) + expect(await inboxPage.page.getByText("Test Body").isVisible()).toEqual(true) }) From 20c742bf814a18bed16893a21485612384534225 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 21:47:05 +0100 Subject: [PATCH 06/20] chore: expose env in workflow --- .github/workflows/ui_test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ui_test.yml b/.github/workflows/ui_test.yml index da8f8501..ab899df5 100644 --- a/.github/workflows/ui_test.yml +++ b/.github/workflows/ui_test.yml @@ -29,6 +29,8 @@ jobs: env: VITE_PROJECT_ID: ${{ secrets.VITE_DEV_PROJECT_ID }} VITE_EXPLORER_API_URL: ${{ secrets.VITE_EXPLORER_API_URL }} + TEST_DAPP_ID: ${{ secrets.TEST_DAPP_ID }} + TEST_DAPP_SECRET: ${{ secrets.TEST_DAPP_SECRET }} VITE_CI: true - uses: actions/upload-artifact@v3 if: always() From 219f74f599d52f58038b8c3c8a9990fb7c30afac Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 22:05:25 +0100 Subject: [PATCH 07/20] chore: pass duplex option for webkit --- tests/shared/helpers/notifyServer.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/shared/helpers/notifyServer.ts b/tests/shared/helpers/notifyServer.ts index c5e48184..ec123d13 100644 --- a/tests/shared/helpers/notifyServer.ts +++ b/tests/shared/helpers/notifyServer.ts @@ -52,6 +52,8 @@ export class NotifyServer { const fetchResults = await fetch(fetchUrl, { method: "POST", headers, + // @ts-ignore + duplex: true, body: stream, }) From 93f0b43ca0461b71d39135165bb4c4ae7e6c8504 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 23:21:28 +0100 Subject: [PATCH 08/20] Update tests/shared/helpers/notifyServer.ts Co-authored-by: Ben Kremer --- tests/shared/helpers/notifyServer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/shared/helpers/notifyServer.ts b/tests/shared/helpers/notifyServer.ts index ec123d13..fe8f02aa 100644 --- a/tests/shared/helpers/notifyServer.ts +++ b/tests/shared/helpers/notifyServer.ts @@ -36,7 +36,6 @@ export class NotifyServer { const fetchUrl = `${this.notifyBaseUrl}/${projectId}/notify` const headers = new Headers({ - Authorization: `Bearer ${projectSecret}`, "Content-Type": "application/json" From a8b9ed3f60aef8f313e02795c4e9f875f33e8f17 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 23:23:11 +0100 Subject: [PATCH 09/20] Apply suggestions from code review Co-authored-by: Chris Smith <1979423+chris13524@users.noreply.github.com> Co-authored-by: Ben Kremer --- .github/workflows/ui_test.yml | 4 ++-- tests/shared/helpers/notifyServer.ts | 1 - tests/subscribe.spec.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ui_test.yml b/.github/workflows/ui_test.yml index ab899df5..c5541366 100644 --- a/.github/workflows/ui_test.yml +++ b/.github/workflows/ui_test.yml @@ -29,8 +29,8 @@ jobs: env: VITE_PROJECT_ID: ${{ secrets.VITE_DEV_PROJECT_ID }} VITE_EXPLORER_API_URL: ${{ secrets.VITE_EXPLORER_API_URL }} - TEST_DAPP_ID: ${{ secrets.TEST_DAPP_ID }} - TEST_DAPP_SECRET: ${{ secrets.TEST_DAPP_SECRET }} + TEST_DAPP_PROJECT_ID: ${{ secrets.TEST_DAPP_PROJECT_ID }} + TEST_DAPP_PROJECT_SECRET: ${{ secrets.TEST_DAPP_PROJECT_SECRET }} VITE_CI: true - uses: actions/upload-artifact@v3 if: always() diff --git a/tests/shared/helpers/notifyServer.ts b/tests/shared/helpers/notifyServer.ts index fe8f02aa..3f5cf12b 100644 --- a/tests/shared/helpers/notifyServer.ts +++ b/tests/shared/helpers/notifyServer.ts @@ -38,7 +38,6 @@ export class NotifyServer { const headers = new Headers({ Authorization: `Bearer ${projectSecret}`, "Content-Type": "application/json" - }) const stream = new ReadableStream({ diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index 2a9dd3c7..95426067 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -82,7 +82,7 @@ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ }) -test('it should subscribe, recieve messages and unsubscribe', async ({ +test('it should subscribe, receive messages and unsubscribe', async ({ inboxPage, walletPage, settingsPage, From 899ce34e2262f26ef828d676f1f6ff19c567b59b Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 23:23:52 +0100 Subject: [PATCH 10/20] chore: update env vars --- tests/shared/constants/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/shared/constants/index.ts b/tests/shared/constants/index.ts index 606051f4..97179939 100644 --- a/tests/shared/constants/index.ts +++ b/tests/shared/constants/index.ts @@ -14,7 +14,7 @@ export const CUSTOM_TEST_DAPP = { icons: ["https://i.imgur.com/q9QDRXc.png"], name: "Notify Swift Integration Tests Prod", appDomain: "wc-notify-swift-integration-tests-prod.pages.dev", - projectSecret: process.env['TEST_DAPP_SECRET'], - projectId: process.env['TEST_DAPP_ID'], + projectSecret: process.env['TEST_DAPP_PROJECT_SECRET'], + projectId: process.env['TEST_DAPP_PROJECT_ID'], messageType: "f173f231-a45c-4dc0-aa5d-956eb04f7360" } as const; From 502308125ca8be75c562c8d48743ecafa3543a80 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Tue, 27 Feb 2024 23:49:40 +0100 Subject: [PATCH 11/20] chore: remove need for clipboard, and stream in fetch --- tests/shared/helpers/notifyServer.ts | 13 +------------ tests/shared/pages/InboxPage.ts | 5 ++--- tests/shared/pages/WalletPage.ts | 2 ++ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/shared/helpers/notifyServer.ts b/tests/shared/helpers/notifyServer.ts index 3f5cf12b..81fb5ff5 100644 --- a/tests/shared/helpers/notifyServer.ts +++ b/tests/shared/helpers/notifyServer.ts @@ -40,23 +40,12 @@ export class NotifyServer { "Content-Type": "application/json" }) - const stream = new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode(request)); - controller.close(); // Close the stream after enqueueing the data - } - }) - const fetchResults = await fetch(fetchUrl, { method: "POST", headers, - // @ts-ignore - duplex: true, - body: stream, + body: request }) - console.log(">>>> FETCH", await fetchResults.text(), fetchResults.status) - expect(fetchResults.status).toEqual(200) } } diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 6769ea07..7e62d8c6 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -49,11 +49,10 @@ export class InboxPage { async getAddress() { await this.page.locator('.Avatar').first().click() - await this.page.locator('wui-icon[name=copy]').first().click(); - const copiedAddress: string = this.page.evaluate('navigator.clipboard.readText()') as any + const address = await this.page.locator('wui-avatar').getAttribute('alt') await this.page.locator('wui-icon[name=close]').first().click(); - return copiedAddress; + return address; } async subscribe(nth: number) { diff --git a/tests/shared/pages/WalletPage.ts b/tests/shared/pages/WalletPage.ts index ba1c0360..25ec4a4e 100644 --- a/tests/shared/pages/WalletPage.ts +++ b/tests/shared/pages/WalletPage.ts @@ -10,6 +10,8 @@ export class WalletPage { private readonly gotoHome: Locator private readonly vercelPreview: Locator + private address: string; + constructor(public readonly page: Page) { this.gotoHome = this.page.getByTestId('wc-connect') this.vercelPreview = this.page.locator('css=vercel-live-feedback') From 58f0d24d80d02e79c8f6c36e2407063520afb2ec Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Wed, 28 Feb 2024 10:30:58 +0100 Subject: [PATCH 12/20] chore: remove unused prop --- tests/shared/pages/WalletPage.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/shared/pages/WalletPage.ts b/tests/shared/pages/WalletPage.ts index 25ec4a4e..ba1c0360 100644 --- a/tests/shared/pages/WalletPage.ts +++ b/tests/shared/pages/WalletPage.ts @@ -10,8 +10,6 @@ export class WalletPage { private readonly gotoHome: Locator private readonly vercelPreview: Locator - private address: string; - constructor(public readonly page: Page) { this.gotoHome = this.page.getByTestId('wc-connect') this.vercelPreview = this.page.locator('css=vercel-live-feedback') From 8fc73eddd2b3b32a3d6f66281de6d92fae736137 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Wed, 28 Feb 2024 11:01:06 +0100 Subject: [PATCH 13/20] chore: wait for dapps to be subscribed --- tests/shared/pages/InboxPage.ts | 2 -- tests/subscribe.spec.ts | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 7e62d8c6..fc0acda5 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -62,8 +62,6 @@ export class InboxPage { console.log({appCardText: await appCard.innerText()}) await appCard.locator('.AppCard__body__subscribed').getByText('Subscribed', { exact: false }).isVisible() - - await this.page.waitForTimeout(3000); } async navigateToNewSubscription(nth: number) { diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index 95426067..ab9df776 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -69,6 +69,14 @@ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ await inboxPage.rejectNotifications() await inboxPage.subscribe(0) await inboxPage.subscribe(1) + + // Wait for the 2 dapps to be subscribed to. + await inboxPage.page.waitForFunction(() => { + // Using 1 here since the first `AppSelector__list` is the one with `Discover Apps` + const apps = document.getElementsByClassName('AppSelector__list')[1].children.length; + return apps === 2; + }) + expect(await inboxPage.countSubscribedDapps()).toEqual(2); await inboxPage.navigateToDappFromSidebar(0); From 9d287befd39c4597f3c7bd9940d8e413fbc3cb4f Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Wed, 28 Feb 2024 11:39:18 +0100 Subject: [PATCH 14/20] chore: disable webkit --- playwright.config.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index 901a8c2a..7350c995 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -37,10 +37,6 @@ export default defineConfig({ name: 'firefox', use: { ...devices['Desktop Firefox'] } }, - { - name: 'webkit', - use: { ...devices['Desktop Safari'] } - } ], /* Run your local dev server before starting the tests */ From 2a2cddbe5a745152a6a5257634b13909bad429c3 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Wed, 28 Feb 2024 12:37:20 +0100 Subject: [PATCH 15/20] chore: remove extra subscribe --- tests/shared/helpers/notifyServer.ts | 2 ++ tests/subscribe.spec.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/shared/helpers/notifyServer.ts b/tests/shared/helpers/notifyServer.ts index 81fb5ff5..620636ce 100644 --- a/tests/shared/helpers/notifyServer.ts +++ b/tests/shared/helpers/notifyServer.ts @@ -46,6 +46,8 @@ export class NotifyServer { body: request }) + console.log({fetchResultsStatus: fetchResults.status, fetchResults: await fetchResults.text()}) + expect(fetchResults.status).toEqual(200) } } diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index ab9df776..3d4fa3df 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -106,7 +106,6 @@ test('it should subscribe, receive messages and unsubscribe', async ({ await walletValidator.expectReceivedSign({}) await walletPage.handleRequest({ accept: true }) await inboxPage.rejectNotifications() - await inboxPage.subscribe(0) await settingsPage.goToNotificationSettings() await settingsPage.displayCustomDapp(CUSTOM_TEST_DAPP.appDomain) From ad9dc6f647a60243ed37c9deb342ff9408728718 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Wed, 28 Feb 2024 12:46:19 +0100 Subject: [PATCH 16/20] chore: remove unhelpful logs --- tests/shared/pages/InboxPage.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index fc0acda5..b2c44849 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -59,8 +59,6 @@ export class InboxPage { const appCard = this.page.locator('.AppCard__body').nth(nth) await appCard.locator('.AppCard__body__subscribe').click() - console.log({appCardText: await appCard.innerText()}) - await appCard.locator('.AppCard__body__subscribed').getByText('Subscribed', { exact: false }).isVisible() } @@ -89,7 +87,6 @@ export class InboxPage { async countSubscribedDapps() { const selected = await this.page.locator('AppSelector__list').all() - console.log({selected}) return (await this.page.locator('.AppSelector__notifications').count() - 1) } @@ -101,7 +98,6 @@ export class InboxPage { await this.page.getByText('Preferences').nth(1).click() const firstCheckBoxIsChecked = await this.page.isChecked('.Toggle__checkbox:nth-of-type(1)') - console.log({firstCheckBoxIsChecked}) await expect(this.page.locator('.Toggle__label').first()).toBeVisible() await this.page.locator('.Toggle').first().click() From d3582d55d4e8384ce6962ee9e0ccc14eef5f5d5a Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Thu, 29 Feb 2024 10:35:32 +0100 Subject: [PATCH 17/20] Update tests/shared/pages/InboxPage.ts Co-authored-by: Enes --- tests/shared/pages/InboxPage.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index b2c44849..0ccf0367 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -87,7 +87,9 @@ export class InboxPage { async countSubscribedDapps() { const selected = await this.page.locator('AppSelector__list').all() - return (await this.page.locator('.AppSelector__notifications').count() - 1) + const notificationsCount = await this.page.locator('.AppSelector__notifications').count() + + return notificationsCount - 1; } async updatePreferences() { From df8a8485824b9d29a040f52a5261fb403e20b4a6 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Thu, 29 Feb 2024 10:36:09 +0100 Subject: [PATCH 18/20] Update tests/shared/pages/InboxPage.ts Co-authored-by: Enes --- tests/shared/pages/InboxPage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 0ccf0367..e360db61 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -12,7 +12,7 @@ export class InboxPage { } async load() { - await this.page.goto(`${this.baseURL}`) + await this.page.goto(this.baseURL) } async gotoDiscoverPage() { From 514b1877ac2496a0a692b3aebcdf6a2247e4b785 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Thu, 29 Feb 2024 12:13:40 +0100 Subject: [PATCH 19/20] chore: remove empty space --- tests/shared/pages/InboxPage.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index e360db61..35096f90 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -85,8 +85,6 @@ export class InboxPage { } async countSubscribedDapps() { - - const selected = await this.page.locator('AppSelector__list').all() const notificationsCount = await this.page.locator('.AppSelector__notifications').count() return notificationsCount - 1; From e61d72d810e935f2429e3a800bc42e24ed4f9aaa Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Thu, 29 Feb 2024 12:24:53 +0100 Subject: [PATCH 20/20] chore: refactor waitForSubscriptions --- tests/shared/pages/InboxPage.ts | 15 +++++++++++++++ tests/subscribe.spec.ts | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tests/shared/pages/InboxPage.ts b/tests/shared/pages/InboxPage.ts index 35096f90..55a76dd5 100644 --- a/tests/shared/pages/InboxPage.ts +++ b/tests/shared/pages/InboxPage.ts @@ -90,6 +90,21 @@ export class InboxPage { return notificationsCount - 1; } + /** + * Waits for a specific number of dApps to be subscribed. + * + * @param {number} expectedCount - The expected number of dApps to wait for. + * @returns {Promise} + */ + async waitForSubscriptions(expectedCount: number): Promise { + // Wait for a function that checks the length of a list or a set of elements + // matching a certain condition to equal the expectedCount. + await this.page.waitForFunction(([className, count]) => { + const elements = document.getElementsByClassName(className)[1].children;; + return elements.length === count; + }, ['AppSelector__list', expectedCount] as const, { timeout: 5000 }); + } + async updatePreferences() { await this.page.locator('.AppNotificationsHeader__wrapper > .Dropdown').click() await this.page.getByRole('button', { name: 'Preferences' }).click() diff --git a/tests/subscribe.spec.ts b/tests/subscribe.spec.ts index 3d4fa3df..cb54d4cc 100644 --- a/tests/subscribe.spec.ts +++ b/tests/subscribe.spec.ts @@ -70,6 +70,8 @@ test('it should subscribe and unsubscribe to and from multiple dapps', async ({ await inboxPage.subscribe(0) await inboxPage.subscribe(1) + await inboxPage.waitForSubscriptions(2) + // Wait for the 2 dapps to be subscribed to. await inboxPage.page.waitForFunction(() => { // Using 1 here since the first `AppSelector__list` is the one with `Discover Apps`