From f8080eba247e51ef48d0b49f9911b7da7e8cac54 Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Tue, 17 Dec 2024 12:53:49 +0100 Subject: [PATCH] address requested changes --- .../src/components/{dialog.tsx => Dialog.tsx} | 0 .../src/components/{result.tsx => Result.tsx} | 0 .../components/{settings.tsx => Settings.tsx} | 0 .../preinstalled/src/components/index.ts | 6 +-- .../packages/preinstalled/src/index.test.tsx | 40 ++++++++++++++++++- .../packages/preinstalled/src/index.tsx | 1 + 6 files changed, 43 insertions(+), 4 deletions(-) rename packages/examples/packages/preinstalled/src/components/{dialog.tsx => Dialog.tsx} (100%) rename packages/examples/packages/preinstalled/src/components/{result.tsx => Result.tsx} (100%) rename packages/examples/packages/preinstalled/src/components/{settings.tsx => Settings.tsx} (100%) diff --git a/packages/examples/packages/preinstalled/src/components/dialog.tsx b/packages/examples/packages/preinstalled/src/components/Dialog.tsx similarity index 100% rename from packages/examples/packages/preinstalled/src/components/dialog.tsx rename to packages/examples/packages/preinstalled/src/components/Dialog.tsx diff --git a/packages/examples/packages/preinstalled/src/components/result.tsx b/packages/examples/packages/preinstalled/src/components/Result.tsx similarity index 100% rename from packages/examples/packages/preinstalled/src/components/result.tsx rename to packages/examples/packages/preinstalled/src/components/Result.tsx diff --git a/packages/examples/packages/preinstalled/src/components/settings.tsx b/packages/examples/packages/preinstalled/src/components/Settings.tsx similarity index 100% rename from packages/examples/packages/preinstalled/src/components/settings.tsx rename to packages/examples/packages/preinstalled/src/components/Settings.tsx diff --git a/packages/examples/packages/preinstalled/src/components/index.ts b/packages/examples/packages/preinstalled/src/components/index.ts index d7a0a19df9..265d85397b 100644 --- a/packages/examples/packages/preinstalled/src/components/index.ts +++ b/packages/examples/packages/preinstalled/src/components/index.ts @@ -1,3 +1,3 @@ -export * from './dialog'; -export * from './result'; -export * from './settings'; +export * from './Dialog'; +export * from './Result'; +export * from './Settings'; diff --git a/packages/examples/packages/preinstalled/src/index.test.tsx b/packages/examples/packages/preinstalled/src/index.test.tsx index 4fe235d886..12ddeb69fb 100644 --- a/packages/examples/packages/preinstalled/src/index.test.tsx +++ b/packages/examples/packages/preinstalled/src/index.test.tsx @@ -1,7 +1,7 @@ import { expect } from '@jest/globals'; import { installSnap } from '@metamask/snaps-jest'; -import { Dialog, Result } from './components'; +import { Dialog, Result, Settings } from './components'; describe('onRpcRequest', () => { it('throws an error if the requested method does not exist', async () => { @@ -61,4 +61,42 @@ describe('onRpcRequest', () => { expect(result).toRespondWith('foo bar'); }); }); + + describe('getSettings', () => { + it('returns the settings state', async () => { + const { request, onSettingsPage } = await installSnap(); + + const settingPageResponse = await onSettingsPage(); + + const screen = settingPageResponse.getInterface(); + + await screen.clickElement('setting1'); + + await screen.selectFromRadioGroup('setting2', 'option1'); + + await screen.selectInDropdown('setting3', 'option2'); + + expect( + await request({ + method: 'getSettings', + }), + ).toRespondWith({ + setting1: true, + setting2: 'option1', + setting3: 'option2', + }); + }); + }); +}); + +describe('onSettingsPage', () => { + it('returns custom UI', async () => { + const { onSettingsPage } = await installSnap(); + + const response = await onSettingsPage(); + + const screen = response.getInterface(); + + expect(screen).toRender(); + }); }); diff --git a/packages/examples/packages/preinstalled/src/index.tsx b/packages/examples/packages/preinstalled/src/index.tsx index acf0a31440..3132be492c 100644 --- a/packages/examples/packages/preinstalled/src/index.tsx +++ b/packages/examples/packages/preinstalled/src/index.tsx @@ -25,6 +25,7 @@ type SnapState = { * @returns The JSON-RPC response. * @see https://docs.metamask.io/snaps/reference/exports/#onrpcrequest * @see https://docs.metamask.io/snaps/reference/rpc-api/#wallet_invokesnap + * @see https://docs.metamask.io/snaps/reference/snaps-api/#snap_dialog * @see https://docs.metamask.io/snaps/reference/snaps-api/#snap_managestate */ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {