Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/snaps-jest/src/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ describe('installSnap', () => {
selectFromSelector: expect.any(Function),
uploadFile: expect.any(Function),
waitForUpdate: expect.any(Function),
id: expect.any(String),
ok: expect.any(Function),
cancel: expect.any(Function),
});
Expand Down Expand Up @@ -475,6 +476,7 @@ describe('installSnap', () => {
selectFromSelector: expect.any(Function),
uploadFile: expect.any(Function),
waitForUpdate: expect.any(Function),
id: expect.any(String),
ok: expect.any(Function),
cancel: expect.any(Function),
});
Expand Down Expand Up @@ -538,6 +540,7 @@ describe('installSnap', () => {
selectFromSelector: expect.any(Function),
uploadFile: expect.any(Function),
waitForUpdate: expect.any(Function),
id: expect.any(String),
ok: expect.any(Function),
});

Expand Down
3 changes: 3 additions & 0 deletions packages/snaps-simulation/src/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('helpers', () => {
selectFromSelector: expect.any(Function),
uploadFile: expect.any(Function),
waitForUpdate: expect.any(Function),
id: expect.any(String),
ok: expect.any(Function),
cancel: expect.any(Function),
});
Expand Down Expand Up @@ -209,6 +210,7 @@ describe('helpers', () => {
selectFromSelector: expect.any(Function),
uploadFile: expect.any(Function),
waitForUpdate: expect.any(Function),
id: expect.any(String),
ok: expect.any(Function),
cancel: expect.any(Function),
});
Expand Down Expand Up @@ -272,6 +274,7 @@ describe('helpers', () => {
selectFromSelector: expect.any(Function),
uploadFile: expect.any(Function),
waitForUpdate: expect.any(Function),
id: expect.any(String),
ok: expect.any(Function),
});

Expand Down
22 changes: 22 additions & 0 deletions packages/snaps-simulation/src/interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES[DialogType.Alert],
'foo',
<Text>foo</Text>,
interfaceActions,
);
assertIsAlertDialog(response);

