@planningcenter/tapestry-migration-cli 2.4.0-rc.10 → 2.4.0-rc.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/tapestry-migration-cli",
3
- "version": "2.4.0-rc.10",
3
+ "version": "2.4.0-rc.12",
4
4
  "description": "CLI tool for Tapestry migrations",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "cb64c1483123040f674d56065cb108dbb10ca985"
54
+ "gitHead": "e7660769921beb3848d31ed3733846bcb22e7159"
55
55
  }
@@ -4,9 +4,11 @@ import childrenToLabel from "./transforms/childrenToLabel"
4
4
  import convertStyleProps from "./transforms/convertStyleProps"
5
5
  import inlineMemberToKind from "./transforms/inlineMemberToKind"
6
6
  import inlinePropToKind from "./transforms/inlinePropToKind"
7
+ import moveLinkImport from "./transforms/moveLinkImport"
7
8
  import removeAs from "./transforms/removeAs"
8
9
  import reviewStyles from "./transforms/reviewStyles"
9
10
  import targetBlankToExternal from "./transforms/targetBlankToExternal"
11
+ import tooltipToWrapper from "./transforms/tooltipToWrapper"
10
12
  import toToHref from "./transforms/toToHref"
11
13
  import unsupportedProps from "./transforms/unsupportedProps"
12
14
 
