Skip to content

Commit 4f201d5

Browse files
authored
Add the interface ID to the return value of getInterface (#3174)
This adds the interface ID in the return value of `snap-jest` `getInterface`.
1 parent 0ee1f83 commit 4f201d5

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

packages/snaps-jest/src/helpers.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ describe('installSnap', () => {
412412
selectFromSelector: expect.any(Function),
413413
uploadFile: expect.any(Function),
414414
waitForUpdate: expect.any(Function),
415+
id: expect.any(String),
415416
ok: expect.any(Function),
416417
cancel: expect.any(Function),
417418
});
@@ -475,6 +476,7 @@ describe('installSnap', () => {
475476
selectFromSelector: expect.any(Function),
476477
uploadFile: expect.any(Function),
477478
waitForUpdate: expect.any(Function),
479+
id: expect.any(String),
478480
ok: expect.any(Function),
479481
cancel: expect.any(Function),
480482
});
@@ -538,6 +540,7 @@ describe('installSnap', () => {
538540
selectFromSelector: expect.any(Function),
539541
uploadFile: expect.any(Function),
540542
waitForUpdate: expect.any(Function),
543+
id: expect.any(String),
541544
ok: expect.any(Function),
542545
});
543546

packages/snaps-simulation/src/helpers.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ describe('helpers', () => {
146146
selectFromSelector: expect.any(Function),
147147
uploadFile: expect.any(Function),
148148
waitForUpdate: expect.any(Function),
149+
id: expect.any(String),
149150
ok: expect.any(Function),
150151
cancel: expect.any(Function),
151152
});
@@ -209,6 +210,7 @@ describe('helpers', () => {
209210
selectFromSelector: expect.any(Function),
210211
uploadFile: expect.any(Function),
211212
waitForUpdate: expect.any(Function),
213+
id: expect.any(String),
212214
ok: expect.any(Function),
213215
cancel: expect.any(Function),
214216
});
@@ -272,6 +274,7 @@ describe('helpers', () => {
272274
selectFromSelector: expect.any(Function),
273275
uploadFile: expect.any(Function),
274276
waitForUpdate: expect.any(Function),
277+
id: expect.any(String),
275278
ok: expect.any(Function),
276279
});
277280

packages/snaps-simulation/src/interface.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ describe('getInterfaceResponse', () => {
9999
const response = getInterfaceResponse(
100100
runSaga,
101101
DIALOG_APPROVAL_TYPES[DialogType.Alert],
102+
'foo',
102103
<Text>foo</Text>,
103104
interfaceActions,
104105
);
105106
assertIsAlertDialog(response);
106107

107108
expect(response).toStrictEqual({
108109
type: DialogType.Alert,
110+
id: 'foo',
109111
content: <Text>foo</Text>,
110112
clickElement: expect.any(Function),
111113
typeInField: expect.any(Function),
@@ -127,13 +129,15 @@ describe('getInterfaceResponse', () => {
127129
const response = getInterfaceResponse(
128130
runSaga,
129131
DIALOG_APPROVAL_TYPES[DialogType.Confirmation],
132+
'foo',
130133
<Text>foo</Text>,
131134
interfaceActions,
132135
);
133136

134137
assertIsConfirmationDialog(response);
135138
expect(response).toStrictEqual({
136139
type: DialogType.Confirmation,
140+
id: 'foo',
137141
content: <Text>foo</Text>,
138142
clickElement: expect.any(Function),
139143
typeInField: expect.any(Function),
@@ -156,13 +160,15 @@ describe('getInterfaceResponse', () => {
156160
const response = getInterfaceResponse(
157161
runSaga,
158162
DIALOG_APPROVAL_TYPES[DialogType.Confirmation],
163+
'foo',
159164
<Text>foo</Text>,
160165
interfaceActions,
161166
);
162167

163168
assertIsConfirmationDialog(response);
164169
expect(response).toStrictEqual({
165170
type: DialogType.Confirmation,
171+
id: 'foo',
166172
content: <Text>foo</Text>,
167173
clickElement: expect.any(Function),
168174
typeInField: expect.any(Function),
@@ -185,13 +191,15 @@ describe('getInterfaceResponse', () => {
185191
const response = getInterfaceResponse(
186192
runSaga,
187193
DIALOG_APPROVAL_TYPES[DialogType.Prompt],
194+
'foo',
188195
<Text>foo</Text>,
189196
interfaceActions,
190197
);
191198

192199
assertIsPromptDialog(response);
193200
expect(response).toStrictEqual({
194201
type: DialogType.Prompt,
202+
id: 'foo',
195203
content: <Text>foo</Text>,
196204
clickElement: expect.any(Function),
197205
typeInField: expect.any(Function),
@@ -214,13 +222,15 @@ describe('getInterfaceResponse', () => {
214222
const response = getInterfaceResponse(
215223
runSaga,
216224
DIALOG_APPROVAL_TYPES[DialogType.Prompt],
225+
'foo',
217226
<Text>foo</Text>,
218227
interfaceActions,
219228
);
220229

221230
assertIsPromptDialog(response);
222231
expect(response).toStrictEqual({
223232
type: DialogType.Prompt,
233+
id: 'foo',
224234
content: <Text>foo</Text>,
225235
clickElement: expect.any(Function),
226236
typeInField: expect.any(Function),
@@ -243,13 +253,15 @@ describe('getInterfaceResponse', () => {
243253
const response = getInterfaceResponse(
244254
runSaga,
245255
DIALOG_APPROVAL_TYPES[DialogType.Prompt],
256+
'foo',
246257
<Text>foo</Text>,
247258
interfaceActions,
248259
);
249260

250261
assertIsPromptDialog(response);
251262
expect(response).toStrictEqual({
252263
type: DialogType.Prompt,
264+
id: 'foo',
253265
content: <Text>foo</Text>,
254266
clickElement: expect.any(Function),
255267
typeInField: expect.any(Function),
@@ -272,6 +284,7 @@ describe('getInterfaceResponse', () => {
272284
const response = getInterfaceResponse(
273285
runSaga,
274286
DIALOG_APPROVAL_TYPES.default,
287+
'foo',
275288
<Container>
276289
<Box>
277290
<Text>foo</Text>
@@ -288,6 +301,7 @@ describe('getInterfaceResponse', () => {
288301
assertCustomDialogHasFooter(response);
289302

290303
expect(response).toStrictEqual({
304+
id: 'foo',
291305
content: (
292306
<Container>
293307
<Box>
@@ -314,6 +328,7 @@ describe('getInterfaceResponse', () => {
314328
const response = getInterfaceResponse(
315329
runSaga,
316330
DIALOG_APPROVAL_TYPES.default,
331+
'foo',
317332
<Container>
318333
<Box>
319334
<Text>foo</Text>
@@ -329,6 +344,7 @@ describe('getInterfaceResponse', () => {
329344
assertCustomDialogHasPartialFooter(response);
330345

331346
expect(response).toStrictEqual({
347+
id: 'foo',
332348
content: (
333349
<Container>
334350
<Box>
@@ -355,6 +371,7 @@ describe('getInterfaceResponse', () => {
355371
const response = getInterfaceResponse(
356372
runSaga,
357373
DIALOG_APPROVAL_TYPES.default,
374+
'foo',
358375
<Container>
359376
<Box>
360377
<Text>foo</Text>
@@ -367,6 +384,7 @@ describe('getInterfaceResponse', () => {
367384
assertCustomDialogHasNoFooter(response);
368385

369386
expect(response).toStrictEqual({
387+
id: 'foo',
370388
content: (
371389
<Container>
372390
<Box>
@@ -391,13 +409,15 @@ describe('getInterfaceResponse', () => {
391409
const response = getInterfaceResponse(
392410
runSaga,
393411
'Notification',
412+
'foo',
394413
<Box>
395414
<Text>Foo</Text>
396415
</Box>,
397416
interfaceActions,
398417
);
399418

400419
expect(response).toStrictEqual({
420+
id: 'foo',
401421
content: (
402422
<Box>
403423
<Text>Foo</Text>
@@ -1280,6 +1300,7 @@ describe('getInterface', () => {
12801300
rootControllerMessenger,
12811301
).toPromise();
12821302
expect(result).toStrictEqual({
1303+
id,
12831304
type,
12841305
content: getJsxElementFromComponent(content),
12851306
clickElement: expect.any(Function),
@@ -1311,6 +1332,7 @@ describe('getInterface', () => {
13111332

13121333
const result = await promise;
13131334
expect(result).toStrictEqual({
1335+
id,
13141336
type,
13151337
content: getJsxElementFromComponent(content),
13161338
clickElement: expect.any(Function),

packages/snaps-simulation/src/interface.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ const MAX_FILE_SIZE = 10_000_000; // 10 MB
4848
*
4949
* @param runSaga - A function to run a saga outside the usual Redux flow.
5050
* @param type - The type of the interface.
51+
* @param id - The interface ID.
5152
* @param content - The content to show in the interface.
5253
* @param interfaceActions - The actions to interact with the interface.
5354
* @returns The user interface object.
5455
*/
5556
export function getInterfaceResponse(
5657
runSaga: RunSagaFunction,
5758
type: DialogApprovalTypes[DialogType | 'default'] | 'Notification',
59+
id: string,
5860
content: JSXElement,
5961
interfaceActions: SnapInterfaceActions,
6062
): SnapInterface {
@@ -64,6 +66,8 @@ export function getInterfaceResponse(
6466
...interfaceActions,
6567
type: DialogType.Alert,
6668
content,
69+
id,
70+
6771
ok: resolveWith(runSaga, null),
6872
};
6973

@@ -72,6 +76,7 @@ export function getInterfaceResponse(
7276
...interfaceActions,
7377
type: DialogType.Confirmation,
7478
content,
79+
id,
7580

7681
ok: resolveWith(runSaga, true),
7782
cancel: resolveWith(runSaga, false),
@@ -82,6 +87,7 @@ export function getInterfaceResponse(
8287
...interfaceActions,
8388
type: DialogType.Prompt,
8489
content,
90+
id,
8591

8692
ok: resolveWithInput(runSaga),
8793
cancel: resolveWith(runSaga, null),
@@ -95,6 +101,7 @@ export function getInterfaceResponse(
95101
return {
96102
...interfaceActions,
97103
content,
104+
id,
98105

99106
ok: resolveWith(runSaga, null),
100107
cancel: resolveWith(runSaga, null),
@@ -106,6 +113,7 @@ export function getInterfaceResponse(
106113
return {
107114
...interfaceActions,
108115
content,
116+
id,
109117

110118
cancel: resolveWith(runSaga, null),
111119
};
@@ -115,13 +123,15 @@ export function getInterfaceResponse(
115123
return {
116124
...interfaceActions,
117125
content,
126+
id,
118127
};
119128
}
120129

121130
case 'Notification': {
122131
return {
123132
...interfaceActions,
124133
content,
134+
id,
125135
};
126136
}
127137

@@ -1017,6 +1027,7 @@ export function* getInterface(
10171027
return getInterfaceResponse(
10181028
runSaga,
10191029
storedInterface.type,
1030+
storedInterface.id,
10201031
storedInterface.content,
10211032
interfaceActions,
10221033
);

packages/snaps-simulation/src/request.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('handleRequest', () => {
109109
},
110110
key: null,
111111
},
112+
id: expect.any(String),
112113
ok: expect.any(Function),
113114
selectFromRadioGroup: expect.any(Function),
114115
selectFromSelector: expect.any(Function),

packages/snaps-simulation/src/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ export type SnapAlertInterface = {
194194
*/
195195
content: JSXElement;
196196

197+
/**
198+
* The ID of the interface.
199+
*/
200+
id: string;
201+
197202
/**
198203
* Close the alert.
199204
*/
@@ -214,6 +219,11 @@ export type SnapConfirmationInterface = {
214219
*/
215220
content: JSXElement;
216221

222+
/**
223+
* The ID of the interface.
224+
*/
225+
id: string;
226+
217227
/**
218228
* Close the confirmation.
219229
*/
@@ -239,6 +249,11 @@ export type SnapPromptInterface = {
239249
*/
240250
content: JSXElement;
241251

252+
/**
253+
* The ID of the interface.
254+
*/
255+
id: string;
256+
242257
/**
243258
* Close the prompt.
244259
*
@@ -261,6 +276,11 @@ export type DefaultSnapInterfaceWithFooter = {
261276
* The content to show in the interface.
262277
*/
263278
content: JSXElement;
279+
280+
/**
281+
* The ID of the interface.
282+
*/
283+
id: string;
264284
};
265285

266286
/**

0 commit comments

Comments
 (0)