Skip to content

Commit 0e3abc2

Browse files
committed
add pickDateTime util to snaps-jest and update example snap
1 parent 7c6c5a9 commit 0e3abc2

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

packages/examples/packages/interactive-ui/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "1hZ+bdefsF0p3XoeHB3jlx3G0133M32ytog7F0CPrBk=",
10+
"shasum": "FnPgPqF+ikILx3j78midkBr2Yvqr6vsszAYm4DpeqMc=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/interactive-ui/src/components/InteractiveForm.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ export type InteractiveFormState = {
4747
* The value of the example Selector.
4848
*/
4949
'example-selector': string;
50+
51+
/**
52+
* The value of the example DateTimePicker.
53+
*/
54+
'example-datetime'?: string;
55+
56+
/**
57+
* The value of the example DatePicker.
58+
*/
59+
'example-date'?: string;
60+
61+
/**
62+
* The value of the example TimePicker.
63+
*/
64+
'example-time'?: string;
5065
};
5166

5267
export const InteractiveForm: SnapComponent<{ disabled?: boolean }> = ({
@@ -106,7 +121,6 @@ export const InteractiveForm: SnapComponent<{ disabled?: boolean }> = ({
106121
<Field label="Example DateTimePicker">
107122
<DateTimePicker
108123
name="example-datetime"
109-
disablePast={true}
110124
placeholder="Select a date and time"
111125
/>
112126
</Field>
@@ -115,7 +129,7 @@ export const InteractiveForm: SnapComponent<{ disabled?: boolean }> = ({
115129
name="example-date"
116130
type="date"
117131
placeholder="Select a date"
118-
disablePast={true}
132+
disableFuture={true}
119133
/>
120134
</Field>
121135
<Field label="Example TimePicker">

packages/examples/packages/interactive-ui/src/index.test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ describe('onRpcRequest', () => {
3535
method: 'dialog',
3636
});
3737

38+
const presentDate = new Date();
39+
40+
const futureDate = new Date();
41+
futureDate.setFullYear(futureDate.getFullYear() + 1);
42+
43+
const pastDate = new Date();
44+
pastDate.setFullYear(pastDate.getFullYear() - 1);
45+
3846
const formScreen = await response.getInterface();
3947

4048
expect(formScreen).toRender(<InteractiveForm />);
@@ -49,6 +57,12 @@ describe('onRpcRequest', () => {
4957

5058
await formScreen.clickElement('example-checkbox');
5159

60+
await formScreen.pickDateTime('example-datetime', presentDate);
61+
62+
await formScreen.pickDateTime('example-date', pastDate);
63+
64+
await formScreen.pickDateTime('example-time', futureDate);
65+
5266
await formScreen.clickElement('submit');
5367

5468
const resultScreen = await response.getInterface();
@@ -62,6 +76,9 @@ describe('onRpcRequest', () => {
6276
'example-radiogroup': 'option3',
6377
'example-checkbox': true,
6478
'example-selector': 'option2',
79+
'example-datetime': presentDate.toISOString(),
80+
'example-date': pastDate.toISOString(),
81+
'example-time': futureDate.toISOString(),
6582
}}
6683
/>,
6784
);
@@ -94,6 +111,9 @@ describe('onRpcRequest', () => {
94111
'example-radiogroup': 'option1',
95112
'example-checkbox': false,
96113
'example-selector': 'option1',
114+
'example-datetime': '',
115+
'example-date': '',
116+
'example-time': '',
97117
}}
98118
/>,
99119
);
@@ -106,6 +126,14 @@ describe('onRpcRequest', () => {
106126

107127
describe('onHomePage', () => {
108128
it('returns custom UI', async () => {
129+
const presentDate = new Date();
130+
131+
const futureDate = new Date();
132+
futureDate.setFullYear(futureDate.getFullYear() + 1);
133+
134+
const pastDate = new Date();
135+
pastDate.setFullYear(pastDate.getFullYear() - 1);
136+
109137
const { onHomePage } = await installSnap();
110138

111139
const response = await onHomePage();
@@ -122,6 +150,12 @@ describe('onHomePage', () => {
122150

123151
await formScreen.selectFromSelector('example-selector', 'option2');
124152

153+
await formScreen.pickDateTime('example-datetime', presentDate);
154+
155+
await formScreen.pickDateTime('example-date', pastDate);
156+
157+
await formScreen.pickDateTime('example-time', futureDate);
158+
125159
await formScreen.clickElement('submit');
126160

127161
const resultScreen = response.getInterface();
@@ -134,6 +168,9 @@ describe('onHomePage', () => {
134168
'example-radiogroup': 'option3',
135169
'example-checkbox': false,
136170
'example-selector': 'option2',
171+
'example-datetime': presentDate.toISOString(),
172+
'example-date': pastDate.toISOString(),
173+
'example-time': futureDate.toISOString(),
137174
}}
138175
/>,
139176
);

0 commit comments

Comments
 (0)