@sproutsocial/seeds-react-badge 1.0.6 → 2.0.1
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/codemods/__tests__/badge-1.x-to-2.x.test.ts +406 -0
- package/codemods/badge-1.x-to-2.x.ts +489 -0
- package/dist/codemods/badge-1.x-to-2.x.d.ts +2 -0
- package/dist/codemods/badge-1.x-to-2.x.js +285 -0
- package/dist/codemods/badge-1.x-to-2.x.js.map +1 -0
- package/dist/esm/index.js +51 -65
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +2 -9
- package/dist/index.d.ts +2 -9
- package/dist/index.js +51 -65
- package/dist/index.js.map +1 -1
- package/package.json +20 -4
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -4
- package/.turbo/turbo-build.log +0 -21
- package/CHANGELOG.md +0 -50
- package/jest.config.js +0 -9
- package/src/Badge.stories.tsx +0 -83
- package/src/Badge.tsx +0 -55
- package/src/BadgeTypes.ts +0 -30
- package/src/__tests__/features.test.tsx +0 -94
- package/src/__tests__/types.test.tsx +0 -28
- package/src/constants.ts +0 -64
- package/src/index.ts +0 -6
- package/src/styles.ts +0 -36
- package/tsconfig.json +0 -15
- package/tsup.config.ts +0 -12
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
// @ts-expect-error - jscodeshift/dist/testUtils doesn't have type definitions
|
|
2
|
+
import { defineInlineTest } from "jscodeshift/dist/testUtils";
|
|
3
|
+
|
|
4
|
+
jest.autoMockOff();
|
|
5
|
+
|
|
6
|
+
// Import the codemod transformer
|
|
7
|
+
// The codemod uses module.exports because jscodeshift expects CommonJS
|
|
8
|
+
// We use require() because ES module imports don't work well with CommonJS module.exports
|
|
9
|
+
// This is consistent with other codemod tests in the codebase
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
11
|
+
const transform = require("../badge-1.x-to-2.x");
|
|
12
|
+
|
|
13
|
+
describe("badge-1.x-to-2.x codemod", () => {
|
|
14
|
+
function createTest(
|
|
15
|
+
testName: string,
|
|
16
|
+
input: string,
|
|
17
|
+
output: string,
|
|
18
|
+
options: Record<string, unknown> = {}
|
|
19
|
+
) {
|
|
20
|
+
return defineInlineTest(
|
|
21
|
+
transform,
|
|
22
|
+
{ quote: "single", ...options },
|
|
23
|
+
input,
|
|
24
|
+
output,
|
|
25
|
+
testName
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("Size transformation", () => {
|
|
30
|
+
createTest(
|
|
31
|
+
"Replace size='default' with size='large'",
|
|
32
|
+
`
|
|
33
|
+
import {Badge} from '@sproutsocial/racine';
|
|
34
|
+
<Badge size='default' />
|
|
35
|
+
`,
|
|
36
|
+
`
|
|
37
|
+
import {Badge} from '@sproutsocial/racine';
|
|
38
|
+
<Badge size='large' />
|
|
39
|
+
`
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
createTest(
|
|
43
|
+
"No change for size='small'",
|
|
44
|
+
`
|
|
45
|
+
import {Badge} from '@sproutsocial/racine';
|
|
46
|
+
<Badge size='small' />
|
|
47
|
+
`,
|
|
48
|
+
`
|
|
49
|
+
import {Badge} from '@sproutsocial/racine';
|
|
50
|
+
<Badge size='small' />
|
|
51
|
+
`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
createTest(
|
|
55
|
+
"No change for size='large'",
|
|
56
|
+
`
|
|
57
|
+
import {Badge} from '@sproutsocial/racine';
|
|
58
|
+
<Badge size='large' />
|
|
59
|
+
`,
|
|
60
|
+
`
|
|
61
|
+
import {Badge} from '@sproutsocial/racine';
|
|
62
|
+
<Badge size='large' />
|
|
63
|
+
`
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("Type to badgeColor transformation", () => {
|
|
68
|
+
createTest(
|
|
69
|
+
"Replace type='passive' with badgeColor='neutral'",
|
|
70
|
+
`
|
|
71
|
+
import {Badge} from '@sproutsocial/racine';
|
|
72
|
+
<Badge type='passive' />
|
|
73
|
+
`,
|
|
74
|
+
`
|
|
75
|
+
import {Badge} from '@sproutsocial/racine';
|
|
76
|
+
<Badge badgeColor='neutral' />
|
|
77
|
+
`
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
createTest(
|
|
81
|
+
"Replace type='default' with badgeColor='purple'",
|
|
82
|
+
`
|
|
83
|
+
import {Badge} from '@sproutsocial/racine';
|
|
84
|
+
<Badge type='default' />
|
|
85
|
+
`,
|
|
86
|
+
`
|
|
87
|
+
import {Badge} from '@sproutsocial/racine';
|
|
88
|
+
<Badge badgeColor='purple' />
|
|
89
|
+
`
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
createTest(
|
|
93
|
+
"Replace type='primary' with badgeColor='blue'",
|
|
94
|
+
`
|
|
95
|
+
import {Badge} from '@sproutsocial/racine';
|
|
96
|
+
<Badge type='primary' />
|
|
97
|
+
`,
|
|
98
|
+
`
|
|
99
|
+
import {Badge} from '@sproutsocial/racine';
|
|
100
|
+
<Badge badgeColor='blue' />
|
|
101
|
+
`
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
createTest(
|
|
105
|
+
"Replace type='secondary' with badgeColor='yellow'",
|
|
106
|
+
`
|
|
107
|
+
import {Badge} from '@sproutsocial/racine';
|
|
108
|
+
<Badge type='secondary' />
|
|
109
|
+
`,
|
|
110
|
+
`
|
|
111
|
+
import {Badge} from '@sproutsocial/racine';
|
|
112
|
+
<Badge badgeColor='yellow' />
|
|
113
|
+
`
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
createTest(
|
|
117
|
+
"Replace type='secondary' with badgeColor='yellow' when other attributes are present",
|
|
118
|
+
`
|
|
119
|
+
import {Badge} from '@sproutsocial/racine';
|
|
120
|
+
<Badge type='secondary' position='relative'><Icon size='mini' name='circle-x-solid' /></Badge>
|
|
121
|
+
`,
|
|
122
|
+
`
|
|
123
|
+
import {Badge} from '@sproutsocial/racine';
|
|
124
|
+
<Badge position='relative' badgeColor='yellow'><Icon size='mini' name='circle-x-solid' /></Badge>
|
|
125
|
+
`
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
createTest(
|
|
129
|
+
"Replace type='approval' with badgeColor='orange'",
|
|
130
|
+
`
|
|
131
|
+
import {Badge} from '@sproutsocial/racine';
|
|
132
|
+
<Badge type='approval' />
|
|
133
|
+
`,
|
|
134
|
+
`
|
|
135
|
+
import {Badge} from '@sproutsocial/racine';
|
|
136
|
+
<Badge badgeColor='orange' />
|
|
137
|
+
`
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
createTest(
|
|
141
|
+
"Replace type='suggestion' with badgeColor='blue'",
|
|
142
|
+
`
|
|
143
|
+
import {Badge} from '@sproutsocial/racine';
|
|
144
|
+
<Badge type='suggestion' />
|
|
145
|
+
`,
|
|
146
|
+
`
|
|
147
|
+
import {Badge} from '@sproutsocial/racine';
|
|
148
|
+
<Badge badgeColor='blue' />
|
|
149
|
+
`
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
createTest(
|
|
153
|
+
"Replace type='common' with badgeColor='aqua' and add TODO",
|
|
154
|
+
`
|
|
155
|
+
import {Badge} from '@sproutsocial/racine';
|
|
156
|
+
<Badge type='common' />
|
|
157
|
+
`,
|
|
158
|
+
`
|
|
159
|
+
import {Badge} from '@sproutsocial/racine';
|
|
160
|
+
/* TODO (badge-1.x-to-2.x codemod): type="common" mapped to badgeColor="aqua", but colors.container.background.decorative.aqua does not match original colors.aqua.600. Verify color match. */
|
|
161
|
+
<Badge badgeColor='aqua' />;
|
|
162
|
+
`
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
createTest(
|
|
166
|
+
"Keep existing badgeColor when type is also present",
|
|
167
|
+
`
|
|
168
|
+
import {Badge} from '@sproutsocial/racine';
|
|
169
|
+
<Badge type='passive' badgeColor='blue' />
|
|
170
|
+
`,
|
|
171
|
+
`
|
|
172
|
+
import {Badge} from '@sproutsocial/racine';
|
|
173
|
+
<Badge badgeColor='blue' />
|
|
174
|
+
`
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
createTest(
|
|
178
|
+
"Keep existing badgeColor when type is also present (badgeColor first)",
|
|
179
|
+
`
|
|
180
|
+
import {Badge} from '@sproutsocial/racine';
|
|
181
|
+
<Badge badgeColor='blue' type='passive' />
|
|
182
|
+
`,
|
|
183
|
+
`
|
|
184
|
+
import {Badge} from '@sproutsocial/racine';
|
|
185
|
+
<Badge badgeColor='blue' />
|
|
186
|
+
`
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe("Dynamic type values", () => {
|
|
191
|
+
createTest(
|
|
192
|
+
"Add TODO for dynamic type value",
|
|
193
|
+
`
|
|
194
|
+
import {Badge} from '@sproutsocial/racine';
|
|
195
|
+
<Badge type={getBadgeColor(id)} />
|
|
196
|
+
`,
|
|
197
|
+
`
|
|
198
|
+
import {Badge} from '@sproutsocial/racine';
|
|
199
|
+
/* TODO (badge-1.x-to-2.x codemod): Update function/variable to return badgeColor values instead of type values. See type-to-badgeColor mapping: passive→neutral, default→purple, primary→blue, secondary→yellow, approval→orange, suggestion→blue, common→aqua. */
|
|
200
|
+
<Badge />;
|
|
201
|
+
`
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
createTest(
|
|
205
|
+
"Add TODO for variable type",
|
|
206
|
+
`
|
|
207
|
+
import {Badge} from '@sproutsocial/racine';
|
|
208
|
+
<Badge type={badgeType} />
|
|
209
|
+
`,
|
|
210
|
+
`
|
|
211
|
+
import {Badge} from '@sproutsocial/racine';
|
|
212
|
+
/* TODO (badge-1.x-to-2.x codemod): Update function/variable to return badgeColor values instead of type values. See type-to-badgeColor mapping: passive→neutral, default→purple, primary→blue, secondary→yellow, approval→orange, suggestion→blue, common→aqua. */
|
|
213
|
+
<Badge />;
|
|
214
|
+
`
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
createTest(
|
|
218
|
+
"Add TODO for dynamic type in nested JSX",
|
|
219
|
+
`
|
|
220
|
+
import {Badge, Tooltip} from '@sproutsocial/racine';
|
|
221
|
+
const badgeType = 'secondary';
|
|
222
|
+
<Tooltip content="test">
|
|
223
|
+
<Badge type={badgeType} />
|
|
224
|
+
</Tooltip>
|
|
225
|
+
`,
|
|
226
|
+
`
|
|
227
|
+
import {Badge, Tooltip} from '@sproutsocial/racine';
|
|
228
|
+
const badgeType = 'secondary';
|
|
229
|
+
/* TODO (badge-1.x-to-2.x codemod): Update function/variable to return badgeColor values instead of type values. See type-to-badgeColor mapping: passive→neutral, default→purple, primary→blue, secondary→yellow, approval→orange, suggestion→blue, common→aqua. */
|
|
230
|
+
<Tooltip content="test">
|
|
231
|
+
<Badge />
|
|
232
|
+
</Tooltip>;
|
|
233
|
+
`
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("Text prop to children", () => {
|
|
238
|
+
createTest(
|
|
239
|
+
"Convert text prop string to children",
|
|
240
|
+
`
|
|
241
|
+
import {Badge} from '@sproutsocial/racine';
|
|
242
|
+
<Badge text='Label' />
|
|
243
|
+
`,
|
|
244
|
+
`
|
|
245
|
+
import {Badge} from '@sproutsocial/racine';
|
|
246
|
+
<Badge>Label</Badge>
|
|
247
|
+
`
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
createTest(
|
|
251
|
+
"Convert text prop variable to children",
|
|
252
|
+
`
|
|
253
|
+
import {Badge} from '@sproutsocial/racine';
|
|
254
|
+
<Badge text={labelText} />
|
|
255
|
+
`,
|
|
256
|
+
`
|
|
257
|
+
import {Badge} from '@sproutsocial/racine';
|
|
258
|
+
<Badge>{labelText}</Badge>
|
|
259
|
+
`
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
createTest(
|
|
263
|
+
"Convert text prop JSX to children",
|
|
264
|
+
`
|
|
265
|
+
import {Badge} from '@sproutsocial/racine';
|
|
266
|
+
<Badge text={<Icon name='check' />} />
|
|
267
|
+
`,
|
|
268
|
+
`
|
|
269
|
+
import {Badge} from '@sproutsocial/racine';
|
|
270
|
+
<Badge><Icon name='check' /></Badge>
|
|
271
|
+
`
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
createTest(
|
|
275
|
+
"Keep existing children when text prop is present",
|
|
276
|
+
`
|
|
277
|
+
import {Badge} from '@sproutsocial/racine';
|
|
278
|
+
<Badge text='Label'>Existing</Badge>
|
|
279
|
+
`,
|
|
280
|
+
`
|
|
281
|
+
import {Badge} from '@sproutsocial/racine';
|
|
282
|
+
<Badge>Existing</Badge>
|
|
283
|
+
`
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe("Tip prop removal", () => {
|
|
288
|
+
createTest(
|
|
289
|
+
"Remove tip prop",
|
|
290
|
+
`
|
|
291
|
+
import {Badge} from '@sproutsocial/racine';
|
|
292
|
+
<Badge tip='tooltip text' />
|
|
293
|
+
`,
|
|
294
|
+
`
|
|
295
|
+
import {Badge} from '@sproutsocial/racine';
|
|
296
|
+
<Badge />
|
|
297
|
+
`
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
createTest(
|
|
301
|
+
"Remove tip prop with variable",
|
|
302
|
+
`
|
|
303
|
+
import {Badge} from '@sproutsocial/racine';
|
|
304
|
+
<Badge tip={tooltipText} />
|
|
305
|
+
`,
|
|
306
|
+
`
|
|
307
|
+
import {Badge} from '@sproutsocial/racine';
|
|
308
|
+
<Badge />
|
|
309
|
+
`
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe("Combined transformations", () => {
|
|
314
|
+
createTest(
|
|
315
|
+
"Transform all deprecated props together",
|
|
316
|
+
`
|
|
317
|
+
import {Badge} from '@sproutsocial/racine';
|
|
318
|
+
<Badge size='default' type='passive' text='Label' tip='tooltip' />
|
|
319
|
+
`,
|
|
320
|
+
`
|
|
321
|
+
import {Badge} from '@sproutsocial/racine';
|
|
322
|
+
<Badge size='large' badgeColor='neutral'>Label</Badge>
|
|
323
|
+
`
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
createTest(
|
|
327
|
+
"Transform type='secondary' with text prop containing JSX and other attributes",
|
|
328
|
+
`
|
|
329
|
+
import {Badge, Icon} from '@sproutsocial/racine';
|
|
330
|
+
<Badge type='secondary' position='relative' text={<Icon size='mini' name='circle-x-solid' />} />
|
|
331
|
+
`,
|
|
332
|
+
`
|
|
333
|
+
import {Badge, Icon} from '@sproutsocial/racine';
|
|
334
|
+
<Badge position='relative' badgeColor='yellow'><Icon size='mini' name='circle-x-solid' /></Badge>
|
|
335
|
+
`
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
createTest(
|
|
339
|
+
"Transform multiple Badge components",
|
|
340
|
+
`
|
|
341
|
+
import {Badge} from '@sproutsocial/racine';
|
|
342
|
+
<>
|
|
343
|
+
<Badge type='primary' text='One' />
|
|
344
|
+
<Badge type='secondary' text='Two' />
|
|
345
|
+
</>
|
|
346
|
+
`,
|
|
347
|
+
`
|
|
348
|
+
import {Badge} from '@sproutsocial/racine';
|
|
349
|
+
<>
|
|
350
|
+
<Badge badgeColor='blue'>One</Badge>
|
|
351
|
+
<Badge badgeColor='yellow'>Two</Badge>
|
|
352
|
+
</>
|
|
353
|
+
`
|
|
354
|
+
);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe("Import detection", () => {
|
|
358
|
+
createTest(
|
|
359
|
+
"No changes if Badge not imported",
|
|
360
|
+
`
|
|
361
|
+
<Badge type='passive' />
|
|
362
|
+
`,
|
|
363
|
+
`
|
|
364
|
+
<Badge type='passive' />
|
|
365
|
+
`
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
createTest(
|
|
369
|
+
"Handle Badge from seeds-react-badge",
|
|
370
|
+
`
|
|
371
|
+
import {Badge} from '@sproutsocial/seeds-react-badge';
|
|
372
|
+
<Badge type='passive' />
|
|
373
|
+
`,
|
|
374
|
+
`
|
|
375
|
+
import {Badge} from '@sproutsocial/seeds-react-badge';
|
|
376
|
+
<Badge badgeColor='neutral' />
|
|
377
|
+
`
|
|
378
|
+
);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
describe("Data attribute TODO comments", () => {
|
|
382
|
+
createTest(
|
|
383
|
+
"Add TODO for data-qa-badge-type",
|
|
384
|
+
`
|
|
385
|
+
import {screen} from '@sproutsocial/test-utils';
|
|
386
|
+
const badge = screen.queryByDataQaLabel('badge-type');
|
|
387
|
+
`,
|
|
388
|
+
`
|
|
389
|
+
/* TODO (badge-1.x-to-2.x codemod): Data attributes data-qa-badge-type, data-qa-badge-tip, and data-tip have been removed from Badge component. Update test selectors and data attribute references. */
|
|
390
|
+
import { screen } from '@sproutsocial/test-utils';
|
|
391
|
+
const badge = screen.queryByDataQaLabel('badge-type');
|
|
392
|
+
`
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
createTest(
|
|
396
|
+
"Add TODO for data-qa-badge-tip",
|
|
397
|
+
`
|
|
398
|
+
const badge = element.querySelector('[data-qa-badge-tip]');
|
|
399
|
+
`,
|
|
400
|
+
`
|
|
401
|
+
/* TODO (badge-1.x-to-2.x codemod): Data attributes data-qa-badge-type, data-qa-badge-tip, and data-tip have been removed from Badge component. Update test selectors and data attribute references. */
|
|
402
|
+
const badge = element.querySelector('[data-qa-badge-tip]');
|
|
403
|
+
`
|
|
404
|
+
);
|
|
405
|
+
});
|
|
406
|
+
});
|