Skip to content

Commit

Permalink
fix: avoid subscribing to non-test apps, subscribe by name not index
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Mar 6, 2024
1 parent 7b879bc commit c037958
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
38 changes: 26 additions & 12 deletions tests/shared/pages/InboxPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
38 changes: 26 additions & 12 deletions tests/subscribe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test.afterEach(async ({ inboxValidator, walletValidator }) => {
test('it should subscribe and unsubscribe', async ({
inboxPage,
walletPage,
settingsPage,
walletValidator,
browserName
}) => {
Expand All @@ -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
}) => {
Expand All @@ -48,14 +55,20 @@ 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()
})

test('it should subscribe and unsubscribe to and from multiple dapps', async ({
inboxPage,
walletPage,
settingsPage,
walletValidator,
browserName
}) => {
Expand All @@ -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)

Expand All @@ -82,15 +100,15 @@ 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)

/*
* 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()
})

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit c037958

Please sign in to comment.