@planningcenter/tapestry-migration-cli 3.1.0-rc.8 → 3.1.0
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/tapestry-react-shim.cjs +7 -1
- package/package.json +3 -3
- package/src/components/input/transformableInput.ts +47 -6
- package/src/components/input/transforms/mergeFieldIntoInput.test.ts +78 -0
- package/src/components/input/transforms/mergeFieldIntoInput.ts +6 -212
- package/src/components/input/transforms/removeDuplicateKeys.test.ts +3 -3
- package/src/components/input/transforms/removeTypeInput.test.ts +212 -0
- package/src/components/input/transforms/removeTypeInput.ts +22 -0
- package/src/components/input/transforms/removeTypeText.ts +2 -3
- package/src/components/input/transforms/unsupportedProps.test.ts +20 -20
- package/src/components/select/index.ts +58 -0
- package/src/components/select/transformableSelect.ts +7 -0
- package/src/components/select/transforms/auditSpreadProps.test.ts +103 -0
- package/src/components/select/transforms/auditSpreadProps.ts +26 -0
- package/src/components/select/transforms/childrenToOptions.test.ts +367 -0
- package/src/components/select/transforms/childrenToOptions.ts +295 -0
- package/src/components/select/transforms/convertLegacyOptions.test.ts +150 -0
- package/src/components/select/transforms/convertLegacyOptions.ts +105 -0
- package/src/components/select/transforms/convertStyleProps.test.ts +73 -0
- package/src/components/select/transforms/convertStyleProps.ts +12 -0
- package/src/components/select/transforms/emptyValueToPlaceholder.test.ts +122 -0
- package/src/components/select/transforms/emptyValueToPlaceholder.ts +22 -0
- package/src/components/select/transforms/innerRefToRef.test.ts +89 -0
- package/src/components/select/transforms/innerRefToRef.ts +18 -0
- package/src/components/select/transforms/mapChildrenToOptions.test.ts +521 -0
- package/src/components/select/transforms/mapChildrenToOptions.ts +312 -0
- package/src/components/select/transforms/mergeFieldIntoSelect.test.ts +506 -0
- package/src/components/select/transforms/mergeFieldIntoSelect.ts +7 -0
- package/src/components/select/transforms/mergeSelectLabel.test.ts +458 -0
- package/src/components/select/transforms/mergeSelectLabel.ts +225 -0
- package/src/components/select/transforms/moveSelectImport.test.ts +148 -0
- package/src/components/select/transforms/moveSelectImport.ts +14 -0
- package/src/components/select/transforms/removeDefaultProps.test.ts +249 -0
- package/src/components/select/transforms/removeDefaultProps.ts +112 -0
- package/src/components/select/transforms/sizeMapping.test.ts +188 -0
- package/src/components/select/transforms/sizeMapping.ts +17 -0
- package/src/components/select/transforms/skipMultipleSelect.test.ts +148 -0
- package/src/components/select/transforms/skipMultipleSelect.ts +23 -0
- package/src/components/select/transforms/stateToInvalid.test.ts +217 -0
- package/src/components/select/transforms/stateToInvalid.ts +59 -0
- package/src/components/select/transforms/stateToInvalidTernary.test.ts +146 -0
- package/src/components/select/transforms/stateToInvalidTernary.ts +13 -0
- package/src/components/select/transforms/unsupportedProps.test.ts +252 -0
- package/src/components/select/transforms/unsupportedProps.ts +44 -0
- package/src/components/shared/helpers/getAttributeExpression.ts +26 -0
- package/src/components/shared/helpers/unsupportedPropsHelpers.ts +52 -2
- package/src/components/shared/transformFactories/mergeFieldFactory.ts +244 -0
- package/src/components/shared/transformFactories/stylePropTransformFactory.ts +2 -1
- package/src/components/text-area/index.ts +48 -0
- package/src/components/text-area/transforms/auditSpreadProps.test.ts +139 -0
- package/src/components/text-area/transforms/auditSpreadProps.ts +10 -0
- package/src/components/text-area/transforms/convertStyleProps.test.ts +158 -0
- package/src/components/text-area/transforms/convertStyleProps.ts +10 -0
- package/src/components/text-area/transforms/innerRefToRef.test.ts +206 -0
- package/src/components/text-area/transforms/innerRefToRef.ts +14 -0
- package/src/components/text-area/transforms/mergeFieldIntoTextArea.test.ts +477 -0
- package/src/components/text-area/transforms/mergeFieldIntoTextArea.ts +5 -0
- package/src/components/text-area/transforms/moveTextAreaImport.test.ts +168 -0
- package/src/components/text-area/transforms/moveTextAreaImport.ts +13 -0
- package/src/components/text-area/transforms/removeDuplicateKeys.test.ts +129 -0
- package/src/components/text-area/transforms/removeDuplicateKeys.ts +8 -0
- package/src/components/text-area/transforms/removeRedundantAriaLabel.test.ts +183 -0
- package/src/components/text-area/transforms/removeRedundantAriaLabel.ts +59 -0
- package/src/components/text-area/transforms/sizeMapping.test.ts +199 -0
- package/src/components/text-area/transforms/sizeMapping.ts +15 -0
- package/src/components/text-area/transforms/stateToInvalid.test.ts +204 -0
- package/src/components/text-area/transforms/stateToInvalid.ts +57 -0
- package/src/components/text-area/transforms/stateToInvalidTernary.test.ts +133 -0
- package/src/components/text-area/transforms/stateToInvalidTernary.ts +11 -0
- package/src/components/text-area/transforms/unsupportedProps.test.ts +275 -0
- package/src/components/text-area/transforms/unsupportedProps.ts +35 -0
- package/src/index.ts +4 -1
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import jscodeshift from "jscodeshift"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
|
|
4
|
+
import transform from "./mergeFieldIntoSelect"
|
|
5
|
+
|
|
6
|
+
const j = jscodeshift.withParser("tsx")
|
|
7
|
+
|
|
8
|
+
function applyTransform(source: string): string | null {
|
|
9
|
+
const fileInfo = { path: "test.tsx", source }
|
|
10
|
+
return transform(
|
|
11
|
+
fileInfo,
|
|
12
|
+
{ j, jscodeshift: j, report: () => {}, stats: () => {} },
|
|
13
|
+
{}
|
|
14
|
+
) as string | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("mergeFieldIntoSelect transform", () => {
|
|
18
|
+
describe("basic prop merging", () => {
|
|
19
|
+
it("merges label prop from Field into Select", () => {
|
|
20
|
+
const input = `
|
|
21
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
22
|
+
|
|
23
|
+
function Test() {
|
|
24
|
+
return (
|
|
25
|
+
<Box>
|
|
26
|
+
<Field label="Product"><Select emptyValue="Pick" /></Field>
|
|
27
|
+
</Box>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
`.trim()
|
|
31
|
+
|
|
32
|
+
const result = applyTransform(input)
|
|
33
|
+
expect(result).not.toBeNull()
|
|
34
|
+
expect(result).not.toContain("<Field")
|
|
35
|
+
expect(result).toContain('label="Product"')
|
|
36
|
+
expect(result).toContain("<Select")
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("renames feedbackText to description on Select", () => {
|
|
40
|
+
const input = `
|
|
41
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
42
|
+
|
|
43
|
+
function Test() {
|
|
44
|
+
return (
|
|
45
|
+
<Field feedbackText="Required"><Select emptyValue="Pick" /></Field>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
`.trim()
|
|
49
|
+
|
|
50
|
+
const result = applyTransform(input)
|
|
51
|
+
expect(result).not.toBeNull()
|
|
52
|
+
expect(result).not.toContain("<Field")
|
|
53
|
+
expect(result).not.toContain("feedbackText")
|
|
54
|
+
expect(result).toContain('description="Required"')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it("copies state prop as-is to Select", () => {
|
|
58
|
+
const input = `
|
|
59
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
60
|
+
|
|
61
|
+
function Test() {
|
|
62
|
+
return (
|
|
63
|
+
<Field state="error"><Select emptyValue="Pick" /></Field>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
`.trim()
|
|
67
|
+
|
|
68
|
+
const result = applyTransform(input)
|
|
69
|
+
expect(result).not.toBeNull()
|
|
70
|
+
expect(result).not.toContain("<Field")
|
|
71
|
+
expect(result).toContain('state="error"')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("copies state expression as-is to Select", () => {
|
|
75
|
+
const input = `
|
|
76
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
77
|
+
|
|
78
|
+
function Test() {
|
|
79
|
+
return (
|
|
80
|
+
<Field state={"error"}><Select emptyValue="Pick" /></Field>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
`.trim()
|
|
84
|
+
|
|
85
|
+
const result = applyTransform(input)
|
|
86
|
+
expect(result).not.toBeNull()
|
|
87
|
+
expect(result).not.toContain("<Field")
|
|
88
|
+
expect(result).toContain('state={"error"}')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("preserves dynamic label value", () => {
|
|
92
|
+
const input = `
|
|
93
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
94
|
+
|
|
95
|
+
function Test() {
|
|
96
|
+
return (
|
|
97
|
+
<Field label={labelText}><Select emptyValue="Pick" /></Field>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
`.trim()
|
|
101
|
+
|
|
102
|
+
const result = applyTransform(input)
|
|
103
|
+
expect(result).not.toBeNull()
|
|
104
|
+
expect(result).not.toContain("<Field")
|
|
105
|
+
expect(result).toContain("label={labelText}")
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe("unsupported props", () => {
|
|
110
|
+
it("adds TODO comment for helpContent and removes Field", () => {
|
|
111
|
+
const input = `
|
|
112
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
113
|
+
|
|
114
|
+
function Test() {
|
|
115
|
+
return (
|
|
116
|
+
<Field helpContent="Help"><Select emptyValue="Pick" /></Field>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
`.trim()
|
|
120
|
+
|
|
121
|
+
const result = applyTransform(input)
|
|
122
|
+
expect(result).not.toBeNull()
|
|
123
|
+
expect(result).not.toContain("<Field")
|
|
124
|
+
expect(result).toContain(
|
|
125
|
+
"TODO: tapestry-migration (mergeFieldIntoSelect)"
|
|
126
|
+
)
|
|
127
|
+
expect(result).toContain("helpContent")
|
|
128
|
+
expect(result).toContain("not supported by Select")
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it("passes through dynamic state value to Select", () => {
|
|
132
|
+
const input = `
|
|
133
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
134
|
+
|
|
135
|
+
function Test() {
|
|
136
|
+
return (
|
|
137
|
+
<Field state={fieldState}><Select emptyValue="Pick" /></Field>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
`.trim()
|
|
141
|
+
|
|
142
|
+
const result = applyTransform(input)
|
|
143
|
+
expect(result).not.toBeNull()
|
|
144
|
+
expect(result).not.toContain("<Field")
|
|
145
|
+
expect(result).toContain("state={fieldState}")
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe("Field with no props", () => {
|
|
150
|
+
it("unwraps Field with no props cleanly", () => {
|
|
151
|
+
const input = `
|
|
152
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
153
|
+
|
|
154
|
+
function Test() {
|
|
155
|
+
return (
|
|
156
|
+
<Field><Select emptyValue="Pick" /></Field>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
`.trim()
|
|
160
|
+
|
|
161
|
+
const result = applyTransform(input)
|
|
162
|
+
expect(result).not.toBeNull()
|
|
163
|
+
expect(result).not.toContain("<Field")
|
|
164
|
+
expect(result).toContain("<Select")
|
|
165
|
+
expect(result).not.toContain("TODO")
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
describe("conflict detection", () => {
|
|
170
|
+
it("adds warning when Select already has label", () => {
|
|
171
|
+
const input = `
|
|
172
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
173
|
+
|
|
174
|
+
function Test() {
|
|
175
|
+
return (
|
|
176
|
+
<Field label="Name"><Select label="Other" emptyValue="Pick" /></Field>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
`.trim()
|
|
180
|
+
|
|
181
|
+
const result = applyTransform(input)
|
|
182
|
+
expect(result).not.toBeNull()
|
|
183
|
+
expect(result).not.toContain("<Field")
|
|
184
|
+
expect(result).toContain('label="Other"')
|
|
185
|
+
expect(result).toContain(
|
|
186
|
+
"TODO: tapestry-migration (mergeFieldIntoSelect)"
|
|
187
|
+
)
|
|
188
|
+
expect(result).toContain("already has label")
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it("adds warning when Select already has description and Field has feedbackText", () => {
|
|
192
|
+
const input = `
|
|
193
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
194
|
+
|
|
195
|
+
function Test() {
|
|
196
|
+
return (
|
|
197
|
+
<Field feedbackText="Error"><Select description="Help" emptyValue="Pick" /></Field>
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
`.trim()
|
|
201
|
+
|
|
202
|
+
const result = applyTransform(input)
|
|
203
|
+
expect(result).not.toBeNull()
|
|
204
|
+
expect(result).toContain("already has description")
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
it("adds warning when Select already has state and Field has state", () => {
|
|
208
|
+
const input = `
|
|
209
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
210
|
+
|
|
211
|
+
function Test() {
|
|
212
|
+
return (
|
|
213
|
+
<Field state="error"><Select state="success" emptyValue="Pick" /></Field>
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
`.trim()
|
|
217
|
+
|
|
218
|
+
const result = applyTransform(input)
|
|
219
|
+
expect(result).not.toBeNull()
|
|
220
|
+
expect(result).toContain("already has state")
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
describe("multiple children", () => {
|
|
225
|
+
it("adds comment to Select and leaves Field when Field has multiple children", () => {
|
|
226
|
+
const input = `
|
|
227
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
228
|
+
|
|
229
|
+
function Test() {
|
|
230
|
+
return (
|
|
231
|
+
<Field><Select emptyValue="Pick" /><button /></Field>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
`.trim()
|
|
235
|
+
|
|
236
|
+
const result = applyTransform(input)
|
|
237
|
+
expect(result).not.toBeNull()
|
|
238
|
+
expect(result).toContain("<Field")
|
|
239
|
+
expect(result).toContain(
|
|
240
|
+
"TODO: tapestry-migration (mergeFieldIntoSelect)"
|
|
241
|
+
)
|
|
242
|
+
expect(result).toContain("multiple children")
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
describe("non-Select child", () => {
|
|
247
|
+
it("returns null when Field contains only a non-Select child", () => {
|
|
248
|
+
const input = `
|
|
249
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
250
|
+
|
|
251
|
+
function Test() {
|
|
252
|
+
return (
|
|
253
|
+
<Field><textarea /></Field>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
`.trim()
|
|
257
|
+
|
|
258
|
+
const result = applyTransform(input)
|
|
259
|
+
expect(result).toBeNull()
|
|
260
|
+
})
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
describe("import cleanup", () => {
|
|
264
|
+
it("removes Field from import specifiers when all Fields are converted", () => {
|
|
265
|
+
const input = `
|
|
266
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
267
|
+
|
|
268
|
+
function Test() {
|
|
269
|
+
return (
|
|
270
|
+
<Field label="Name"><Select emptyValue="Pick" /></Field>
|
|
271
|
+
)
|
|
272
|
+
}
|
|
273
|
+
`.trim()
|
|
274
|
+
|
|
275
|
+
const result = applyTransform(input)
|
|
276
|
+
expect(result).not.toBeNull()
|
|
277
|
+
expect(result).not.toContain("Field")
|
|
278
|
+
expect(result).toContain("Select")
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it("removes entire import declaration when Field was the only specifier", () => {
|
|
282
|
+
const input = `
|
|
283
|
+
import { Field } from "@planningcenter/tapestry-react"
|
|
284
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
285
|
+
|
|
286
|
+
function Test() {
|
|
287
|
+
return (
|
|
288
|
+
<Field><Select emptyValue="Pick" /></Field>
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
`.trim()
|
|
292
|
+
|
|
293
|
+
const result = applyTransform(input)
|
|
294
|
+
expect(result).not.toBeNull()
|
|
295
|
+
expect(result).not.toContain("{ Field }")
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it("keeps Field in import when some Fields cannot be converted", () => {
|
|
299
|
+
const input = `
|
|
300
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
301
|
+
|
|
302
|
+
function Test() {
|
|
303
|
+
return (
|
|
304
|
+
<div>
|
|
305
|
+
<Field label="Name"><Select emptyValue="Pick" /></Field>
|
|
306
|
+
<Field><Select emptyValue="Pick" /><button /></Field>
|
|
307
|
+
</div>
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
`.trim()
|
|
311
|
+
|
|
312
|
+
const result = applyTransform(input)
|
|
313
|
+
expect(result).not.toBeNull()
|
|
314
|
+
expect(result).toContain("Field")
|
|
315
|
+
})
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
describe("full prop set", () => {
|
|
319
|
+
it("merges label, feedbackText, state='error' and flags helpContent", () => {
|
|
320
|
+
const input = `
|
|
321
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
322
|
+
|
|
323
|
+
function Test() {
|
|
324
|
+
return (
|
|
325
|
+
<Field label="Product" feedbackText="Required" state="error" helpContent="Help">
|
|
326
|
+
<Select emptyValue="Pick" />
|
|
327
|
+
</Field>
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
`.trim()
|
|
331
|
+
|
|
332
|
+
const result = applyTransform(input)
|
|
333
|
+
expect(result).not.toBeNull()
|
|
334
|
+
expect(result).not.toContain("<Field")
|
|
335
|
+
expect(result).toContain('label="Product"')
|
|
336
|
+
expect(result).toContain('description="Required"')
|
|
337
|
+
expect(result).toContain('state="error"')
|
|
338
|
+
expect(result).toContain("helpContent")
|
|
339
|
+
expect(result).toContain("not supported by Select")
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
describe("key prop handling", () => {
|
|
344
|
+
it("moves key from Field to Select when Select has no key", () => {
|
|
345
|
+
const input = `
|
|
346
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
347
|
+
|
|
348
|
+
function Test() {
|
|
349
|
+
return (
|
|
350
|
+
<Box>
|
|
351
|
+
<Field key="item-1" label="Name"><Select emptyValue="Pick" /></Field>
|
|
352
|
+
</Box>
|
|
353
|
+
)
|
|
354
|
+
}
|
|
355
|
+
`.trim()
|
|
356
|
+
|
|
357
|
+
const result = applyTransform(input)
|
|
358
|
+
expect(result).not.toBeNull()
|
|
359
|
+
expect(result).not.toContain("<Field")
|
|
360
|
+
expect(result).toContain('key="item-1"')
|
|
361
|
+
expect(result).toContain("<Select")
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it("keeps Select's key when both Field and Select have key", () => {
|
|
365
|
+
const input = `
|
|
366
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
367
|
+
|
|
368
|
+
function Test() {
|
|
369
|
+
return (
|
|
370
|
+
<Box>
|
|
371
|
+
<Field key="field-1" label="Name"><Select key="sel-1" emptyValue="Pick" /></Field>
|
|
372
|
+
</Box>
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
`.trim()
|
|
376
|
+
|
|
377
|
+
const result = applyTransform(input)
|
|
378
|
+
expect(result).not.toBeNull()
|
|
379
|
+
expect(result).not.toContain("<Field")
|
|
380
|
+
expect(result).toContain('key="sel-1"')
|
|
381
|
+
})
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
describe("spread props on Field", () => {
|
|
385
|
+
it("bails out with TODO comment when Field has spread props", () => {
|
|
386
|
+
const input = `
|
|
387
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
388
|
+
|
|
389
|
+
function Test() {
|
|
390
|
+
return (
|
|
391
|
+
<Field {...fieldProps}><Select emptyValue="Pick" /></Field>
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
`.trim()
|
|
395
|
+
|
|
396
|
+
const result = applyTransform(input)
|
|
397
|
+
expect(result).not.toBeNull()
|
|
398
|
+
expect(result).toContain("<Field")
|
|
399
|
+
expect(result).toContain(
|
|
400
|
+
"TODO: tapestry-migration (mergeFieldIntoSelect)"
|
|
401
|
+
)
|
|
402
|
+
expect(result).toContain("spread props")
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
it("bails out when Field has spread props mixed with regular props", () => {
|
|
406
|
+
const input = `
|
|
407
|
+
import { Field, Select } from "@planningcenter/tapestry-react"
|
|
408
|
+
|
|
409
|
+
function Test() {
|
|
410
|
+
return (
|
|
411
|
+
<Field label="Name" {...fieldProps}><Select emptyValue="Pick" /></Field>
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
`.trim()
|
|
415
|
+
|
|
416
|
+
const result = applyTransform(input)
|
|
417
|
+
expect(result).not.toBeNull()
|
|
418
|
+
expect(result).toContain("<Field")
|
|
419
|
+
expect(result).toContain("spread props")
|
|
420
|
+
})
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
describe("not from tapestry-react", () => {
|
|
424
|
+
it("returns null when Field is not imported from tapestry-react", () => {
|
|
425
|
+
const input = `
|
|
426
|
+
import { Field } from "some-other-library"
|
|
427
|
+
import { Select } from "@planningcenter/tapestry-react"
|
|
428
|
+
|
|
429
|
+
function Test() {
|
|
430
|
+
return (
|
|
431
|
+
<Field label="Name"><Select emptyValue="Pick" /></Field>
|
|
432
|
+
)
|
|
433
|
+
}
|
|
434
|
+
`.trim()
|
|
435
|
+
|
|
436
|
+
const result = applyTransform(input)
|
|
437
|
+
expect(result).toBeNull()
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
it("returns null when Select is not imported from tapestry-react", () => {
|
|
441
|
+
const input = `
|
|
442
|
+
import { Field } from "@planningcenter/tapestry-react"
|
|
443
|
+
import { Select } from "some-other-library"
|
|
444
|
+
|
|
445
|
+
function Test() {
|
|
446
|
+
return (
|
|
447
|
+
<Field label="Name"><Select emptyValue="Pick" /></Field>
|
|
448
|
+
)
|
|
449
|
+
}
|
|
450
|
+
`.trim()
|
|
451
|
+
|
|
452
|
+
const result = applyTransform(input)
|
|
453
|
+
expect(result).toBeNull()
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it("returns null when neither import exists", () => {
|
|
457
|
+
const input = `
|
|
458
|
+
import { Button } from "@planningcenter/tapestry-react"
|
|
459
|
+
|
|
460
|
+
function Test() {
|
|
461
|
+
return <Button label="Click" />
|
|
462
|
+
}
|
|
463
|
+
`.trim()
|
|
464
|
+
|
|
465
|
+
const result = applyTransform(input)
|
|
466
|
+
expect(result).toBeNull()
|
|
467
|
+
})
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
describe("aliased imports", () => {
|
|
471
|
+
it("handles aliased Field import", () => {
|
|
472
|
+
const input = `
|
|
473
|
+
import { Field as TapField, Select } from "@planningcenter/tapestry-react"
|
|
474
|
+
|
|
475
|
+
function Test() {
|
|
476
|
+
return (
|
|
477
|
+
<TapField label="Name"><Select emptyValue="Pick" /></TapField>
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
`.trim()
|
|
481
|
+
|
|
482
|
+
const result = applyTransform(input)
|
|
483
|
+
expect(result).not.toBeNull()
|
|
484
|
+
expect(result).not.toContain("<TapField")
|
|
485
|
+
expect(result).toContain('label="Name"')
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
it("handles aliased Select import", () => {
|
|
489
|
+
const input = `
|
|
490
|
+
import { Field, Select as TapSelect } from "@planningcenter/tapestry-react"
|
|
491
|
+
|
|
492
|
+
function Test() {
|
|
493
|
+
return (
|
|
494
|
+
<Field label="Name"><TapSelect emptyValue="Pick" /></Field>
|
|
495
|
+
)
|
|
496
|
+
}
|
|
497
|
+
`.trim()
|
|
498
|
+
|
|
499
|
+
const result = applyTransform(input)
|
|
500
|
+
expect(result).not.toBeNull()
|
|
501
|
+
expect(result).not.toContain("<Field")
|
|
502
|
+
expect(result).toContain('label="Name"')
|
|
503
|
+
expect(result).toContain("<TapSelect")
|
|
504
|
+
})
|
|
505
|
+
})
|
|
506
|
+
})
|