Skip to content

Commit

Permalink
address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeRx committed Dec 17, 2024
1 parent 0dc7ae6 commit f8080eb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './dialog';
export * from './result';
export * from './settings';
export * from './Dialog';
export * from './Result';
export * from './Settings';
40 changes: 39 additions & 1 deletion packages/examples/packages/preinstalled/src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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(<Settings />);
});
});
1 change: 1 addition & 0 deletions packages/examples/packages/preinstalled/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit f8080eb

Please sign in to comment.