This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: node engine requirements (#184) (#186) set engines compatibility for 16 and above Co-authored-by: Bernard Stojanovi膰 <bero4net@gmail.com> * pair improvements * fix lint * feat: add notify Snap method * go back after getting all notifications * remove timeout * wip * Add notification observe method * update test * remove unused code * wip notifiction observer * wip observer based notifications * wip observer based notifications * remove unused dependency * cleanup * fixes after merge * revert method names * clean waitForNotification method * emitter solution - FP * emitter solution - ClassBased * Cleanup class based emitter * fix lint * fixes after merge * remove p-event library * remove eslint comment * update test configuration * return NotificationList from waitForNotification * add getNotificationEmitter method * remove back button Co-authored-by: Marin Petruni膰 <mpetrunic@users.noreply.github.com> Co-authored-by: Bernard Stojanovi膰 <bero4net@gmail.com> Co-authored-by: Marin Petrunic <marin.petrunic@gmail.com>
- Loading branch information
1 parent
a633120
commit 089e951
Showing
18 changed files
with
215 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { StrictEventEmitter } from "strict-event-emitter"; | ||
import { DappeteerPage } from "../page"; | ||
import { clickOnElement, profileDropdownClick } from "../helpers"; | ||
import { NotificationItem, NotificationList } from "./types"; | ||
|
||
interface EventsMap { | ||
notification: (notification: NotificationItem) => void; | ||
} | ||
|
||
class NotificationsEmitter extends StrictEventEmitter<EventsMap> { | ||
private notificationsTab: DappeteerPage; | ||
|
||
constructor( | ||
private page: DappeteerPage, | ||
private notificationTimeout: number = 30000 | ||
) { | ||
super(); | ||
} | ||
|
||
private async exposeEmitNotificationToWindow(): Promise<void> { | ||
await this.notificationsTab.exposeFunction( | ||
"emitNotification", | ||
(notification: NotificationItem) => { | ||
this.emit("notification", notification); | ||
} | ||
); | ||
} | ||
|
||
private async openNotificationPage(): Promise<void> { | ||
const newPage = await this.page.browser().newPage(); | ||
await newPage.goto(this.page.url()); | ||
|
||
await profileDropdownClick(newPage); | ||
await clickOnElement(newPage, "Notifications"); | ||
|
||
await newPage.waitForSelector(".notifications__container", { | ||
timeout: this.notificationTimeout, | ||
}); | ||
this.notificationsTab = newPage; | ||
} | ||
|
||
private async observeNotificationsMutation(): Promise<void> { | ||
await this.notificationsTab.evaluate(() => { | ||
const observer = new MutationObserver((mutations) => { | ||
for (const mutation of mutations) { | ||
if (mutation.addedNodes.length) { | ||
const element = mutation.addedNodes[0] as HTMLElement; | ||
window.emitNotification({ message: element.innerText }); | ||
observer.disconnect(); | ||
} | ||
} | ||
}); | ||
observer.observe(document.querySelector(".notifications__container"), { | ||
childList: true, | ||
}); | ||
}); | ||
} | ||
|
||
public async setup(): Promise<void> { | ||
await this.openNotificationPage(); | ||
await this.exposeEmitNotificationToWindow(); | ||
await this.observeNotificationsMutation(); | ||
} | ||
|
||
public async cleanup(): Promise<void> { | ||
this.removeAllListeners("notification"); | ||
await this.notificationsTab.close(); | ||
} | ||
|
||
public async waitForNotification(): Promise<NotificationList> { | ||
return (await NotificationsEmitter.once( | ||
this, | ||
"notification" | ||
)) as NotificationList; | ||
} | ||
} | ||
|
||
export default NotificationsEmitter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { DappeteerPage } from "../page"; | ||
import NotificationsEmitter from "./NotificationsEmitter"; | ||
|
||
export const getNotificationEmitter = | ||
(page: DappeteerPage) => async (): Promise<NotificationsEmitter> => { | ||
const emitter = new NotificationsEmitter(page); | ||
await emitter.setup(); | ||
return emitter; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.