Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat: add notify Snap method
Browse files Browse the repository at this point in the history
  • Loading branch information
Lykhoyda committed Nov 1, 2022
1 parent 3cd36b0 commit b4b3604
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/flask/methods-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export const onRpcRequest: OnRpcRequestHandler = ({ origin, request }) => {
},
],
});
case "notify_inApp":
return wallet.request({
method: "snap_notify",
params: [
{
type: "inApp",
message: `Hello, in App notification`,
},
],
});
default:
throw new Error("Method not found.");
}
Expand Down
40 changes: 40 additions & 0 deletions test/flask/snaps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as dappeteer from "../../src";
import { TestContext } from "../constant";
import { Snaps } from "../deploy";
import { toUrl } from "../utils/utils";
import { clickOnElement, openProfileDropdown } from "../../src/helpers";

function getSnapIdByName(testContext: TestContext, snapName: Snaps): string {
return `local:${toUrl(testContext.snapServers[snapName].address())}`;
Expand Down Expand Up @@ -97,5 +98,44 @@ describe("snaps", function () {

expect(await invokeAction).to.equal(false);
});

it("should invoke IN APP NOTIFICATION method and show text", async function (this: TestContext) {
await metamask.snaps.invokeSnap(
testPage,
getSnapIdByName(this, Snaps.METHODS_SNAP),
"notify_inApp"
);

await metamask.page.bringToFront();
await openProfileDropdown(metamask.page);
await clickOnElement(metamask.page, "Notifications");

const notificationItem = await metamask.page.waitForSelector(
".notifications__item"
);
const notificationText = await notificationItem.$eval(
".notifications__item__details__message",
(el) => el.textContent
);
const unreadDot = await notificationItem.$eval(
".notifications__item__unread-dot",
(el) => el.className
);

expect(notificationText).to.equal("Hello, in App notification");
expect(unreadDot).to.equal("notifications__item__unread-dot unread");

await notificationItem.click();
const notificationItemUpdated = await metamask.page.waitForSelector(
".notifications__item"
);

expect(
await notificationItemUpdated.$eval(
".notifications__item__unread-dot",
(el) => el.className
)
).to.equal("notifications__item__unread-dot");
});
});
});

0 comments on commit b4b3604

Please sign in to comment.