1
1
/* eslint-disable jest/valid-expect */
2
2
import React from "react" ;
3
- import { PolarisAutoForm } from "../../../../src/auto/polaris/PolarisAutoForm.js" ;
4
- import { PolarisAutoInput } from "../../../../src/auto/polaris/inputs/PolarisAutoInput.js" ;
3
+ import { elements } from "../../../../spec/auto/shadcn-defaults/index.js" ;
5
4
import { PolarisAutoJSONInput } from "../../../../src/auto/polaris/inputs/PolarisAutoJSONInput.js" ;
6
5
import { PolarisAutoSubmit } from "../../../../src/auto/polaris/submit/PolarisAutoSubmit.js" ;
7
- import { PolarisSubmitResultBanner } from "../../../../src/auto/polaris/submit/PolarisSubmitResultBanner.js" ;
8
6
import { api } from "../../../support/api.js" ;
9
- import { PolarisWrapper } from "../../../support/auto.js" ;
7
+ import { describeForEachAutoAdapter } from "../../../support/auto.js" ;
8
+ import { SUITE_NAMES } from "../../../support/constants.js" ;
9
+
10
+ import { PolarisAutoInput } from "../../../../src/auto/polaris/inputs/PolarisAutoInput.js" ;
11
+ import { PolarisSubmitResultBanner } from "../../../../src/auto/polaris/submit/PolarisSubmitResultBanner.js" ;
12
+ import { makeShadcnAutoInput } from "../../../../src/auto/shadcn/inputs/ShadcnAutoInput.js" ;
13
+ import { makeShadcnAutoJSONInput } from "../../../../src/auto/shadcn/inputs/ShadcnAutoJSONInput.js" ;
14
+ import { makeShadcnAutoSubmit } from "../../../../src/auto/shadcn/submit/ShadcnAutoSubmit.js" ;
15
+ import { makeSubmitResultBanner } from "../../../../src/auto/shadcn/submit/ShadcnSubmitResultBanner.js" ;
16
+
17
+ const ShadcnAutoJSONInput = makeShadcnAutoJSONInput ( elements ) ;
18
+ const ShadcnAutoSubmit = makeShadcnAutoSubmit ( elements ) ;
19
+ const ShadcnAutoInput = makeShadcnAutoInput ( elements ) ;
20
+ const { ShadcnSubmitResultBanner } = makeSubmitResultBanner ( elements ) ;
21
+
22
+ describeForEachAutoAdapter ( "AutoFormJSONInput" , ( { name, adapter : { AutoForm } , wrapper } ) => {
23
+ const AutoJSONInputWithSubmit = ( props : { field : string } ) => {
24
+ if ( name === SUITE_NAMES . POLARIS ) {
25
+ return (
26
+ < >
27
+ < PolarisAutoJSONInput { ...props } />
28
+ < PolarisAutoSubmit id = "auto" />
29
+ </ >
30
+ ) ;
31
+ }
32
+
33
+ if ( name === SUITE_NAMES . SHADCN ) {
34
+ return (
35
+ < >
36
+ < ShadcnAutoJSONInput { ...props } />
37
+ < ShadcnAutoSubmit id = "auto" />
38
+ </ >
39
+ ) ;
40
+ }
41
+
42
+ throw new Error ( "Invalid suite name" ) ;
43
+ } ;
44
+
45
+ const AutoInputWithSubmit = ( ) => {
46
+ if ( name === SUITE_NAMES . POLARIS ) {
47
+ return (
48
+ < >
49
+ < PolarisSubmitResultBanner />
50
+ < PolarisAutoJSONInput field = "metafields" />
51
+ < PolarisAutoInput field = "name" />
52
+ < PolarisAutoInput field = "inventoryCount" />
53
+ < PolarisAutoSubmit id = "auto" />
54
+ < PolarisAutoSubmit id = "auto" />
55
+ </ >
56
+ ) ;
57
+ }
58
+
59
+ if ( name === SUITE_NAMES . SHADCN ) {
60
+ return (
61
+ < >
62
+ < ShadcnSubmitResultBanner />
63
+ < ShadcnAutoJSONInput field = "metafields" />
64
+ < ShadcnAutoInput field = "name" />
65
+ < ShadcnAutoInput field = "inventoryCount" />
66
+ < ShadcnAutoSubmit id = "auto" />
67
+ </ >
68
+ ) ;
69
+ }
70
+
71
+ throw new Error ( "Invalid suite name" ) ;
72
+ } ;
10
73
11
- describe ( "PolarisJSONInput" , ( ) => {
12
74
beforeEach ( ( ) => {
13
75
cy . viewport ( "macbook-13" ) ;
14
76
} ) ;
@@ -39,14 +101,10 @@ describe("PolarisJSONInput", () => {
39
101
) ;
40
102
41
103
cy . mountWithWrapper (
42
- < PolarisAutoForm action = { api . widget . create } >
43
- < PolarisSubmitResultBanner />
44
- < PolarisAutoJSONInput field = "metafields" />
45
- < PolarisAutoInput field = "name" />
46
- < PolarisAutoInput field = "inventoryCount" />
47
- < PolarisAutoSubmit />
48
- </ PolarisAutoForm > ,
49
- PolarisWrapper
104
+ < AutoForm action = { api . widget . create } >
105
+ < AutoInputWithSubmit />
106
+ </ AutoForm > ,
107
+ wrapper
50
108
) ;
51
109
52
110
cy . get ( `textarea[name="widget.metafields"]` ) . type ( "not a valid JSON" ) ;
@@ -56,13 +114,13 @@ describe("PolarisJSONInput", () => {
56
114
cy . get ( `input[name="widget.name"]` ) . type ( "foobar" ) ;
57
115
58
116
// try to submit form, but it shouldn't submit as the json field is invalid
59
- cy . get ( `button.Polaris-Button[type="submit"] ` ) . click ( ) ;
117
+ cy . get ( `#auto ` ) . click ( ) ;
60
118
61
119
cy . contains ( `Invalid JSON: Unexpected token 'o', "not a valid JSON" is not valid JSON` ) ;
62
120
63
121
cy . get ( `textarea[name="widget.metafields"]` ) . clear ( ) . type ( `{"foo": "bar"}` , { parseSpecialCharSequences : false } ) ;
64
122
65
- cy . get ( `button.Polaris-Button[type="submit"] ` ) . click ( ) ;
123
+ cy . get ( `#auto ` ) . click ( ) ;
66
124
67
125
cy . contains ( `Saved Widget successfully` ) ;
68
126
} ) ;
@@ -93,11 +151,10 @@ describe("PolarisJSONInput", () => {
93
151
) . as ( "widget" ) ;
94
152
95
153
cy . mountWithWrapper (
96
- < PolarisAutoForm action = { api . widget . update } findBy = "1" >
97
- < PolarisAutoJSONInput field = "metafields" />
98
- < PolarisAutoSubmit />
99
- </ PolarisAutoForm > ,
100
- PolarisWrapper
154
+ < AutoForm action = { api . widget . update } findBy = "1" >
155
+ < AutoJSONInputWithSubmit field = "metafields" />
156
+ </ AutoForm > ,
157
+ wrapper
101
158
) ;
102
159
103
160
cy . wait ( "@widget" ) ;
@@ -133,11 +190,10 @@ describe("PolarisJSONInput", () => {
133
190
) . as ( "widget" ) ;
134
191
135
192
cy . mountWithWrapper (
136
- < PolarisAutoForm action = { api . widget . update } findBy = "2" >
137
- < PolarisAutoJSONInput field = "metafields" />
138
- < PolarisAutoSubmit />
139
- </ PolarisAutoForm > ,
140
- PolarisWrapper
193
+ < AutoForm action = { api . widget . update } findBy = "2" >
194
+ < AutoJSONInputWithSubmit field = "metafields" />
195
+ </ AutoForm > ,
196
+ wrapper
141
197
) ;
142
198
cy . wait ( "@widget" ) ;
143
199
@@ -171,11 +227,10 @@ describe("PolarisJSONInput", () => {
171
227
) . as ( "widget" ) ;
172
228
173
229
cy . mountWithWrapper (
174
- < PolarisAutoForm action = { api . widget . update } findBy = "3" >
175
- < PolarisAutoJSONInput field = "metafields" />
176
- < PolarisAutoSubmit />
177
- </ PolarisAutoForm > ,
178
- PolarisWrapper
230
+ < AutoForm action = { api . widget . update } findBy = "3" >
231
+ < AutoJSONInputWithSubmit field = "metafields" />
232
+ </ AutoForm > ,
233
+ wrapper
179
234
) ;
180
235
cy . wait ( "@widget" ) ;
181
236
@@ -207,11 +262,10 @@ describe("PolarisJSONInput", () => {
207
262
) ;
208
263
209
264
cy . mountWithWrapper (
210
- < PolarisAutoForm action = { api . widget . update } findBy = "3" >
211
- < PolarisAutoJSONInput field = "metafields" />
212
- < PolarisAutoSubmit />
213
- </ PolarisAutoForm > ,
214
- PolarisWrapper
265
+ < AutoForm action = { api . widget . update } findBy = "3" >
266
+ < AutoJSONInputWithSubmit field = "metafields" />
267
+ </ AutoForm > ,
268
+ wrapper
215
269
) ;
216
270
217
271
cy . get ( `textarea[name="widget.metafields"]` ) . should ( "have.value" , `` ) ;
@@ -244,11 +298,10 @@ describe("PolarisJSONInput", () => {
244
298
) . as ( "widget" ) ;
245
299
246
300
cy . mountWithWrapper (
247
- < PolarisAutoForm action = { api . widget . update } findBy = "1" >
248
- < PolarisAutoJSONInput field = "metafields" />
249
- < PolarisAutoSubmit />
250
- </ PolarisAutoForm > ,
251
- PolarisWrapper
301
+ < AutoForm action = { api . widget . update } findBy = "1" >
302
+ < AutoJSONInputWithSubmit field = "metafields" />
303
+ </ AutoForm > ,
304
+ wrapper
252
305
) ;
253
306
254
307
cy . wait ( "@widget" ) ;
@@ -283,7 +336,7 @@ describe("PolarisJSONInput", () => {
283
336
}
284
337
) . as ( "updateWidget" ) ;
285
338
286
- cy . get ( `button.Polaris-Button[type="submit"] ` ) . click ( ) ;
339
+ cy . get ( `#auto ` ) . click ( ) ;
287
340
cy . wait ( "@updateWidget" ) ;
288
341
} ) ;
289
342
} ) ;
0 commit comments