-
Notifications
You must be signed in to change notification settings - Fork 645
Expand file tree
/
Copy pathindex.test.tsx
More file actions
169 lines (126 loc) · 4.62 KB
/
index.test.tsx
File metadata and controls
169 lines (126 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { expect } from '@jest/globals';
import { assertIsCustomDialog, installSnap } from '@metamask/snaps-jest';
import {
Insight,
InteractiveForm,
Result,
TransactionType,
} from './components';
describe('onRpcRequest', () => {
it('throws an error if the requested method does not exist', async () => {
const { request } = await installSnap();
const response = await request({
method: 'foo',
});
expect(response).toRespondWithError({
code: -32601,
message: 'The method does not exist / is not available.',
stack: expect.any(String),
data: {
method: 'foo',
cause: null,
},
});
});
describe('dialog', () => {
it('creates a new Snap interface and use it in a confirmation dialog', async () => {
const { request } = await installSnap();
const response = request({
method: 'dialog',
});
const formScreen = await response.getInterface();
expect(formScreen).toRender(<InteractiveForm />);
await formScreen.typeInField('example-input', 'foobar');
await formScreen.selectInDropdown('example-dropdown', 'option3');
await formScreen.selectFromRadioGroup('example-radiogroup', 'option3');
await formScreen.selectFromSelector('example-selector', 'option2');
await formScreen.clickElement('example-checkbox');
await formScreen.clickElement('submit');
const resultScreen = await response.getInterface();
assertIsCustomDialog(resultScreen);
expect(resultScreen).toRender(
<Result
values={{
'example-input': 'foobar',
'example-dropdown': 'option3',
'example-radiogroup': 'option3',
'example-checkbox': true,
'example-selector': 'option2',
}}
/>,
);
await resultScreen.clickElement('ok');
expect(await response).toRespondWith(null);
});
it('lets users input nothing', async () => {
const { request } = await installSnap();
const response = request({
method: 'dialog',
});
const formScreen = await response.getInterface();
expect(formScreen).toRender(<InteractiveForm />);
await formScreen.clickElement('submit');
const resultScreen = await response.getInterface();
assertIsCustomDialog(resultScreen);
expect(resultScreen).toRender(
<Result
values={{
'example-input': '',
'example-dropdown': 'option1',
'example-radiogroup': 'option1',
'example-checkbox': false,
'example-selector': 'option1',
}}
/>,
);
await resultScreen.clickElement('ok');
expect(await response).toRespondWith(null);
});
});
});
describe('onHomePage', () => {
it('returns custom UI', async () => {
const { onHomePage } = await installSnap();
const response = await onHomePage();
const formScreen = response.getInterface();
expect(formScreen).toRender(<InteractiveForm />);
await formScreen.typeInField('example-input', 'foobar');
await formScreen.selectInDropdown('example-dropdown', 'option3');
await formScreen.selectFromRadioGroup('example-radiogroup', 'option3');
await formScreen.selectFromSelector('example-selector', 'option2');
await formScreen.clickElement('submit');
const resultScreen = response.getInterface();
expect(resultScreen).toRender(
<Result
values={{
'example-input': 'foobar',
'example-dropdown': 'option3',
'example-radiogroup': 'option3',
'example-checkbox': false,
'example-selector': 'option2',
}}
/>,
);
});
});
describe('onTransaction', () => {
const FROM_ADDRESS = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045';
const TO_ADDRESS = '0x4bbeeb066ed09b7aed07bf39eee0460dfa261520';
it('returns custom UI', async () => {
const { onTransaction } = await installSnap();
const response = await onTransaction({
from: FROM_ADDRESS,
to: TO_ADDRESS,
// This is not a valid ERC-20 transfer as all the values are zero, but it
// is enough to test the `onTransaction` handler.
data: '0xa9059cbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
});
const startScreen = response.getInterface();
expect(startScreen).toRender(
<Insight from={FROM_ADDRESS} to={TO_ADDRESS} />,
);
await startScreen.clickElement('transaction-type');
const txTypeScreen = response.getInterface();
expect(txTypeScreen).toRender(<TransactionType type="ERC-20" />);
});
});