@refinedev/react-hook-form 4.8.14 → 4.8.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js.map +1 -1
- package/dist/iife/index.js +18 -18
- package/dist/iife/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/useForm/index.d.ts.map +1 -1
- package/dist/useModalForm/index.d.ts +13 -13
- package/dist/useModalForm/index.d.ts.map +1 -1
- package/dist/useStepsForm/index.d.ts +10 -10
- package/dist/useStepsForm/index.d.ts.map +1 -1
- package/package.json +32 -32
- package/src/index.ts +6 -6
- package/src/useForm/index.spec.tsx +210 -222
- package/src/useForm/index.ts +227 -229
- package/src/useModalForm/index.spec.ts +243 -243
- package/src/useModalForm/index.ts +256 -265
- package/src/useStepsForm/index.spec.ts +103 -107
- package/src/useStepsForm/index.ts +120 -120
|
@@ -5,270 +5,270 @@ import { act, MockJSONServer, TestWrapper } from "../../test";
|
|
|
5
5
|
import { useModalForm } from "./";
|
|
6
6
|
|
|
7
7
|
describe("useModalForm Hook", () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
expect(result.current.modal.visible).toBe(false);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("'visible' initial value should be set with 'defaultVisible'", async () => {
|
|
17
|
-
const { result } = renderHook(
|
|
18
|
-
() =>
|
|
19
|
-
useModalForm({
|
|
20
|
-
refineCoreProps: {
|
|
21
|
-
resource: "posts",
|
|
22
|
-
},
|
|
23
|
-
modalProps: {
|
|
24
|
-
defaultVisible: true,
|
|
25
|
-
},
|
|
26
|
-
}),
|
|
27
|
-
{
|
|
28
|
-
wrapper: TestWrapper({}),
|
|
29
|
-
},
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
expect(result.current.modal.visible).toBe(true);
|
|
8
|
+
it("should return correct initial value of 'visible'", async () => {
|
|
9
|
+
const { result } = renderHook(() => useModalForm(), {
|
|
10
|
+
wrapper: TestWrapper({}),
|
|
33
11
|
});
|
|
34
12
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
|
|
13
|
+
expect(result.current.modal.visible).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("'visible' initial value should be set with 'defaultVisible'", async () => {
|
|
17
|
+
const { result } = renderHook(
|
|
18
|
+
() =>
|
|
19
|
+
useModalForm({
|
|
20
|
+
refineCoreProps: {
|
|
21
|
+
resource: "posts",
|
|
22
|
+
},
|
|
23
|
+
modalProps: {
|
|
24
|
+
defaultVisible: true,
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
{
|
|
28
|
+
wrapper: TestWrapper({}),
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(result.current.modal.visible).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("'visible' value should be false when 'close' is called", async () => {
|
|
36
|
+
const { result } = renderHook(
|
|
37
|
+
() =>
|
|
38
|
+
useModalForm({
|
|
39
|
+
modalProps: {
|
|
40
|
+
defaultVisible: true,
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
{
|
|
44
|
+
wrapper: TestWrapper({}),
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await act(async () => {
|
|
49
|
+
result.current.modal.close();
|
|
53
50
|
});
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
expect(result.current.modal.visible).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("'visible' value should be true when 'show' is called", async () => {
|
|
56
|
+
const { result } = renderHook(
|
|
57
|
+
() =>
|
|
58
|
+
useModalForm({
|
|
59
|
+
refineCoreProps: {
|
|
60
|
+
id: "5",
|
|
61
|
+
},
|
|
62
|
+
modalProps: {
|
|
63
|
+
defaultVisible: false,
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
{
|
|
67
|
+
wrapper: TestWrapper({}),
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
await act(async () => {
|
|
72
|
+
result.current.modal.show();
|
|
76
73
|
});
|
|
77
74
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
75
|
+
await waitFor(() => expect(result.current.modal.visible).toBe(true));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("'visible' value should be false when 'show' is called without id", async () => {
|
|
79
|
+
const { result } = renderHook(
|
|
80
|
+
() =>
|
|
81
|
+
useModalForm({
|
|
82
|
+
refineCoreProps: {
|
|
83
|
+
action: "edit",
|
|
84
|
+
},
|
|
85
|
+
modalProps: {
|
|
86
|
+
defaultVisible: false,
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
{
|
|
90
|
+
wrapper: TestWrapper({}),
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await act(async () => {
|
|
95
|
+
result.current.modal.show();
|
|
99
96
|
});
|
|
100
97
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
wrapper: TestWrapper({}),
|
|
104
|
-
});
|
|
98
|
+
expect(result.current.modal.visible).toBe(false);
|
|
99
|
+
});
|
|
105
100
|
|
|
106
|
-
|
|
101
|
+
it("'id' should be updated when 'show' is called with 'id'", async () => {
|
|
102
|
+
const { result } = renderHook(() => useModalForm(), {
|
|
103
|
+
wrapper: TestWrapper({}),
|
|
104
|
+
});
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
result.current.modal.show(id);
|
|
110
|
-
});
|
|
106
|
+
const id = "5";
|
|
111
107
|
|
|
112
|
-
|
|
108
|
+
await act(async () => {
|
|
109
|
+
result.current.modal.show(id);
|
|
113
110
|
});
|
|
114
111
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
expect(result.current.refineCore.id).toBe(id);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("'title' should be set with 'action' and 'resource'", async () => {
|
|
116
|
+
const { result } = renderHook(
|
|
117
|
+
() =>
|
|
118
|
+
useModalForm({
|
|
119
|
+
refineCoreProps: {
|
|
120
|
+
resource: "test",
|
|
121
|
+
action: "edit",
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
{
|
|
125
|
+
wrapper: TestWrapper({}),
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(result.current.modal.title).toBe("Edit test");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("when 'autoSubmitClose' is true, 'close' should be called when 'submit' is called", async () => {
|
|
133
|
+
const { result } = renderHook(
|
|
134
|
+
() =>
|
|
135
|
+
useModalForm({
|
|
136
|
+
refineCoreProps: {
|
|
137
|
+
resource: "posts",
|
|
138
|
+
},
|
|
139
|
+
modalProps: {
|
|
140
|
+
autoSubmitClose: true,
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
{
|
|
144
|
+
wrapper: TestWrapper({}),
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
await act(async () => {
|
|
149
|
+
result.current.modal.close();
|
|
150
|
+
result.current.modal.submit({});
|
|
130
151
|
});
|
|
131
152
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
expect(result.current.modal.visible).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("when 'autoSubmitClose' is false, 'close' should not be called when 'submit' is called", async () => {
|
|
157
|
+
const { result } = renderHook(
|
|
158
|
+
() =>
|
|
159
|
+
useModalForm({
|
|
160
|
+
refineCoreProps: {
|
|
161
|
+
id: 5,
|
|
162
|
+
resource: "posts",
|
|
163
|
+
},
|
|
164
|
+
modalProps: {
|
|
165
|
+
autoSubmitClose: false,
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
{
|
|
169
|
+
wrapper: TestWrapper({}),
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
await act(async () => {
|
|
174
|
+
result.current.modal.show();
|
|
154
175
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const { result } = renderHook(
|
|
158
|
-
() =>
|
|
159
|
-
useModalForm({
|
|
160
|
-
refineCoreProps: {
|
|
161
|
-
id: 5,
|
|
162
|
-
resource: "posts",
|
|
163
|
-
},
|
|
164
|
-
modalProps: {
|
|
165
|
-
autoSubmitClose: false,
|
|
166
|
-
},
|
|
167
|
-
}),
|
|
168
|
-
{
|
|
169
|
-
wrapper: TestWrapper({}),
|
|
170
|
-
},
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
await act(async () => {
|
|
174
|
-
result.current.modal.show();
|
|
175
|
-
});
|
|
176
|
-
await act(async () => {
|
|
177
|
-
result.current.modal.submit({});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
await waitFor(() => expect(result.current.modal.visible).toBe(true));
|
|
176
|
+
await act(async () => {
|
|
177
|
+
result.current.modal.submit({});
|
|
181
178
|
});
|
|
182
179
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
expect(result.current.getValues()).toStrictEqual({});
|
|
180
|
+
await waitFor(() => expect(result.current.modal.visible).toBe(true));
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("autoResetForm is true, 'reset' should be called when 'submit' is called", async () => {
|
|
184
|
+
const { result } = renderHook(
|
|
185
|
+
() =>
|
|
186
|
+
useModalForm({
|
|
187
|
+
refineCoreProps: {
|
|
188
|
+
resource: "posts",
|
|
189
|
+
action: "create",
|
|
190
|
+
},
|
|
191
|
+
modalProps: {
|
|
192
|
+
autoResetForm: true,
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
{
|
|
196
|
+
wrapper: TestWrapper({}),
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
await act(async () => {
|
|
201
|
+
result.current.modal.show();
|
|
202
|
+
result.current.register("test");
|
|
203
|
+
result.current.setValue("test", "test");
|
|
204
|
+
result.current.modal.submit({ test: "test" });
|
|
210
205
|
});
|
|
211
206
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
207
|
+
await waitFor(() => result.current.refineCore.mutationResult.isSuccess);
|
|
208
|
+
|
|
209
|
+
expect(result.current.getValues()).toStrictEqual({});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("autoResetForm is false, 'reset' should not be called when 'submit' is called", async () => {
|
|
213
|
+
const { result } = renderHook(
|
|
214
|
+
() =>
|
|
215
|
+
useModalForm({
|
|
216
|
+
refineCoreProps: {
|
|
217
|
+
resource: "posts",
|
|
218
|
+
},
|
|
219
|
+
modalProps: {
|
|
220
|
+
autoResetForm: false,
|
|
221
|
+
},
|
|
222
|
+
}),
|
|
223
|
+
{
|
|
224
|
+
wrapper: TestWrapper({}),
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
await act(async () => {
|
|
229
|
+
result.current.modal.show();
|
|
230
|
+
result.current.register("test");
|
|
231
|
+
result.current.setValue("test", "test");
|
|
232
|
+
result.current.modal.submit({ test: "test" });
|
|
236
233
|
});
|
|
237
234
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
await waitFor(() => expect(mockGetOne.mock.calls.length).toBe(1));
|
|
270
|
-
expect(mockGetOne.mock.calls[0][0].meta?.["modal-posts-edit"]).toBe(
|
|
271
|
-
undefined,
|
|
272
|
-
);
|
|
235
|
+
expect(result.current.getValues()).toStrictEqual({ test: "test" });
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("should `meta[syncWithLocationKey]` overrided by default", async () => {
|
|
239
|
+
const mockGetOne = jest.fn();
|
|
240
|
+
const mockUpdate = jest.fn();
|
|
241
|
+
|
|
242
|
+
const { result } = renderHook(
|
|
243
|
+
() =>
|
|
244
|
+
useModalForm({
|
|
245
|
+
syncWithLocation: true,
|
|
246
|
+
refineCoreProps: {
|
|
247
|
+
id: 5,
|
|
248
|
+
action: "edit",
|
|
249
|
+
resource: "posts",
|
|
250
|
+
},
|
|
251
|
+
}),
|
|
252
|
+
{
|
|
253
|
+
wrapper: TestWrapper({
|
|
254
|
+
dataProvider: {
|
|
255
|
+
...MockJSONServer,
|
|
256
|
+
getOne: mockGetOne,
|
|
257
|
+
update: mockUpdate,
|
|
258
|
+
},
|
|
259
|
+
}),
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
await act(async () => {
|
|
264
|
+
result.current.modal.show();
|
|
273
265
|
});
|
|
266
|
+
|
|
267
|
+
await waitFor(() => expect(result.current.modal.visible).toBe(true));
|
|
268
|
+
|
|
269
|
+
await waitFor(() => expect(mockGetOne.mock.calls.length).toBe(1));
|
|
270
|
+
expect(mockGetOne.mock.calls[0][0].meta?.["modal-posts-edit"]).toBe(
|
|
271
|
+
undefined,
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
274
|
});
|