@@ -17,6 +19,7 @@ const transform: Transform = (fileInfo, api, options) => {
17
19
  const transforms: Transform[] = [
18
20
  inlineMemberToKind,
19
21
  inlinePropToKind,
22
+ tooltipToWrapper,
20
23
  toToHref,
21
24
  targetBlankToExternal,
22
25
  removeAs,
@@ -24,6 +27,7 @@ const transform: Transform = (fileInfo, api, options) => {
24
27
  reviewStyles,
25
28
  convertStyleProps,
26
29
  unsupportedProps,
30
+ moveLinkImport,
27
31
  ]
28
32
 
29
33
  for (const individualTransform of transforms) {
@@ -0,0 +1,295 @@
1
+ import jscodeshift from "jscodeshift"
2
+ import { describe, expect, it } from "vitest"
3
+
4
+ import transform from "./moveLinkImport"
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("moveLinkImport transform", () => {
18
+ describe("basic transformations", () => {
19
+ it("should move Link import from tapestry-react to tapestry", () => {
20
+ const input = `
21
+ import { Link } from "@planningcenter/tapestry-react"
22
+
23
+ export default function Test() {
24
+ return <Link href="/test">Test</Link>
25
+ }
26
+ `.trim()
27
+
28
+ const expected = `
29
+ import { Link } from "@planningcenter/tapestry";
30
+
31
+ export default function Test() {
32
+ return <Link href="/test">Test</Link>
33
+ }
34
+ `.trim()
35
+
36
+ const result = applyTransform(input)
37
+ expect(result?.trim()).toBe(expected)
38
+ })
39
+
40
+ it("should handle multiple Link components", () => {
41
+ const input = `
42
+ import { Link } from "@planningcenter/tapestry-react"
43
+
44
+ export default function Test() {
45
+ return (
46
+ <div>
47
+ <Link href="/home">Home</Link>
48
+ <Link href="/about">About</Link>
49
+ </div>
50
+ )
51
+ }
52
+ `.trim()
53
+
54
+ const expected = `
55
+ import { Link } from "@planningcenter/tapestry";
56
+
57
+ export default function Test() {
58
+ return (
59
+ <div>
60
+ <Link href="/home">Home</Link>
61
+ <Link href="/about">About</Link>
62
+ </div>
63
+ )
64
+ }
65
+ `.trim()
66
+
67
+ const result = applyTransform(input)
68
+ expect(result?.trim()).toBe(expected)
69
+ })
70
+
71
+ it("should preserve other imports from tapestry-react", () => {
72
+ const input = `
73
+ import { Link, Button, Input } from "@planningcenter/tapestry-react"
74
+
75
+ export default function Test() {
76
+ return <Link href="/test">Test</Link>
77
+ }
78
+ `.trim()
79
+
80
+ const result = applyTransform(input)
81
+ expect(result).toContain(
82
+ 'import { Button, Input } from "@planningcenter/tapestry-react"'
83
+ )
84
+ expect(result).toContain(
85
+ 'import { Link } from "@planningcenter/tapestry"'
86
+ )
87
+ expect(result).toContain('<Link href="/test">Test</Link>')
88
+ expect(result).not.toContain(
89
+ 'Link, Button } from "@planningcenter/tapestry-react"'
90
+ )
91
+ })
92
+ })
93
+
94
+ describe("import conflict handling", () => {
95
+ it("should use alias when Link already imported from tapestry", () => {
96
+ const input = `
97
+ import { Link } from "@planningcenter/tapestry"
98
+ import { Link as ReactLink } from "@planningcenter/tapestry-react"
99
+
100
+ export default function Test() {
101
+ return <ReactLink href="/test">Test</ReactLink>
102
+ }
103
+ `.trim()
104
+
105
+ const result = applyTransform(input)
106
+ expect(result).toContain(
107
+ 'import { Link } from "@planningcenter/tapestry"'
108
+ )
109
+ expect(result).toContain('<Link href="/test">Test</Link>')
110
+ expect(result).not.toContain('from "@planningcenter/tapestry-react"')
111
+ expect(result).not.toContain("ReactLink")
112
+ })
113
+
114
+ it("should handle existing tapestry import with other components", () => {
115
+ const input = `
116
+ import { Button, Input } from "@planningcenter/tapestry"
117
+ import { Link } from "@planningcenter/tapestry-react"
118
+
119
+ export default function Test() {
120
+ return <Link href="/test">Test</Link>
121
+ }
122
+ `.trim()
123
+
124
+ const result = applyTransform(input)
125
+ expect(result).toContain(
126
+ 'import { Button, Input, Link } from "@planningcenter/tapestry"'
127
+ )
128
+ expect(result).toContain('<Link href="/test">Test</Link>')
129
+ expect(result).not.toContain('from "@planningcenter/tapestry-react"')
130
+ })
131
+ })
132
+
133
+ describe("edge cases", () => {
134
+ it("should not transform if Link is not imported from tapestry-react", () => {
135
+ const input = `
136
+ import { Button } from "@planningcenter/tapestry-react"
137
+
138
+ export default function Test() {
139
+ return <Button>Test</Button>
140
+ }
141
+ `.trim()
142
+
143
+ const result = applyTransform(input)
144
+ expect(result).toBe(null)
145
+ })
146
+
147
+ it("should handle Link with aliased import", () => {
148
+ const input = `
149
+ import { Link as ReactLink } from "@planningcenter/tapestry-react"
150
+
151
+ export default function Test() {
152
+ return <ReactLink href="/test">Test</ReactLink>
153
+ }
154
+ `.trim()
155
+
156
+ const result = applyTransform(input)
157
+ expect(result).toContain(
158
+ 'import { Link } from "@planningcenter/tapestry"'
159
+ )
160
+ expect(result).toContain('<Link href="/test">Test</Link>')
161
+ expect(result).not.toContain("ReactLink")
162
+ expect(result).not.toContain('from "@planningcenter/tapestry-react"')
163
+ })
164
+
165
+ it("should handle self-closing Link components", () => {
166
+ const input = `
167
+ import { Link } from "@planningcenter/tapestry-react"
168
+
169
+ export default function Test() {
170
+ return <Link href="/test" />
171
+ }
172
+ `.trim()
173
+
174
+ const expected = `
175
+ import { Link } from "@planningcenter/tapestry";
176
+
177
+ export default function Test() {
178
+ return <Link href="/test" />
179
+ }
180
+ `.trim()
181
+
182
+ const result = applyTransform(input)
183
+ expect(result?.trim()).toBe(expected)
184
+ })
185
+
186
+ it("should handle Link with props", () => {
187
+ const input = `
188
+ import { Link } from "@planningcenter/tapestry-react"
189
+
190
+ export default function Test() {
191
+ return <Link href="/test" kind="primary" onClick={handleClick}>Test</Link>
192
+ }
193
+ `.trim()
194
+
195
+ const result = applyTransform(input)
196
+ expect(result).toContain(
197
+ 'import { Link } from "@planningcenter/tapestry"'
198
+ )
199
+ expect(result).toContain('kind="primary"')
200
+ expect(result).toContain("onClick={handleClick}")
201
+ expect(result).not.toContain('from "@planningcenter/tapestry-react"')
202
+ })
203
+ })
204
+
205
+ describe("no changes scenarios", () => {
206
+ it("should return null when no Link import exists", () => {
207
+ const input = `
208
+ import React from "react"
209
+
210
+ export default function Test() {
211
+ return <div>Hello</div>
212
+ }
213
+ `.trim()
214
+
215
+ const result = applyTransform(input)
216
+ expect(result).toBe(null)
217
+ })
218
+
219
+ it("should return null when Link already imported from tapestry", () => {
220
+ const input = `
221
+ import { Link } from "@planningcenter/tapestry"
222
+
223
+ export default function Test() {
224
+ return <Link href="/test">Test</Link>
225
+ }
226
+ `.trim()
227
+
228
+ const result = applyTransform(input)
229
+ expect(result).toBe(null)
230
+ })
231
+
232
+ it("should return null for empty file", () => {
233
+ const result = applyTransform("")
234
+ expect(result).toBe(null)
235
+ })
236
+ })
237
+
238
+ describe("complex scenarios", () => {
239
+ it("should handle mixed imports and multiple components", () => {
240
+ const input = `
241
+ import React from "react"
242
+ import { Link, Button } from "@planningcenter/tapestry-react"
243
+ import { Input } from "@planningcenter/tapestry"
244
+
245
+ export default function Test() {
246
+ return (
247
+ <form>
248
+ <Input name="email" />
249
+ <Button type="submit">Submit</Button>
250
+ <Link href="/cancel">Cancel</Link>
251
+ </form>
252
+ )
253
+ }
254
+ `.trim()
255
+
256
+ const result = applyTransform(input)
257
+ expect(result).toContain(
258
+ 'import { Button } from "@planningcenter/tapestry-react"'
259
+ )
260
+ expect(result).toContain(
261
+ 'import { Input, Link } from "@planningcenter/tapestry"'
262
+ )
263
+ expect(result).toContain('<Button type="submit">Submit</Button>')
264
+ expect(result).toContain('<Link href="/cancel">Cancel</Link>')
265
+ expect(result).not.toContain(
266
+ 'Link, Button } from "@planningcenter/tapestry-react"'
267
+ )
268
+ })
269
+
270
+ it("should handle Link usage in JSX expressions", () => {
271
+ const input = `
272
+ import { Link } from "@planningcenter/tapestry-react"
273
+
274
+ export default function Test({ showLink }) {
275
+ return (
276
+ <div>
277
+ {showLink && <Link href="/conditional">Conditional</Link>}
278
+ {items.map(item => <Link key={item.id} href={item.url}>{item.name}</Link>)}
279
+ </div>
280
+ )
281
+ }
282
+ `.trim()
283
+
284
+ const result = applyTransform(input)
285
+ expect(result).toContain(
286
+ 'import { Link } from "@planningcenter/tapestry"'
287
+ )
288
+ expect(result).toContain('<Link href="/conditional">Conditional</Link>')
289
+ expect(result).toContain(
290
+ "<Link key={item.id} href={item.url}>{item.name}</Link>"
291
+ )
292
+ expect(result).not.toContain('from "@planningcenter/tapestry-react"')
293
+ })
294
+ })
295
+ })
@@ -0,0 +1,14 @@
1
+ import { Transform } from "jscodeshift"
2
+
3
+ import { componentTransformFactory } from "../../shared/transformFactories/componentTransformFactory"
4
+
5
+ const transform: Transform = componentTransformFactory({
6
+ condition: () => true,
7
+ conflictAlias: "TLink",
8
+ fromComponent: "Link",
9
+ fromPackage: "@planningcenter/tapestry-react",
10
+ toComponent: "Link",
11
+ toPackage: "@planningcenter/tapestry",
12
+ })
13
+
14
+ export default transform
@@ -0,0 +1,392 @@
1
+ import jscodeshift from "jscodeshift"
2
+ import { describe, expect, it } from "vitest"
3
+
4
+ import transform from "./tooltipToWrapper"
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("tooltipToWrapper transform", () => {
18
+ describe("basic transformations", () => {
19
+ it("should wrap Link with tooltip string in Tooltip component", () => {
20
+ const input = `
21
+ import { Link } from "@planningcenter/tapestry-react"
22
+
23
+ export default function Test() {
24
+ return <Link href="/save" tooltip={{ title: "Save this item" }}>Save</Link>
25
+ }
26
+ `.trim()
27
+
28
+ const result = applyTransform(input)
29
+
30
+ expect(result).toContain(
31
+ 'import { Link, Tooltip } from "@planningcenter/tapestry-react"'
32
+ )
33
+ expect(result).toContain('<Tooltip {...{ title: "Save this item" }}>')
34
+ expect(result).toContain('<Link href="/save">Save</Link>')
35
+ expect(result).toContain("</Tooltip>")
36
+ expect(result).not.toContain("tooltip=")
37
+ })
38
+
39
+ it("should handle tooltip with JSX expression containing string literal", () => {
40
+ const input = `
41
+ import { Link } from "@planningcenter/tapestry-react"
42
+
43
+ export default function Test() {
44
+ return <Link href="/save" tooltip={{ title: "Save this item" }}>Save</Link>
45
+ }
46
+ `.trim()
47
+
48
+ const result = applyTransform(input)
49
+
50
+ expect(result).toContain('<Tooltip {...{ title: "Save this item" }}>')
51
+ expect(result).toContain('<Link href="/save">Save</Link>')
52
+ expect(result).not.toContain("tooltip=")
53
+ })
54
+
55
+ it("should handle tooltip with object expression as spread", () => {
56
+ const input = `
57
+ import { Link } from "@planningcenter/tapestry-react"
58
+
59
+ export default function Test() {
60
+ return <Link href="/save" tooltip={{text: "Save", placement: "top"}}>Save</Link>
61
+ }
62
+ `.trim()
63
+
64
+ const result = applyTransform(input)
65
+
66
+ expect(result).toContain(
67
+ '<Tooltip {...{text: "Save", placement: "top"}}>'
68
+ )
69
+ expect(result).toContain('<Link href="/save">Save</Link>')
70
+ expect(result).not.toContain("tooltip=")
71
+ })
72
+
73
+ it("should preserve other Link attributes", () => {
74
+ const input = `
75
+ import { Link } from "@planningcenter/tapestry-react"
76
+
77
+ export default function Test() {
78
+ return <Link href="/help" tooltip={{title: "Help"}} kind="primary" onClick={handler}>Help</Link>
79
+ }
80
+ `.trim()
81
+
82
+ const result = applyTransform(input)
83
+
84
+ expect(result).toContain('<Tooltip {...{title: "Help"}}>')
85
+ expect(result).toContain(
86
+ '<Link href="/help" kind="primary" onClick={handler}>Help</Link>'
87
+ )
88
+ expect(result).not.toContain("tooltip=")
89
+ })
90
+
91
+ it("should handle self-closing Link with tooltip", () => {
92
+ const input = `
93
+ import { Link } from "@planningcenter/tapestry-react"
94
+
95
+ export default function Test() {
96
+ return <Link href="/icon" tooltip={{title: "Icon link"}} />
97
+ }
98
+ `.trim()
99
+
100
+ const result = applyTransform(input)
101
+
102
+ expect(result).toContain('<Tooltip {...{title: "Icon link"}}>')
103
+ expect(result).toContain('<Link href="/icon" />')
104
+ expect(result).toContain("</Tooltip>")
105
+ expect(result).not.toContain("tooltip=")
106
+ })
107
+ })
108
+
109
+ describe("import management", () => {
110
+ it("should add Tooltip to existing tapestry-react import", () => {
111
+ const input = `
112
+ import { Link, Button } from "@planningcenter/tapestry-react"
113
+
114
+ export default function Test() {
115
+ return <Link href="/save" tooltip={{title: "Save"}}>Save</Link>
116
+ }
117
+ `.trim()
118
+
119
+ const result = applyTransform(input)
120
+
121
+ expect(result).toContain(
122
+ 'import { Link, Button, Tooltip } from "@planningcenter/tapestry-react"'
123
+ )
124
+ expect(result).toContain('<Tooltip {...{title: "Save"}}>')
125
+ })
126
+
127
+ it("should not add duplicate Tooltip import", () => {
128
+ const input = `
129
+ import { Link, Tooltip } from "@planningcenter/tapestry-react"
130
+
131
+ export default function Test() {
132
+ return <Link href="/save" tooltip={{title: "Save"}}>Save</Link>
133
+ }
134
+ `.trim()
135
+
136
+ const result = applyTransform(input)
137
+
138
+ const tooltipImports = (result?.match(/import.*Tooltip.*from/g) || [])
139
+ .length
140
+ expect(tooltipImports).toBe(1)
141
+ expect(result).toContain(
142
+ 'import { Link, Tooltip } from "@planningcenter/tapestry-react"'
143
+ )
144
+ })
145
+
146
+ it("should create new tapestry-react import when none exists", () => {
147
+ const input = `
148
+ import React from "react"
149
+ import { Link } from "@planningcenter/tapestry-react"
150
+
151
+ export default function Test() {
152
+ return <Link href="/save" tooltip={{title: "Save"}}>Save</Link>
153
+ }
154
+ `.trim()
155
+
156
+ const result = applyTransform(input)
157
+
158
+ expect(result).toContain(
159
+ 'import { Link, Tooltip } from "@planningcenter/tapestry-react"'
160
+ )
161
+ })
162
+
163
+ it("should handle empty imports scenario", () => {
164
+ const input = `
165
+ import { Link } from "@planningcenter/tapestry-react"
166
+ export default function Test() {
167
+ return <Link href="/save" tooltip={{title: "Save"}}>Save</Link>
168
+ }
169
+ `.trim()
170
+
171
+ const result = applyTransform(input)
172
+
173
+ expect(result).toContain(
174
+ 'import { Link, Tooltip } from "@planningcenter/tapestry-react"'
175
+ )
176
+ })
177
+ })
178
+
179
+ describe("multiple elements", () => {
180
+ it("should handle multiple Links with tooltips", () => {
181
+ const input = `
182
+ import { Link } from "@planningcenter/tapestry-react"
183
+
184
+ export default function Test() {
185
+ return (
186
+ <div>
187
+ <Link href="/save" tooltip={{title: "Save the document"}}>Save</Link>
188
+ <Link href="/cancel" tooltip={{title: "Cancel operation"}}>Cancel</Link>
189
+ </div>
190
+ )
191
+ }
192
+ `.trim()
193
+
194
+ const result = applyTransform(input)
195
+
196
+ expect(result).toContain(
197
+ 'import { Link, Tooltip } from "@planningcenter/tapestry-react"'
198
+ )
199
+ expect(result).toContain('<Tooltip {...{title: "Save the document"}}>')
200
+ expect(result).toContain('<Tooltip {...{title: "Cancel operation"}}>')
201
+ expect(result).not.toContain("tooltip=")
202
+ })
203
+
204
+ it("should only transform Links with tooltip attribute", () => {
205
+ const input = `
206
+ import { Link } from "@planningcenter/tapestry-react"
207
+
208
+ export default function Test() {
209
+ return (
210
+ <div>
211
+ <Link href="/with" tooltip={{title: "Has tooltip"}}>With Tooltip</Link>
212
+ <Link href="/without">Without Tooltip</Link>
213
+ </div>
214
+ )
215
+ }
216
+ `.trim()
217
+
218
+ const result = applyTransform(input)
219
+
220
+ expect(result).toContain('<Tooltip {...{title: "Has tooltip"}}>')
221
+ expect(result).toContain('<Link href="/with">With Tooltip</Link>')
222
+ expect(result).toContain('<Link href="/without">Without Tooltip</Link>')
223
+ const tooltipCount = (result?.match(/<Tooltip/g) || []).length
224
+ expect(tooltipCount).toBe(1)
225
+ })
226
+ })
227
+
228
+ describe("edge cases", () => {
229
+ it("should return null when Link is not imported from tapestry-react", () => {
230
+ const input = `
231
+ import { Button } from "@planningcenter/tapestry-react"
232
+ import { Link } from "other-library"
233
+
234
+ export default function Test() {
235
+ return <Link href="/save" tooltip={{title: "Save"}}>Save</Link>
236
+ }
237
+ `.trim()
238
+
239
+ const result = applyTransform(input)
240
+ expect(result).toBe(null)
241
+ })
242
+
243
+ it("should return null when no Link is imported", () => {
244
+ const input = `
245
+ import React from "react"
246
+
247
+ export default function Test() {
248
+ return <div>No links here</div>
249
+ }
250
+ `.trim()
251
+
252
+ const result = applyTransform(input)
253
+ expect(result).toBe(null)
254
+ })
255
+
256
+ it("should return null when no tooltips are present", () => {
257
+ const input = `
258
+ import { Link } from "@planningcenter/tapestry-react"
259
+
260
+ export default function Test() {
261
+ return <Link href="/primary" kind="primary">Save</Link>
262
+ }
263
+ `.trim()
264
+
265
+ const result = applyTransform(input)
266
+ expect(result).toBe(null)
267
+ })
268
+
269
+ it("should handle aliased Link import", () => {
270
+ const input = `
271
+ import { Link as TapestryLink } from "@planningcenter/tapestry-react"
272
+
273
+ export default function Test() {
274
+ return <TapestryLink href="/save" tooltip={{title: "Save item"}}>Save</TapestryLink>
275
+ }
276
+ `.trim()
277
+
278
+ const result = applyTransform(input)
279
+
280
+ expect(result).toContain(
281
+ 'import { Link as TapestryLink, Tooltip } from "@planningcenter/tapestry-react"'
282
+ )
283
+ expect(result).toContain('<Tooltip {...{title: "Save item"}}>')
284
+ expect(result).toContain('<TapestryLink href="/save">Save</TapestryLink>')
285
+ expect(result).not.toContain("tooltip=")
286
+ })
287
+
288
+ it("should handle complex JSX expressions", () => {
289
+ const input = `
290
+ import { Link } from "@planningcenter/tapestry-react"
291
+
292
+ export default function Test({ items }) {
293
+ return (
294
+ <div>
295
+ {items.map(item => (
296
+ <Link key={item.id} href={item.url} tooltip={\`Save \${item.name}\`} onClick={() => save(item)}>
297
+ {item.name}
298
+ </Link>
299
+ ))}
300
+ </div>
301
+ )
302
+ }
303
+ `.trim()
304
+
305
+ const result = applyTransform(input)
306
+
307
+ expect(result).toContain(
308
+ "<Tooltip key={item.id} {...`Save ${item.name}`}>"
309
+ )
310
+ expect(result).toContain(
311
+ "<Link href={item.url} onClick={() => save(item)}>"
312
+ )
313
+ expect(result).not.toContain("tooltip=")
314
+ })
315
+
316
+ it("should handle empty tooltip attribute", () => {
317
+ const input = `
318
+ import { Link } from "@planningcenter/tapestry-react"
319
+
320
+ export default function Test() {
321
+ return <Link href="/save" tooltip>Save</Link>
322
+ }
323
+ `.trim()
324
+
325
+ const result = applyTransform(input)
326
+
327
+ expect(result).toContain("<Tooltip>")
328
+ expect(result).toContain('<Link href="/save">Save</Link>')
329
+ expect(result).toContain("</Tooltip>")
330
+ expect(result).not.toContain("tooltip")
331
+ })
332
+ })
333
+
334
+ describe("complex scenarios", () => {
335
+ it("should handle nested JSX and mixed components", () => {
336
+ const input = `
337
+ import React from "react"
338
+ import { Link, Button } from "@planningcenter/tapestry-react"
339
+
340
+ export default function Test() {
341
+ return (
342
+ <form>
343
+ <div className="actions">
344
+ <Link href="/submit" tooltip={{title: "Submit the form"}} kind="primary">
345
+ Submit
346
+ </Link>
347
+ <Button onClick={cancel}>Cancel</Button>
348
+ <Link href="/reset" tooltip={{text: "Reset form", placement: "bottom"}}>
349
+ Reset
350
+ </Link>
351
+ </div>
352
+ </form>
353
+ )
354
+ }
355
+ `.trim()
356
+
357
+ const result = applyTransform(input)
358
+
359
+ expect(result).toContain(
360
+ 'import { Link, Button, Tooltip } from "@planningcenter/tapestry-react"'
361
+ )
362
+ expect(result).toContain('<Tooltip {...{title: "Submit the form"}}>')
363
+ expect(result).toContain('href="/submit" kind="primary"')
364
+ expect(result).toContain("Submit")
365
+ expect(result).toContain(
366
+ '<Tooltip {...{text: "Reset form", placement: "bottom"}}>'
367
+ )
368
+ expect(result).toContain('href="/reset"')
369
+ expect(result).toContain("Reset")
370
+ expect(result).toContain("<Button onClick={cancel}>Cancel</Button>")
371
+ expect(result).not.toContain("tooltip=")
372
+ })
373
+ })
374
+
375
+ it("converts tooltip with string literal to title prop", () => {
376
+ const input = `
377
+ import { Link } from "@planningcenter/tapestry-react"
378
+
379
+ export default function Test() {
380
+ return <Link href="/click" tooltip="Click me">Click</Link>
381
+ }
382
+ `.trim()
383
+
384
+ const result = applyTransform(input)!
385
+
386
+ expect(result.replace(/(\s*)?\n(\s*)?/gm, " ")).toContain(
387
+ '<Tooltip {...{ title: "Click me" }}>'
388
+ )
389
+ expect(result).toContain('<Link href="/click">Click</Link>')
390
+ expect(result).not.toContain("tooltip=")
391
+ })
392
+ })
@@ -0,0 +1,35 @@
1
+ import { createWrapper } from "../../shared/actions/createWrapper"
2
+ import { getAttributeValueAsProps } from "../../shared/actions/getAttributeValueAsProps"
3
+ import { removeAttribute } from "../../shared/actions/removeAttribute"
4
+ import { hasAttribute } from "../../shared/conditions/hasAttribute"
5
+ import { attributeTransformFactory } from "../../shared/transformFactories/attributeTransformFactory"
6
+
7
+ const transform = attributeTransformFactory({
8
+ condition: hasAttribute("tooltip"),
9
+ targetComponent: "Link",
10
+ targetPackage: "@planningcenter/tapestry-react",
11
+ transform: (element, { j, source }) => {
12
+ const wrapperProps = getAttributeValueAsProps({
13
+ element,
14
+ j,
15
+ name: "tooltip",
16
+ stringValueKey: "title",
17
+ })
18
+
19
+ removeAttribute("tooltip", { element, j, source })
20
+
21
+ createWrapper({
22
+ conflictAlias: "TRTooltip",
23
+ element,
24
+ j,
25
+ source,
26
+ wrapperName: "Tooltip",
27
+ wrapperPackage: "@planningcenter/tapestry-react",
28
+ wrapperProps,
29
+ })
30
+
31
+ return true
32
+ },
33
+ })
34
+
35
+ export default transform