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

feat: added notification snap to methods-snap #137 #166

Merged
merged 8 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
});
});
});