Skip to content

Commit

Permalink
chore: refactor waitForSubscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
devceline committed Feb 29, 2024
1 parent 514b187 commit e61d72d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/shared/pages/InboxPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
async waitForSubscriptions(expectedCount: number): Promise<void> {
// 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()
Expand Down
2 changes: 2 additions & 0 deletions tests/subscribe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit e61d72d

Please sign in to comment.