-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexportPagesAndComponents.test.ts
More file actions
172 lines (150 loc) · 5.54 KB
/
exportPagesAndComponents.test.ts
File metadata and controls
172 lines (150 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { describe, expect, test } from 'bun:test'
import {
DEVUP_COMPONENTS,
extractCustomComponentImports,
extractImports,
generateImportStatements,
} from '../exportPagesAndComponents'
describe('DEVUP_COMPONENTS', () => {
test('should contain expected devup-ui components', () => {
expect(DEVUP_COMPONENTS).toContain('Box')
expect(DEVUP_COMPONENTS).toContain('Flex')
expect(DEVUP_COMPONENTS).toContain('Text')
expect(DEVUP_COMPONENTS).toContain('Image')
expect(DEVUP_COMPONENTS).toContain('Grid')
expect(DEVUP_COMPONENTS).toContain('VStack')
expect(DEVUP_COMPONENTS).toContain('Center')
})
})
describe('extractImports', () => {
test('should extract Box import', () => {
const result = extractImports([['Test', '<Box>Hello</Box>']])
expect(result).toContain('Box')
})
test('should extract multiple devup-ui components', () => {
const result = extractImports([
['Test', '<Box><Flex><Text>Hello</Text></Flex></Box>'],
])
expect(result).toContain('Box')
expect(result).toContain('Flex')
expect(result).toContain('Text')
})
test('should extract keyframes with parenthesis', () => {
const result = extractImports([
['Test', '<Box animationName={keyframes({ "0%": { opacity: 0 } })} />'],
])
expect(result).toContain('keyframes')
expect(result).toContain('Box')
})
test('should extract keyframes with template literal', () => {
const result = extractImports([
['Test', '<Box animationName={keyframes`from { opacity: 0 }`} />'],
])
expect(result).toContain('keyframes')
})
test('should not extract keyframes when not present', () => {
const result = extractImports([['Test', '<Box w="100px" />']])
expect(result).not.toContain('keyframes')
})
test('should return sorted imports', () => {
const result = extractImports([
['Test', '<VStack><Box><Center /></Box></VStack>'],
])
expect(result).toEqual(['Box', 'Center', 'VStack'])
})
test('should not include duplicates', () => {
const result = extractImports([
['Test1', '<Box>A</Box>'],
['Test2', '<Box>B</Box>'],
])
expect(result.filter((x) => x === 'Box').length).toBe(1)
})
test('should handle self-closing tags', () => {
const result = extractImports([['Test', '<Image />']])
expect(result).toContain('Image')
})
test('should handle tags with spaces', () => {
const result = extractImports([['Test', '<Grid rows={2}>']])
expect(result).toContain('Grid')
})
})
describe('extractCustomComponentImports', () => {
test('should extract custom component', () => {
const result = extractCustomComponentImports([
['Test', '<Box><CustomButton /></Box>'],
])
expect(result).toContain('CustomButton')
})
test('should extract multiple custom components', () => {
const result = extractCustomComponentImports([
['Test', '<CustomA><CustomB /><CustomC /></CustomA>'],
])
expect(result).toContain('CustomA')
expect(result).toContain('CustomB')
expect(result).toContain('CustomC')
})
test('should not include devup-ui components', () => {
const result = extractCustomComponentImports([
['Test', '<Box><Flex><CustomCard /></Flex></Box>'],
])
expect(result).toContain('CustomCard')
expect(result).not.toContain('Box')
expect(result).not.toContain('Flex')
})
test('should return sorted imports', () => {
const result = extractCustomComponentImports([
['Test', '<Zebra /><Apple /><Mango />'],
])
expect(result).toEqual(['Apple', 'Mango', 'Zebra'])
})
test('should not include duplicates', () => {
const result = extractCustomComponentImports([
['Test1', '<SharedButton />'],
['Test2', '<SharedButton />'],
])
expect(result.filter((x) => x === 'SharedButton').length).toBe(1)
})
test('should return empty array when no custom components', () => {
const result = extractCustomComponentImports([
['Test', '<Box><Flex>Hello</Flex></Box>'],
])
expect(result).toEqual([])
})
})
describe('generateImportStatements', () => {
test('should generate devup-ui import statement', () => {
const result = generateImportStatements([['Test', '<Box><Flex /></Box>']])
expect(result).toContain("import { Box, Flex } from '@devup-ui/react'")
})
test('should generate custom component import statements', () => {
const result = generateImportStatements([
['Test', '<Box><CustomButton /></Box>'],
])
expect(result).toContain("import { Box } from '@devup-ui/react'")
expect(result).toContain(
"import { CustomButton } from '@/components/CustomButton'",
)
})
test('should generate multiple custom component imports on separate lines', () => {
const result = generateImportStatements([
['Test', '<Box><ButtonA /><ButtonB /></Box>'],
])
expect(result).toContain("import { ButtonA } from '@/components/ButtonA'")
expect(result).toContain("import { ButtonB } from '@/components/ButtonB'")
})
test('should return empty string when no imports', () => {
const result = generateImportStatements([['Test', 'just text']])
expect(result).toBe('')
})
test('should include keyframes in devup-ui import', () => {
const result = generateImportStatements([
['Test', '<Box animation={keyframes({})} />'],
])
expect(result).toContain('keyframes')
expect(result).toContain("from '@devup-ui/react'")
})
test('should end with double newline when has imports', () => {
const result = generateImportStatements([['Test', '<Box />']])
expect(result.endsWith('\n\n')).toBe(true)
})
})