expect(response).toStrictEqual({
type: DialogType.Alert,
id: 'foo',
content: <Text>foo</Text>,
clickElement: expect.any(Function),
typeInField: expect.any(Function),
Expand All @@ -127,13 +129,15 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES[DialogType.Confirmation],
'foo',
<Text>foo</Text>,
interfaceActions,
);

assertIsConfirmationDialog(response);
expect(response).toStrictEqual({
type: DialogType.Confirmation,
id: 'foo',
content: <Text>foo</Text>,
clickElement: expect.any(Function),
typeInField: expect.any(Function),
Expand All @@ -156,13 +160,15 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES[DialogType.Confirmation],
'foo',
<Text>foo</Text>,
interfaceActions,
);

assertIsConfirmationDialog(response);
expect(response).toStrictEqual({
type: DialogType.Confirmation,
id: 'foo',
content: <Text>foo</Text>,
clickElement: expect.any(Function),
typeInField: expect.any(Function),
Expand All @@ -185,13 +191,15 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES[DialogType.Prompt],
'foo',
<Text>foo</Text>,
interfaceActions,
);

assertIsPromptDialog(response);
expect(response).toStrictEqual({
type: DialogType.Prompt,
id: 'foo',
content: <Text>foo</Text>,
clickElement: expect.any(Function),
typeInField: expect.any(Function),
Expand All @@ -214,13 +222,15 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES[DialogType.Prompt],
'foo',
<Text>foo</Text>,
interfaceActions,
);

assertIsPromptDialog(response);
expect(response).toStrictEqual({
type: DialogType.Prompt,
id: 'foo',
content: <Text>foo</Text>,
clickElement: expect.any(Function),
typeInField: expect.any(Function),
Expand All @@ -243,13 +253,15 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES[DialogType.Prompt],
'foo',
<Text>foo</Text>,
interfaceActions,
);

assertIsPromptDialog(response);
expect(response).toStrictEqual({
type: DialogType.Prompt,
id: 'foo',
content: <Text>foo</Text>,
clickElement: expect.any(Function),
typeInField: expect.any(Function),
Expand All @@ -272,6 +284,7 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES.default,
'foo',
<Container>
<Box>
<Text>foo</Text>
Expand All @@ -288,6 +301,7 @@ describe('getInterfaceResponse', () => {
assertCustomDialogHasFooter(response);

expect(response).toStrictEqual({
id: 'foo',
content: (
<Container>
<Box>
Expand All @@ -314,6 +328,7 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES.default,
'foo',
<Container>
<Box>
<Text>foo</Text>
Expand All @@ -329,6 +344,7 @@ describe('getInterfaceResponse', () => {
assertCustomDialogHasPartialFooter(response);

expect(response).toStrictEqual({
id: 'foo',
content: (
<Container>
<Box>
Expand All @@ -355,6 +371,7 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
DIALOG_APPROVAL_TYPES.default,
'foo',
<Container>
<Box>
<Text>foo</Text>
Expand All @@ -367,6 +384,7 @@ describe('getInterfaceResponse', () => {
assertCustomDialogHasNoFooter(response);

expect(response).toStrictEqual({
id: 'foo',
content: (
<Container>
<Box>
Expand All @@ -391,13 +409,15 @@ describe('getInterfaceResponse', () => {
const response = getInterfaceResponse(
runSaga,
'Notification',
'foo',
<Box>
<Text>Foo</Text>
</Box>,
interfaceActions,
);

expect(response).toStrictEqual({
id: 'foo',
content: (
<Box>
<Text>Foo</Text>
Expand Down Expand Up @@ -1280,6 +1300,7 @@ describe('getInterface', () => {
rootControllerMessenger,
).toPromise();
expect(result).toStrictEqual({
id,
type,
content: getJsxElementFromComponent(content),
clickElement: expect.any(Function),
Expand Down Expand Up @@ -1311,6 +1332,7 @@ describe('getInterface', () => {

const result = await promise;
expect(result).toStrictEqual({
id,
type,
content: getJsxElementFromComponent(content),
clickElement: expect.any(Function),
Expand Down
11 changes: 11 additions & 0 deletions packages/snaps-simulation/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ const MAX_FILE_SIZE = 10_000_000; // 10 MB
*
* @param runSaga - A function to run a saga outside the usual Redux flow.
* @param type - The type of the interface.
* @param id - The interface ID.
* @param content - The content to show in the interface.
* @param interfaceActions - The actions to interact with the interface.
* @returns The user interface object.
*/
export function getInterfaceResponse(
runSaga: RunSagaFunction,
type: DialogApprovalTypes[DialogType | 'default'] | 'Notification',
id: string,
content: JSXElement,
interfaceActions: SnapInterfaceActions,
): SnapInterface {
Expand All @@ -64,6 +66,8 @@ export function getInterfaceResponse(
...interfaceActions,
type: DialogType.Alert,
content,
id,

ok: resolveWith(runSaga, null),
};

Expand All @@ -72,6 +76,7 @@ export function getInterfaceResponse(
...interfaceActions,
type: DialogType.Confirmation,
content,
id,

ok: resolveWith(runSaga, true),
cancel: resolveWith(runSaga, false),
Expand All @@ -82,6 +87,7 @@ export function getInterfaceResponse(
...interfaceActions,
type: DialogType.Prompt,
content,
id,

ok: resolveWithInput(runSaga),
cancel: resolveWith(runSaga, null),
Expand All @@ -95,6 +101,7 @@ export function getInterfaceResponse(
return {
...interfaceActions,
content,
id,

ok: resolveWith(runSaga, null),
cancel: resolveWith(runSaga, null),
Expand All @@ -106,6 +113,7 @@ export function getInterfaceResponse(
return {
...interfaceActions,
content,
id,

cancel: resolveWith(runSaga, null),
};
Expand All @@ -115,13 +123,15 @@ export function getInterfaceResponse(
return {
...interfaceActions,
content,
id,
};
}

case 'Notification': {
return {
...interfaceActions,
content,
id,
};
}

Expand Down Expand Up @@ -1017,6 +1027,7 @@ export function* getInterface(
return getInterfaceResponse(
runSaga,
storedInterface.type,
storedInterface.id,
storedInterface.content,
interfaceActions,
);
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-simulation/src/request.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe('handleRequest', () => {
},
key: null,
},
id: expect.any(String),
ok: expect.any(Function),
selectFromRadioGroup: expect.any(Function),
selectFromSelector: expect.any(Function),
Expand Down
20 changes: 20 additions & 0 deletions packages/snaps-simulation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ export type SnapAlertInterface = {
*/
content: JSXElement;

/**
* The ID of the interface.
*/
id: string;

/**
* Close the alert.
*/
Expand All @@ -214,6 +219,11 @@ export type SnapConfirmationInterface = {
*/
content: JSXElement;

/**
* The ID of the interface.
*/
id: string;

/**
* Close the confirmation.
*/
Expand All @@ -239,6 +249,11 @@ export type SnapPromptInterface = {
*/
content: JSXElement;

/**
* The ID of the interface.
*/
id: string;

/**
* Close the prompt.
*
Expand All @@ -261,6 +276,11 @@ export type DefaultSnapInterfaceWithFooter = {
* The content to show in the interface.
*/
content: JSXElement;

/**
* The ID of the interface.
*/
id: string;
};

/**
Expand Down
Loading