@preply/ds-ai-core 11.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/AGENTS.md +7 -0
- package/README.md +34 -0
- package/dist/event-tracking.d.ts +21 -0
- package/dist/event-tracking.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38209 -0
- package/dist/tools/components/__tests__/get-component-docs.test.d.ts +2 -0
- package/dist/tools/components/__tests__/get-component-docs.test.d.ts.map +1 -0
- package/dist/tools/components/__tests__/list-components.test.d.ts +2 -0
- package/dist/tools/components/__tests__/list-components.test.d.ts.map +1 -0
- package/dist/tools/components/context/__test__/get-components-data.test.d.ts +2 -0
- package/dist/tools/components/context/__test__/get-components-data.test.d.ts.map +1 -0
- package/dist/tools/components/context/__test__/test-components/FixtureButton.d.ts +15 -0
- package/dist/tools/components/context/__test__/test-components/FixtureButton.d.ts.map +1 -0
- package/dist/tools/components/context/__test__/test-components/index.d.ts +2 -0
- package/dist/tools/components/context/__test__/test-components/index.d.ts.map +1 -0
- package/dist/tools/components/context/extract-component-docgen-info.d.ts +3 -0
- package/dist/tools/components/context/extract-component-docgen-info.d.ts.map +1 -0
- package/dist/tools/components/context/get-components-data.d.ts +24 -0
- package/dist/tools/components/context/get-components-data.d.ts.map +1 -0
- package/dist/tools/components/context/index.d.ts +6 -0
- package/dist/tools/components/context/index.d.ts.map +1 -0
- package/dist/tools/components/context/render-component-doc.d.ts +4 -0
- package/dist/tools/components/context/render-component-doc.d.ts.map +1 -0
- package/dist/tools/components/get-component-docs.d.ts +15 -0
- package/dist/tools/components/get-component-docs.d.ts.map +1 -0
- package/dist/tools/components/list-components.d.ts +9 -0
- package/dist/tools/components/list-components.d.ts.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/search-icon/__tests__/get-icons-data.test.d.ts +2 -0
- package/dist/tools/search-icon/__tests__/get-icons-data.test.d.ts.map +1 -0
- package/dist/tools/search-icon/__tests__/search-icon.test.d.ts +2 -0
- package/dist/tools/search-icon/__tests__/search-icon.test.d.ts.map +1 -0
- package/dist/tools/search-icon/get-icons-data.d.ts +6 -0
- package/dist/tools/search-icon/get-icons-data.d.ts.map +1 -0
- package/dist/tools/search-icon/search-icon.d.ts +18 -0
- package/dist/tools/search-icon/search-icon.d.ts.map +1 -0
- package/dist/tools/search-token/__tests__/search-token-by-name.test.d.ts +2 -0
- package/dist/tools/search-token/__tests__/search-token-by-name.test.d.ts.map +1 -0
- package/dist/tools/search-token/__tests__/search-token-by-value.test.d.ts +2 -0
- package/dist/tools/search-token/__tests__/search-token-by-value.test.d.ts.map +1 -0
- package/dist/tools/search-token/context/__tests__/get-tokens-data.test.d.ts +2 -0
- package/dist/tools/search-token/context/__tests__/get-tokens-data.test.d.ts.map +1 -0
- package/dist/tools/search-token/context/get-tokens-data.d.ts +13 -0
- package/dist/tools/search-token/context/get-tokens-data.d.ts.map +1 -0
- package/dist/tools/search-token/context/index.d.ts +6 -0
- package/dist/tools/search-token/context/index.d.ts.map +1 -0
- package/dist/tools/search-token/search-token-by-name.d.ts +26 -0
- package/dist/tools/search-token/search-token-by-name.d.ts.map +1 -0
- package/dist/tools/search-token/search-token-by-value.d.ts +24 -0
- package/dist/tools/search-token/search-token-by-value.d.ts.map +1 -0
- package/dist/tools/search-token/token-utils.d.ts +9 -0
- package/dist/tools/search-token/token-utils.d.ts.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/create-search-index.d.ts +48 -0
- package/dist/utils/create-search-index.d.ts.map +1 -0
- package/dist/utils/define-tool.d.ts +49 -0
- package/dist/utils/define-tool.d.ts.map +1 -0
- package/dist/utils/format-list.d.ts +26 -0
- package/dist/utils/format-list.d.ts.map +1 -0
- package/dist/utils/md.d.ts +24 -0
- package/dist/utils/md.d.ts.map +1 -0
- package/package.json +48 -0
- package/src/event-tracking.ts +117 -0
- package/src/index.ts +4 -0
- package/src/tools/components/__tests__/get-component-docs.test.ts +58 -0
- package/src/tools/components/__tests__/list-components.test.ts +63 -0
- package/src/tools/components/context/__test__/get-components-data.test.ts +57 -0
- package/src/tools/components/context/__test__/test-components/FixtureButton.tsx +18 -0
- package/src/tools/components/context/__test__/test-components/index.ts +1 -0
- package/src/tools/components/context/__test__/test-components/tsconfig.json +11 -0
- package/src/tools/components/context/extract-component-docgen-info.ts +108 -0
- package/src/tools/components/context/get-components-data.ts +94 -0
- package/src/tools/components/context/index.ts +4 -0
- package/src/tools/components/context/render-component-doc.ts +89 -0
- package/src/tools/components/get-component-docs.ts +26 -0
- package/src/tools/components/list-components.ts +36 -0
- package/src/tools/index.ts +5 -0
- package/src/tools/search-icon/__tests__/get-icons-data.test.ts +22 -0
- package/src/tools/search-icon/__tests__/search-icon.test.ts +235 -0
- package/src/tools/search-icon/__tests__/test-icons/NotIcon.md +1 -0
- package/src/tools/search-icon/__tests__/test-icons/OtherIcon.svg +1 -0
- package/src/tools/search-icon/__tests__/test-icons/TokyoUIClose.svg +1 -0
- package/src/tools/search-icon/__tests__/test-icons/TokyoUIHelp.svg +1 -0
- package/src/tools/search-icon/get-icons-data.ts +19 -0
- package/src/tools/search-icon/search-icon.ts +100 -0
- package/src/tools/search-token/__tests__/search-token-by-name.test.ts +384 -0
- package/src/tools/search-token/__tests__/search-token-by-value.test.ts +250 -0
- package/src/tools/search-token/context/__tests__/get-tokens-data.test.ts +148 -0
- package/src/tools/search-token/context/get-tokens-data.ts +103 -0
- package/src/tools/search-token/context/index.ts +4 -0
- package/src/tools/search-token/search-token-by-name.ts +110 -0
- package/src/tools/search-token/search-token-by-value.ts +107 -0
- package/src/tools/search-token/token-utils.ts +60 -0
- package/src/types.ts +3 -0
- package/src/utils/create-search-index.ts +121 -0
- package/src/utils/define-tool.ts +67 -0
- package/src/utils/format-list.ts +38 -0
- package/src/utils/md.ts +12 -0
- package/tsconfig.json +11 -0
- package/vite.config.ts +23 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { searchTokenByName } from '../search-token-by-name';
|
|
3
|
+
|
|
4
|
+
vi.mock(import('../context/get-tokens-data'), () => ({
|
|
5
|
+
getTokensData: () => ({
|
|
6
|
+
web: [
|
|
7
|
+
{
|
|
8
|
+
name: 'spacing.8',
|
|
9
|
+
scss: '$spacing-8',
|
|
10
|
+
less: '@spacing-8',
|
|
11
|
+
typescript: 'spacing[8]',
|
|
12
|
+
value: '8px',
|
|
13
|
+
private: false,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'spacing.16',
|
|
17
|
+
scss: '$spacing-16',
|
|
18
|
+
less: '@spacing-16',
|
|
19
|
+
typescript: 'spacing[16]',
|
|
20
|
+
value: '16px',
|
|
21
|
+
private: false,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'heading.huge.lineHeight',
|
|
25
|
+
scss: '$heading-huge-lineHeight',
|
|
26
|
+
less: '@heading-huge-lineHeight',
|
|
27
|
+
typescript: 'heading.huge.lineHeight',
|
|
28
|
+
value: '68px',
|
|
29
|
+
private: false,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'dsInternalPrimitive.color.background.primary',
|
|
33
|
+
scss: '$dsInternalPrimitive-color-background-primary',
|
|
34
|
+
less: '@dsInternalPrimitive-color-background-primary',
|
|
35
|
+
typescript: 'dsInternalPrimitive.color.background.primary',
|
|
36
|
+
value: '#FFFFFF',
|
|
37
|
+
private: true,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
'react-native': [
|
|
41
|
+
{
|
|
42
|
+
name: 'spacing.8',
|
|
43
|
+
scss: '$spacing-8',
|
|
44
|
+
less: '@spacing-8',
|
|
45
|
+
typescript: 'spacing[8]',
|
|
46
|
+
value: 8,
|
|
47
|
+
private: false,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'spacing.16',
|
|
51
|
+
scss: '$spacing-16',
|
|
52
|
+
less: '@spacing-16',
|
|
53
|
+
typescript: 'spacing[16]',
|
|
54
|
+
value: 16,
|
|
55
|
+
private: false,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'heading.huge.lineHeight',
|
|
59
|
+
scss: '$heading-huge-lineHeight',
|
|
60
|
+
less: '@heading-huge-lineHeight',
|
|
61
|
+
typescript: 'heading.huge.lineHeight',
|
|
62
|
+
value: 68,
|
|
63
|
+
private: false,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'dsInternalPrimitive.color.background.primary',
|
|
67
|
+
scss: '$dsInternalPrimitive-color-background-primary',
|
|
68
|
+
less: '@dsInternalPrimitive-color-background-primary',
|
|
69
|
+
typescript: 'dsInternalPrimitive.color.background.primary',
|
|
70
|
+
value: '#FAFAFA',
|
|
71
|
+
private: true,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
}),
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
describe('searchTokenByName tool', () => {
|
|
78
|
+
it('returns exact match by raw name', () => {
|
|
79
|
+
expect(
|
|
80
|
+
searchTokenByName.callback({
|
|
81
|
+
name: 'spacing.8',
|
|
82
|
+
platform: 'web',
|
|
83
|
+
}),
|
|
84
|
+
).toMatchInlineSnapshot(`
|
|
85
|
+
[
|
|
86
|
+
"Found exact match for "spacing.8":",
|
|
87
|
+
"token: $spacing-8
|
|
88
|
+
value: 8px",
|
|
89
|
+
"Also, here you can find some tokens with similar names:",
|
|
90
|
+
"---
|
|
91
|
+
token: $spacing-16
|
|
92
|
+
value: 16px
|
|
93
|
+
---",
|
|
94
|
+
]
|
|
95
|
+
`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('returns exact match by scss format', () => {
|
|
99
|
+
const result = searchTokenByName.callback({
|
|
100
|
+
name: '$spacing-8',
|
|
101
|
+
platform: 'web',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(result).toMatchInlineSnapshot(`
|
|
105
|
+
[
|
|
106
|
+
"Found exact match for "$spacing-8":",
|
|
107
|
+
"token: $spacing-8
|
|
108
|
+
value: 8px",
|
|
109
|
+
"Also, here you can find some tokens with similar names:",
|
|
110
|
+
"---
|
|
111
|
+
token: $spacing-16
|
|
112
|
+
value: 16px
|
|
113
|
+
---",
|
|
114
|
+
]
|
|
115
|
+
`);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('returns exact match by less format', () => {
|
|
119
|
+
const result = searchTokenByName.callback({
|
|
120
|
+
name: '@spacing-8',
|
|
121
|
+
platform: 'web',
|
|
122
|
+
format: 'less',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(result).toMatchInlineSnapshot(`
|
|
126
|
+
[
|
|
127
|
+
"Found exact match for "@spacing-8":",
|
|
128
|
+
"token: "@spacing-8"
|
|
129
|
+
value: 8px",
|
|
130
|
+
"Also, here you can find some tokens with similar names:",
|
|
131
|
+
"---
|
|
132
|
+
token: "@spacing-16"
|
|
133
|
+
value: 16px
|
|
134
|
+
---",
|
|
135
|
+
]
|
|
136
|
+
`);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('returns exact match by typescript format', () => {
|
|
140
|
+
const result = searchTokenByName.callback({
|
|
141
|
+
name: 'spacing[8]',
|
|
142
|
+
platform: 'web',
|
|
143
|
+
format: 'typescript',
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(result).toMatchInlineSnapshot(`
|
|
147
|
+
[
|
|
148
|
+
"Found exact match for "spacing[8]":",
|
|
149
|
+
"token: spacing[8]
|
|
150
|
+
value: 8px",
|
|
151
|
+
"Also, here you can find some tokens with similar names:",
|
|
152
|
+
"---
|
|
153
|
+
token: spacing[16]
|
|
154
|
+
value: 16px
|
|
155
|
+
---",
|
|
156
|
+
]
|
|
157
|
+
`);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('returns fuzzy results when no exact match', () => {
|
|
161
|
+
expect(
|
|
162
|
+
searchTokenByName.callback({
|
|
163
|
+
name: 'spacing.32',
|
|
164
|
+
platform: 'web',
|
|
165
|
+
}),
|
|
166
|
+
).toMatchInlineSnapshot(`
|
|
167
|
+
[
|
|
168
|
+
"There is no exact match for "spacing.32", but here are some similar tokens:",
|
|
169
|
+
"---
|
|
170
|
+
token: $spacing-8
|
|
171
|
+
value: 8px
|
|
172
|
+
---
|
|
173
|
+
token: $spacing-16
|
|
174
|
+
value: 16px
|
|
175
|
+
---",
|
|
176
|
+
]
|
|
177
|
+
`);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('returns not-found when no matches', () => {
|
|
181
|
+
expect(
|
|
182
|
+
searchTokenByName.callback({
|
|
183
|
+
name: 'definitely_missing_token_name_123',
|
|
184
|
+
platform: 'web',
|
|
185
|
+
}),
|
|
186
|
+
).toMatchInlineSnapshot(`
|
|
187
|
+
[
|
|
188
|
+
"No results found for "definitely_missing_token_name_123"",
|
|
189
|
+
]
|
|
190
|
+
`);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('defaults to scss format when format is omitted', () => {
|
|
194
|
+
expect(
|
|
195
|
+
searchTokenByName.callback({
|
|
196
|
+
name: 'spacing.8',
|
|
197
|
+
platform: 'web',
|
|
198
|
+
}),
|
|
199
|
+
).toMatchInlineSnapshot(`
|
|
200
|
+
[
|
|
201
|
+
"Found exact match for "spacing.8":",
|
|
202
|
+
"token: $spacing-8
|
|
203
|
+
value: 8px",
|
|
204
|
+
"Also, here you can find some tokens with similar names:",
|
|
205
|
+
"---
|
|
206
|
+
token: $spacing-16
|
|
207
|
+
value: 16px
|
|
208
|
+
---",
|
|
209
|
+
]
|
|
210
|
+
`);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('ignores format for react-native and returns typescript names', () => {
|
|
214
|
+
expect(
|
|
215
|
+
searchTokenByName.callback({
|
|
216
|
+
name: 'spacing.8',
|
|
217
|
+
platform: 'react-native',
|
|
218
|
+
format: 'less',
|
|
219
|
+
}),
|
|
220
|
+
).toMatchInlineSnapshot(`
|
|
221
|
+
[
|
|
222
|
+
"Found exact match for "spacing.8":",
|
|
223
|
+
"token: spacing[8]
|
|
224
|
+
value: 8",
|
|
225
|
+
"Also, here you can find some tokens with similar names:",
|
|
226
|
+
"---
|
|
227
|
+
token: spacing[16]
|
|
228
|
+
value: 16
|
|
229
|
+
---",
|
|
230
|
+
]
|
|
231
|
+
`);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('includes example when includeExample is true', () => {
|
|
235
|
+
const result = searchTokenByName.callback({
|
|
236
|
+
name: 'spacing.8',
|
|
237
|
+
platform: 'web',
|
|
238
|
+
includeExample: true,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(result).toMatchInlineSnapshot(`
|
|
242
|
+
[
|
|
243
|
+
"Found exact match for "spacing.8":",
|
|
244
|
+
"token: $spacing-8
|
|
245
|
+
value: 8px",
|
|
246
|
+
"Here is an example of how to use design-system tokens in scss:",
|
|
247
|
+
"@use '@preply/ds-web-core/dist/generated/tokens' as *;
|
|
248
|
+
|
|
249
|
+
.MyComponent {
|
|
250
|
+
box-shadow: $dropShadow-1-shorthand;
|
|
251
|
+
}",
|
|
252
|
+
"Also, here you can find some tokens with similar names:",
|
|
253
|
+
"---
|
|
254
|
+
token: $spacing-16
|
|
255
|
+
value: 16px
|
|
256
|
+
---",
|
|
257
|
+
]
|
|
258
|
+
`);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('includes react-native example', () => {
|
|
262
|
+
const result = searchTokenByName.callback({
|
|
263
|
+
name: 'spacing.8',
|
|
264
|
+
platform: 'react-native',
|
|
265
|
+
includeExample: true,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(result).toMatchInlineSnapshot(`
|
|
269
|
+
[
|
|
270
|
+
"Found exact match for "spacing.8":",
|
|
271
|
+
"token: spacing[8]
|
|
272
|
+
value: 8",
|
|
273
|
+
"Here is an example of how to use design-system tokens in react-native:",
|
|
274
|
+
"import { View } from 'react-native';
|
|
275
|
+
import { color } from '@preply/ds-core';
|
|
276
|
+
import { createStyleSheet, useStyleSheet } from '@preply/ds-rn-core';
|
|
277
|
+
|
|
278
|
+
const rawStyles = createStyleSheet({
|
|
279
|
+
container: {
|
|
280
|
+
backgroundColor: color.background.primary,
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
export const MyComponent = () => {
|
|
285
|
+
const styles = useStyleSheet(rawStyles);
|
|
286
|
+
|
|
287
|
+
return <View style={styles.container} />;
|
|
288
|
+
};",
|
|
289
|
+
"Also, here you can find some tokens with similar names:",
|
|
290
|
+
"---
|
|
291
|
+
token: spacing[16]
|
|
292
|
+
value: 16
|
|
293
|
+
---",
|
|
294
|
+
]
|
|
295
|
+
`);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('filters out private tokens by default', () => {
|
|
299
|
+
expect(
|
|
300
|
+
searchTokenByName.callback({
|
|
301
|
+
name: 'dsInternalPrimitive.color.background.primary',
|
|
302
|
+
platform: 'web',
|
|
303
|
+
}),
|
|
304
|
+
).toMatchInlineSnapshot(`
|
|
305
|
+
[
|
|
306
|
+
"No results found for "dsInternalPrimitive.color.background.primary"",
|
|
307
|
+
]
|
|
308
|
+
`);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('includes private tokens when includePrivate is true', () => {
|
|
312
|
+
const result = searchTokenByName.callback({
|
|
313
|
+
name: 'dsInternalPrimitive.color.background.primary',
|
|
314
|
+
platform: 'web',
|
|
315
|
+
includePrivate: true,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
expect(result).toMatchInlineSnapshot(`
|
|
319
|
+
[
|
|
320
|
+
"Found exact match for "dsInternalPrimitive.color.background.primary":",
|
|
321
|
+
"token: $dsInternalPrimitive-color-background-primary
|
|
322
|
+
value: "#FFFFFF"",
|
|
323
|
+
]
|
|
324
|
+
`);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('includes less example for web', () => {
|
|
328
|
+
const result = searchTokenByName.callback({
|
|
329
|
+
name: 'spacing.8',
|
|
330
|
+
platform: 'web',
|
|
331
|
+
format: 'less',
|
|
332
|
+
includeExample: true,
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
expect(result).toMatchInlineSnapshot(`
|
|
336
|
+
[
|
|
337
|
+
"Found exact match for "spacing.8":",
|
|
338
|
+
"token: "@spacing-8"
|
|
339
|
+
value: 8px",
|
|
340
|
+
"Here is an example of how to use design-system tokens in less:",
|
|
341
|
+
"@import '~@preply/ds-web-core/dist/generated/tokens.less';
|
|
342
|
+
|
|
343
|
+
.MyComponent {
|
|
344
|
+
box-shadow: @dropShadow-1-shorthand;
|
|
345
|
+
}",
|
|
346
|
+
"Also, here you can find some tokens with similar names:",
|
|
347
|
+
"---
|
|
348
|
+
token: "@spacing-16"
|
|
349
|
+
value: 16px
|
|
350
|
+
---",
|
|
351
|
+
]
|
|
352
|
+
`);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('includes typescript example for web', () => {
|
|
356
|
+
const result = searchTokenByName.callback({
|
|
357
|
+
name: 'spacing.8',
|
|
358
|
+
platform: 'web',
|
|
359
|
+
format: 'typescript',
|
|
360
|
+
includeExample: true,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
expect(result).toMatchInlineSnapshot(`
|
|
364
|
+
[
|
|
365
|
+
"Found exact match for "spacing.8":",
|
|
366
|
+
"token: spacing[8]
|
|
367
|
+
value: 8px",
|
|
368
|
+
"Here is an example of how to use design-system tokens in typescript:",
|
|
369
|
+
"import styled from 'styled-components';
|
|
370
|
+
import { dropShadow } from '@preply/ds-core';
|
|
371
|
+
import { getTokenVar } from '@preply/ds-web-core';
|
|
372
|
+
|
|
373
|
+
const MyComponent = styled.div\`
|
|
374
|
+
box-shadow: \${getTokenVar(dropShadow[1].shorthand)};
|
|
375
|
+
\`;",
|
|
376
|
+
"Also, here you can find some tokens with similar names:",
|
|
377
|
+
"---
|
|
378
|
+
token: spacing[16]
|
|
379
|
+
value: 16px
|
|
380
|
+
---",
|
|
381
|
+
]
|
|
382
|
+
`);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { searchTokenByValue } from '../search-token-by-value';
|
|
3
|
+
|
|
4
|
+
vi.mock(import('../context/get-tokens-data'), () => ({
|
|
5
|
+
getTokensData: () => ({
|
|
6
|
+
web: [
|
|
7
|
+
{
|
|
8
|
+
name: 'spacing.8',
|
|
9
|
+
scss: '$spacing-8',
|
|
10
|
+
less: '@spacing-8',
|
|
11
|
+
typescript: 'spacing[8]',
|
|
12
|
+
value: '8px',
|
|
13
|
+
private: false,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'action.base.borderRadius',
|
|
17
|
+
scss: '$action-base-borderRadius',
|
|
18
|
+
less: '@action-base-borderRadius',
|
|
19
|
+
typescript: 'action.base.borderRadius',
|
|
20
|
+
value: '8px',
|
|
21
|
+
private: false,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'spacing.16',
|
|
25
|
+
scss: '$spacing-16',
|
|
26
|
+
less: '@spacing-16',
|
|
27
|
+
typescript: 'spacing[16]',
|
|
28
|
+
value: '16px',
|
|
29
|
+
private: false,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'dsInternalPrimitive.color.background.primary',
|
|
33
|
+
scss: '$dsInternalPrimitive-color-background-primary',
|
|
34
|
+
less: '@dsInternalPrimitive-color-background-primary',
|
|
35
|
+
typescript: 'dsInternalPrimitive.color.background.primary',
|
|
36
|
+
value: '#FFFFFF',
|
|
37
|
+
private: true,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
'react-native': [
|
|
41
|
+
{
|
|
42
|
+
name: 'spacing.8',
|
|
43
|
+
scss: '$spacing-8',
|
|
44
|
+
less: '@spacing-8',
|
|
45
|
+
typescript: 'spacing[8]',
|
|
46
|
+
value: 8,
|
|
47
|
+
private: false,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'action.base.borderRadius',
|
|
51
|
+
scss: '$action-base-borderRadius',
|
|
52
|
+
less: '@action-base-borderRadius',
|
|
53
|
+
typescript: 'action.base.borderRadius',
|
|
54
|
+
value: 8,
|
|
55
|
+
private: false,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'spacing.16',
|
|
59
|
+
scss: '$spacing-16',
|
|
60
|
+
less: '@spacing-16',
|
|
61
|
+
typescript: 'spacing[16]',
|
|
62
|
+
value: 16,
|
|
63
|
+
private: false,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'dsInternalPrimitive.color.background.primary',
|
|
67
|
+
scss: '$dsInternalPrimitive-color-background-primary',
|
|
68
|
+
less: '@dsInternalPrimitive-color-background-primary',
|
|
69
|
+
typescript: 'dsInternalPrimitive.color.background.primary',
|
|
70
|
+
value: '#FAFAFA',
|
|
71
|
+
private: true,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
}),
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
describe('searchTokenByValue tool', () => {
|
|
78
|
+
it('returns matching tokens by value', () => {
|
|
79
|
+
expect(
|
|
80
|
+
searchTokenByValue.callback({
|
|
81
|
+
value: '8px',
|
|
82
|
+
platform: 'web',
|
|
83
|
+
}),
|
|
84
|
+
).toMatchInlineSnapshot(`
|
|
85
|
+
[
|
|
86
|
+
"Found 2 tokens with value "8px"",
|
|
87
|
+
"---
|
|
88
|
+
token: $spacing-8
|
|
89
|
+
value: 8px
|
|
90
|
+
---
|
|
91
|
+
token: $action-base-borderRadius
|
|
92
|
+
value: 8px
|
|
93
|
+
---",
|
|
94
|
+
]
|
|
95
|
+
`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('returns not-found when no matches', () => {
|
|
99
|
+
expect(
|
|
100
|
+
searchTokenByValue.callback({
|
|
101
|
+
value: 'definitely-missing-token-value',
|
|
102
|
+
platform: 'web',
|
|
103
|
+
}),
|
|
104
|
+
).toMatchInlineSnapshot(`
|
|
105
|
+
[
|
|
106
|
+
"No results found for "definitely-missing-token-value"",
|
|
107
|
+
]
|
|
108
|
+
`);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('expands numeric values to include px and em units', () => {
|
|
112
|
+
expect(
|
|
113
|
+
searchTokenByValue.callback({
|
|
114
|
+
value: '8',
|
|
115
|
+
platform: 'web',
|
|
116
|
+
}),
|
|
117
|
+
).toMatchInlineSnapshot(`
|
|
118
|
+
[
|
|
119
|
+
"Found 2 tokens with value "8"",
|
|
120
|
+
"---
|
|
121
|
+
token: $spacing-8
|
|
122
|
+
value: 8px
|
|
123
|
+
---
|
|
124
|
+
token: $action-base-borderRadius
|
|
125
|
+
value: 8px
|
|
126
|
+
---",
|
|
127
|
+
]
|
|
128
|
+
`);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('defaults to scss format when format is omitted', () => {
|
|
132
|
+
expect(
|
|
133
|
+
searchTokenByValue.callback({
|
|
134
|
+
value: '8px',
|
|
135
|
+
platform: 'web',
|
|
136
|
+
}),
|
|
137
|
+
).toMatchInlineSnapshot(`
|
|
138
|
+
[
|
|
139
|
+
"Found 2 tokens with value "8px"",
|
|
140
|
+
"---
|
|
141
|
+
token: $spacing-8
|
|
142
|
+
value: 8px
|
|
143
|
+
---
|
|
144
|
+
token: $action-base-borderRadius
|
|
145
|
+
value: 8px
|
|
146
|
+
---",
|
|
147
|
+
]
|
|
148
|
+
`);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('uses less format for web', () => {
|
|
152
|
+
expect(
|
|
153
|
+
searchTokenByValue.callback({
|
|
154
|
+
value: '8px',
|
|
155
|
+
platform: 'web',
|
|
156
|
+
format: 'less',
|
|
157
|
+
}),
|
|
158
|
+
).toMatchInlineSnapshot(`
|
|
159
|
+
[
|
|
160
|
+
"Found 2 tokens with value "8px"",
|
|
161
|
+
"---
|
|
162
|
+
token: "@spacing-8"
|
|
163
|
+
value: 8px
|
|
164
|
+
---
|
|
165
|
+
token: "@action-base-borderRadius"
|
|
166
|
+
value: 8px
|
|
167
|
+
---",
|
|
168
|
+
]
|
|
169
|
+
`);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('ignores format for react-native and returns typescript names', () => {
|
|
173
|
+
expect(
|
|
174
|
+
searchTokenByValue.callback({
|
|
175
|
+
value: '8',
|
|
176
|
+
platform: 'react-native',
|
|
177
|
+
format: 'less',
|
|
178
|
+
}),
|
|
179
|
+
).toMatchInlineSnapshot(`
|
|
180
|
+
[
|
|
181
|
+
"Found 2 tokens with value "8"",
|
|
182
|
+
"---
|
|
183
|
+
token: spacing[8]
|
|
184
|
+
value: 8
|
|
185
|
+
---
|
|
186
|
+
token: action.base.borderRadius
|
|
187
|
+
value: 8
|
|
188
|
+
---",
|
|
189
|
+
]
|
|
190
|
+
`);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('includes example when includeExample is true', () => {
|
|
194
|
+
expect(
|
|
195
|
+
searchTokenByValue.callback({
|
|
196
|
+
value: '8px',
|
|
197
|
+
platform: 'web',
|
|
198
|
+
includeExample: true,
|
|
199
|
+
}),
|
|
200
|
+
).toMatchInlineSnapshot(`
|
|
201
|
+
[
|
|
202
|
+
"Found 2 tokens with value "8px"",
|
|
203
|
+
"---
|
|
204
|
+
token: $spacing-8
|
|
205
|
+
value: 8px
|
|
206
|
+
---
|
|
207
|
+
token: $action-base-borderRadius
|
|
208
|
+
value: 8px
|
|
209
|
+
---",
|
|
210
|
+
"Here is an example of how to use design-system tokens in scss:",
|
|
211
|
+
"@use '@preply/ds-web-core/dist/generated/tokens' as *;
|
|
212
|
+
|
|
213
|
+
.MyComponent {
|
|
214
|
+
box-shadow: $dropShadow-1-shorthand;
|
|
215
|
+
}",
|
|
216
|
+
]
|
|
217
|
+
`);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('filters out private tokens by default', () => {
|
|
221
|
+
expect(
|
|
222
|
+
searchTokenByValue.callback({
|
|
223
|
+
value: '#FFFFFF',
|
|
224
|
+
platform: 'web',
|
|
225
|
+
}),
|
|
226
|
+
).toMatchInlineSnapshot(`
|
|
227
|
+
[
|
|
228
|
+
"No results found for "#FFFFFF"",
|
|
229
|
+
]
|
|
230
|
+
`);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('includes private tokens when includePrivate is true', () => {
|
|
234
|
+
expect(
|
|
235
|
+
searchTokenByValue.callback({
|
|
236
|
+
value: '#FFFFFF',
|
|
237
|
+
platform: 'web',
|
|
238
|
+
includePrivate: true,
|
|
239
|
+
}),
|
|
240
|
+
).toMatchInlineSnapshot(`
|
|
241
|
+
[
|
|
242
|
+
"Found 1 tokens with value "#FFFFFF"",
|
|
243
|
+
"---
|
|
244
|
+
token: $dsInternalPrimitive-color-background-primary
|
|
245
|
+
value: "#FFFFFF"
|
|
246
|
+
---",
|
|
247
|
+
]
|
|
248
|
+
`);
|
|
249
|
+
});
|
|
250
|
+
});
|