1
1
import React from "react" ;
2
2
import { apiTriggerOnly } from "../../../../spec/auto/support/Triggers.js" ;
3
3
import { getStadiumRecord } from "../../../../spec/auto/support/stadiumModel.js" ;
4
- import { PolarisAutoForm } from "../../../../src/auto/polaris/PolarisAutoForm.js" ;
5
4
import { api } from "../../../support/api.js" ;
6
- import { PolarisWrapper } from "../../../support/auto.js" ;
5
+ import { describeForEachAutoAdapter } from "../../../support/auto.js" ;
6
+ import { SUITE_NAMES } from "../../../support/constants.js" ;
7
7
8
- describe ( "PolarisEnumInput ", ( ) => {
8
+ describeForEachAutoAdapter ( "AutoEnumInput ", ( { name , adapter : { AutoForm } , wrapper } ) => {
9
9
const blurComboboxes = ( ) => {
10
- cy . get ( "#type-combobox-textfield" ) . blur ( { force : true } ) ;
11
- cy . get ( "#tags-combobox-textfield" ) . blur ( { force : true } ) ;
10
+ cy . get ( "body" ) . click ( { force : true } ) ;
11
+ } ;
12
+
13
+ const checkBadgeWithButton = ( value : string ) => {
14
+ cy . get ( `div` )
15
+ . contains ( value )
16
+ . should ( "exist" )
17
+ . within ( ( ) => {
18
+ cy . get ( `button` ) . should ( "exist" ) . and ( "be.visible" ) ;
19
+ } ) ;
12
20
} ;
13
21
14
22
beforeEach ( ( ) => {
@@ -55,18 +63,24 @@ describe("PolarisEnumInput", () => {
55
63
) . as ( "updateStadium" ) ;
56
64
} ) ;
57
65
66
+ const getInputSelector = ( id : string ) => {
67
+ return name == SUITE_NAMES . SHADCN ? `[data-testid='${ id } -combobox-textfield']` : `#${ id } -combobox-textfield` ;
68
+ } ;
69
+
70
+ const selectedItemsSelector = name == SUITE_NAMES . SHADCN ? `[role="presentation"]` : ".Polaris-InlineStack" ;
71
+
58
72
it ( "should include the enum options in the dropdown" , ( ) => {
59
73
cy . mockModelActionMetadata ( api , baseModelActionMetadata ) ;
60
74
61
- cy . mountWithWrapper ( < PolarisAutoForm action = { api . game . stadium . create } /> , PolarisWrapper ) ;
62
- cy . get ( "# type-combobox-textfield" ) . click ( ) ;
75
+ cy . mountWithWrapper ( < AutoForm action = { api . game . stadium . create } /> , wrapper ) ;
76
+ cy . get ( getInputSelector ( " type" ) ) . click ( ) ;
63
77
cy . contains ( "football" ) . should ( "exist" ) ;
64
78
cy . contains ( "basketball" ) . should ( "exist" ) ;
65
79
cy . contains ( "baseball" ) . should ( "exist" ) ;
66
80
// Close the "type" dropdown
67
81
blurComboboxes ( ) ;
68
82
69
- cy . get ( "# tags-combobox-textfield" ) . click ( ) ;
83
+ cy . get ( getInputSelector ( " tags" ) ) . click ( ) ;
70
84
cy . contains ( "hello" ) . should ( "exist" ) ;
71
85
cy . contains ( "world" ) . should ( "exist" ) ;
72
86
} ) ;
@@ -75,15 +89,23 @@ describe("PolarisEnumInput", () => {
75
89
it ( "should show the selected value in the dropdown for single select enum" , ( ) => {
76
90
cy . mockModelActionMetadata ( api , baseModelActionMetadata ) ;
77
91
78
- cy . mountWithWrapper ( < PolarisAutoForm action = { api . game . stadium . create } /> , PolarisWrapper ) ;
79
- cy . get ( "# type-combobox-textfield" ) . click ( ) ;
92
+ cy . mountWithWrapper ( < AutoForm action = { api . game . stadium . create } /> , wrapper ) ;
93
+ cy . get ( getInputSelector ( " type" ) ) . click ( ) ;
80
94
cy . contains ( "football" ) . click ( ) ;
81
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "football" ) ;
82
-
83
- cy . get ( "#tags-combobox-textfield" ) . click ( ) ;
84
- cy . contains ( "hello" ) . parent ( ) . parent ( ) . click ( ) ;
85
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "hello" ) ;
86
- cy . get ( ".Polaris-InlineStack" ) . should ( "not.contain" , "world" ) ;
95
+ cy . get ( selectedItemsSelector ) . should ( "contain" , "football" ) ;
96
+
97
+ if ( name == SUITE_NAMES . SHADCN ) {
98
+ cy . get ( "[cmdk-input]" ) . eq ( 1 ) . click ( ) ;
99
+ cy . get ( '[cmdk-item][data-value="hello"]' ) . click ( ) ;
100
+ cy . get ( "[cmdk-input]" ) . eq ( 1 ) . click ( ) ;
101
+ cy . get ( '[cmdk-item][data-value="hello"][data-selected="true"]' ) . should ( "exist" ) ;
102
+ cy . get ( '[cmdk-item][data-value="world"][data-selected="true"]' ) . should ( "not.exist" ) ;
103
+ } else {
104
+ cy . get ( getInputSelector ( "tags" ) ) . click ( ) ;
105
+ cy . contains ( "hello" ) . parent ( ) . parent ( ) . click ( ) ;
106
+ cy . get ( selectedItemsSelector ) . should ( "contain" , "hello" ) ;
107
+ cy . get ( selectedItemsSelector ) . should ( "not.contain" , "world" ) ;
108
+ }
87
109
88
110
blurComboboxes ( ) ;
89
111
@@ -99,27 +121,37 @@ describe("PolarisEnumInput", () => {
99
121
it ( "should allow searching for options in the dropdown" , ( ) => {
100
122
cy . mockModelActionMetadata ( api , baseModelActionMetadata ) ;
101
123
102
- cy . mountWithWrapper ( < PolarisAutoForm action = { api . game . stadium . create } /> , PolarisWrapper ) ;
124
+ cy . mountWithWrapper ( < AutoForm action = { api . game . stadium . create } /> , wrapper ) ;
103
125
// For single select enums
104
- cy . get ( "# type-combobox-textfield" ) . type ( "foot" ) ;
126
+ cy . get ( getInputSelector ( " type" ) ) . type ( "foot" ) ;
105
127
106
128
// The dropdown items should be filtered
107
129
cy . contains ( "football" ) . should ( "exist" ) ;
108
130
cy . contains ( "basketball" ) . should ( "not.exist" ) ;
109
131
cy . contains ( "baseball" ) . should ( "not.exist" ) ;
110
132
111
133
cy . contains ( "football" ) . click ( ) ;
112
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "football" ) ;
134
+ cy . get ( selectedItemsSelector ) . should ( "contain" , "football" ) ;
113
135
114
136
// For multi-select enums
115
- cy . get ( "# tags-combobox-textfield" ) . type ( "hel" ) ;
137
+ cy . get ( getInputSelector ( " tags" ) ) . type ( "hel" ) ;
116
138
117
139
// The dropdown items should be filtered
118
140
cy . contains ( "hello" ) . should ( "exist" ) ;
119
141
cy . contains ( "world" ) . should ( "not.exist" ) ;
120
142
121
- cy . contains ( "hello" ) . parent ( ) . parent ( ) . click ( ) ;
122
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "hello" ) ;
143
+ if ( name == SUITE_NAMES . SHADCN ) {
144
+ cy . get ( '[cmdk-item][data-value="hello"]' ) . click ( ) ;
145
+ // Verify that the chip/tag appears after selection
146
+ checkBadgeWithButton ( "hello" ) ;
147
+
148
+ cy . get ( "[cmdk-input]" ) . eq ( 1 ) . click ( ) ;
149
+
150
+ cy . contains ( 'Add "hel"' ) . should ( "exist" ) ;
151
+ } else {
152
+ cy . contains ( "hello" ) . parent ( ) . parent ( ) . click ( ) ;
153
+ cy . get ( selectedItemsSelector ) . should ( "contain" , "hello" ) ;
154
+ }
123
155
124
156
blurComboboxes ( ) ;
125
157
@@ -171,14 +203,14 @@ describe("PolarisEnumInput", () => {
171
203
172
204
cy . mockModelActionMetadata ( api , mockedMetadata ) ;
173
205
174
- cy . mountWithWrapper ( < PolarisAutoForm action = { api . game . stadium . create } /> , PolarisWrapper ) ;
175
- cy . get ( "# type-combobox-textfield" ) . type ( "extra" ) ;
206
+ cy . mountWithWrapper ( < AutoForm action = { api . game . stadium . create } /> , wrapper ) ;
207
+ cy . get ( getInputSelector ( " type" ) ) . type ( "extra" ) ;
176
208
cy . contains ( `Add "extra"` ) . click ( ) ;
177
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "extra" ) ;
209
+ cy . get ( selectedItemsSelector ) . should ( "contain" , "extra" ) ;
178
210
179
- cy . get ( "# tags-combobox-textfield" ) . type ( "more" ) ;
211
+ cy . get ( getInputSelector ( " tags" ) ) . type ( "more" ) ;
180
212
cy . contains ( `Add "more"` ) . click ( ) ;
181
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "more" ) ;
213
+ cy . get ( selectedItemsSelector ) . should ( "contain" , "more" ) ;
182
214
183
215
blurComboboxes ( ) ;
184
216
@@ -226,14 +258,14 @@ describe("PolarisEnumInput", () => {
226
258
] ,
227
259
} ) ;
228
260
229
- cy . mountWithWrapper ( < PolarisAutoForm action = { api . game . stadium . create } /> , PolarisWrapper ) ;
230
- cy . get ( "# type-combobox-textfield" ) . type ( "hello" ) ;
261
+ cy . mountWithWrapper ( < AutoForm action = { api . game . stadium . create } /> , wrapper ) ;
262
+ cy . get ( getInputSelector ( " type" ) ) . type ( "hello" ) ;
231
263
cy . contains ( `Add "hello"` ) . should ( "not.exist" ) ;
232
264
cy . contains ( `No options found matching "hello"` ) . should ( "exist" ) ;
233
265
234
266
blurComboboxes ( ) ;
235
267
236
- cy . get ( "# tags-combobox-textfield" ) . type ( "nope" ) ;
268
+ cy . get ( getInputSelector ( " tags" ) ) . type ( "nope" ) ;
237
269
cy . contains ( `Add "nope"` ) . should ( "not.exist" ) ;
238
270
cy . contains ( `No options found matching "nope"` ) . should ( "exist" ) ;
239
271
} ) ;
@@ -264,10 +296,17 @@ describe("PolarisEnumInput", () => {
264
296
} ,
265
297
} ) ;
266
298
267
- cy . mountWithWrapper ( < PolarisAutoForm action = { api . game . stadium . update } findBy = "42" /> , PolarisWrapper ) ;
268
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "football" ) ;
269
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "hello" ) ;
270
- cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "world" ) ;
299
+ cy . mountWithWrapper ( < AutoForm action = { api . game . stadium . update } findBy = "42" /> , wrapper ) ;
300
+
301
+ if ( name == SUITE_NAMES . SHADCN ) {
302
+ checkBadgeWithButton ( "football" ) ;
303
+ checkBadgeWithButton ( "hello" ) ;
304
+ checkBadgeWithButton ( "world" ) ;
305
+ } else {
306
+ cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "football" ) ;
307
+ cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "hello" ) ;
308
+ cy . get ( ".Polaris-InlineStack" ) . should ( "contain" , "world" ) ;
309
+ }
271
310
} ) ;
272
311
273
312
it ( "should be able to clear the value" , ( ) => {
@@ -279,13 +318,13 @@ describe("PolarisEnumInput", () => {
279
318
} ,
280
319
} ) ;
281
320
282
- cy . mountWithWrapper ( < PolarisAutoForm action = { api . game . stadium . update } findBy = "42" /> , PolarisWrapper ) ;
283
- cy . get ( "# type-combobox-textfield" ) . click ( ) ;
321
+ cy . mountWithWrapper ( < AutoForm action = { api . game . stadium . update } findBy = "42" /> , wrapper ) ;
322
+ cy . get ( getInputSelector ( " type" ) ) . click ( ) ;
284
323
cy . get ( '[aria-label="Remove football"]' ) . click ( ) ;
285
324
286
325
blurComboboxes ( ) ;
287
326
288
- cy . get ( "# tags-combobox-textfield" ) . click ( ) ;
327
+ cy . get ( getInputSelector ( " tags" ) ) . click ( ) ;
289
328
cy . get ( '[aria-label="Remove hello"]' ) . click ( ) ;
290
329
cy . get ( '[aria-label="Remove world"]' ) . click ( ) ;
291
330
0 commit comments