@pyreon/document-primitives 0.24.4 → 0.24.6
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 +17 -19
- package/src/DocumentPreview.ts +0 -48
- package/src/__tests__/document-primitives.browser.test.ts +0 -253
- package/src/__tests__/manifest-snapshot.test.ts +0 -45
- package/src/__tests__/primitives-attrs.test.ts +0 -517
- package/src/__tests__/primitives.test.ts +0 -104
- package/src/__tests__/reactivity.test.ts +0 -415
- package/src/__tests__/useDocumentExport.test.ts +0 -366
- package/src/index.ts +0 -37
- package/src/manifest.ts +0 -388
- package/src/primitives/DocButton.ts +0 -37
- package/src/primitives/DocCode.ts +0 -18
- package/src/primitives/DocColumn.ts +0 -11
- package/src/primitives/DocDivider.ts +0 -21
- package/src/primitives/DocDocument.ts +0 -69
- package/src/primitives/DocHeading.ts +0 -33
- package/src/primitives/DocImage.ts +0 -23
- package/src/primitives/DocLink.ts +0 -15
- package/src/primitives/DocList.ts +0 -15
- package/src/primitives/DocListItem.ts +0 -15
- package/src/primitives/DocPage.ts +0 -21
- package/src/primitives/DocPageBreak.ts +0 -11
- package/src/primitives/DocQuote.ts +0 -17
- package/src/primitives/DocRow.ts +0 -19
- package/src/primitives/DocSection.ts +0 -23
- package/src/primitives/DocSpacer.ts +0 -11
- package/src/primitives/DocTable.ts +0 -57
- package/src/primitives/DocText.ts +0 -31
- package/src/theme.ts +0 -37
- package/src/useDocumentExport.ts +0 -84
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
import { initTestConfig, renderProps } from '@pyreon/test-utils'
|
|
2
|
-
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
3
|
-
|
|
4
|
-
// Each test dynamically imports a primitive module which transitively
|
|
5
|
-
// pulls in @pyreon/rocketstyle + @pyreon/attrs + @pyreon/styler chain.
|
|
6
|
-
// First-load on slow CI runners takes 5-30s per primitive. The default
|
|
7
|
-
// 5000ms timeout was hitting these on every cold load.
|
|
8
|
-
vi.setConfig({ testTimeout: 60_000 })
|
|
9
|
-
|
|
10
|
-
let cleanup: () => void
|
|
11
|
-
beforeAll(() => {
|
|
12
|
-
cleanup = initTestConfig()
|
|
13
|
-
})
|
|
14
|
-
afterAll(() => cleanup())
|
|
15
|
-
|
|
16
|
-
// --------------------------------------------------------
|
|
17
|
-
// DocDocument (Element-based)
|
|
18
|
-
// --------------------------------------------------------
|
|
19
|
-
describe('DocDocument attrs', () => {
|
|
20
|
-
it('sets tag to div', async () => {
|
|
21
|
-
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
22
|
-
const result = renderProps(DocDocument, { children: 'test' })
|
|
23
|
-
expect(result.as).toBe('div')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('passes title to _documentProps', async () => {
|
|
27
|
-
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
28
|
-
const result = renderProps(DocDocument, { title: 'My Doc', children: 'test' })
|
|
29
|
-
expect(result._documentProps.title).toBe('My Doc')
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('passes author to _documentProps', async () => {
|
|
33
|
-
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
34
|
-
const result = renderProps(DocDocument, { author: 'Jane', children: 'test' })
|
|
35
|
-
expect(result._documentProps.author).toBe('Jane')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('passes subject to _documentProps', async () => {
|
|
39
|
-
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
40
|
-
const result = renderProps(DocDocument, { subject: 'Report', children: 'test' })
|
|
41
|
-
expect(result._documentProps.subject).toBe('Report')
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('omits missing optional fields from _documentProps', async () => {
|
|
45
|
-
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
46
|
-
const result = renderProps(DocDocument, { children: 'test' })
|
|
47
|
-
expect(result._documentProps).toEqual({})
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
// --------------------------------------------------------
|
|
52
|
-
// DocHeading (Text-based: tag -> as)
|
|
53
|
-
// --------------------------------------------------------
|
|
54
|
-
describe('DocHeading attrs', () => {
|
|
55
|
-
it('defaults to h1', async () => {
|
|
56
|
-
const DocHeading = (await import('../primitives/DocHeading')).default
|
|
57
|
-
const result = renderProps(DocHeading, { children: 'Hello' })
|
|
58
|
-
expect(result.as).toBe('h1')
|
|
59
|
-
expect(result._documentProps.level).toBe(1)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('sets tag to h2 when level is h2', async () => {
|
|
63
|
-
const DocHeading = (await import('../primitives/DocHeading')).default
|
|
64
|
-
const result = renderProps(DocHeading, { level: 'h2', children: 'Hello' })
|
|
65
|
-
expect(result.as).toBe('h2')
|
|
66
|
-
expect(result._documentProps.level).toBe(2)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('parses level h6', async () => {
|
|
70
|
-
const DocHeading = (await import('../primitives/DocHeading')).default
|
|
71
|
-
const result = renderProps(DocHeading, { level: 'h6', children: 'Hello' })
|
|
72
|
-
expect(result.as).toBe('h6')
|
|
73
|
-
expect(result._documentProps.level).toBe(6)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
// --------------------------------------------------------
|
|
78
|
-
// DocText (Text-based: tag -> as)
|
|
79
|
-
// --------------------------------------------------------
|
|
80
|
-
describe('DocText attrs', () => {
|
|
81
|
-
it('sets tag to p', async () => {
|
|
82
|
-
const DocText = (await import('../primitives/DocText')).default
|
|
83
|
-
const result = renderProps(DocText, { children: 'Hello' })
|
|
84
|
-
expect(result.as).toBe('p')
|
|
85
|
-
expect(result._documentProps).toEqual({})
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
// --------------------------------------------------------
|
|
90
|
-
// DocLink (Text-based: tag -> as)
|
|
91
|
-
// --------------------------------------------------------
|
|
92
|
-
describe('DocLink attrs', () => {
|
|
93
|
-
it('sets tag to a', async () => {
|
|
94
|
-
const DocLink = (await import('../primitives/DocLink')).default
|
|
95
|
-
const result = renderProps(DocLink, { children: 'Click' })
|
|
96
|
-
expect(result.as).toBe('a')
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('passes href to _documentProps', async () => {
|
|
100
|
-
const DocLink = (await import('../primitives/DocLink')).default
|
|
101
|
-
const result = renderProps(DocLink, { href: 'https://example.com', children: 'Click' })
|
|
102
|
-
expect(result._documentProps.href).toBe('https://example.com')
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('defaults href to # when not provided', async () => {
|
|
106
|
-
const DocLink = (await import('../primitives/DocLink')).default
|
|
107
|
-
const result = renderProps(DocLink, { children: 'Click' })
|
|
108
|
-
expect(result._documentProps.href).toBe('#')
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
// --------------------------------------------------------
|
|
113
|
-
// DocImage (Element-based)
|
|
114
|
-
// --------------------------------------------------------
|
|
115
|
-
describe('DocImage attrs', () => {
|
|
116
|
-
it('sets tag to img', async () => {
|
|
117
|
-
const DocImage = (await import('../primitives/DocImage')).default
|
|
118
|
-
const result = renderProps(DocImage, { children: null })
|
|
119
|
-
expect(result.tag).toBe('img')
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('passes src to _documentProps', async () => {
|
|
123
|
-
const DocImage = (await import('../primitives/DocImage')).default
|
|
124
|
-
const result = renderProps(DocImage, { src: 'photo.png', children: null })
|
|
125
|
-
expect(result._documentProps.src).toBe('photo.png')
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('defaults src to empty string', async () => {
|
|
129
|
-
const DocImage = (await import('../primitives/DocImage')).default
|
|
130
|
-
const result = renderProps(DocImage, { children: null })
|
|
131
|
-
expect(result._documentProps.src).toBe('')
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('passes alt, width, height, caption when provided', async () => {
|
|
135
|
-
const DocImage = (await import('../primitives/DocImage')).default
|
|
136
|
-
const result = renderProps(DocImage, {
|
|
137
|
-
src: 'photo.png',
|
|
138
|
-
alt: 'A photo',
|
|
139
|
-
width: 200,
|
|
140
|
-
height: 100,
|
|
141
|
-
caption: 'My photo',
|
|
142
|
-
children: null,
|
|
143
|
-
})
|
|
144
|
-
expect(result._documentProps.alt).toBe('A photo')
|
|
145
|
-
expect(result._documentProps.width).toBe(200)
|
|
146
|
-
expect(result._documentProps.height).toBe(100)
|
|
147
|
-
expect(result._documentProps.caption).toBe('My photo')
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('omits alt, width, height, caption when not provided', async () => {
|
|
151
|
-
const DocImage = (await import('../primitives/DocImage')).default
|
|
152
|
-
const result = renderProps(DocImage, { children: null })
|
|
153
|
-
expect(result._documentProps.alt).toBeUndefined()
|
|
154
|
-
expect(result._documentProps.width).toBeUndefined()
|
|
155
|
-
expect(result._documentProps.height).toBeUndefined()
|
|
156
|
-
expect(result._documentProps.caption).toBeUndefined()
|
|
157
|
-
})
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
// --------------------------------------------------------
|
|
161
|
-
// DocTable (Element-based)
|
|
162
|
-
// --------------------------------------------------------
|
|
163
|
-
describe('DocTable attrs', () => {
|
|
164
|
-
it('sets tag to table', async () => {
|
|
165
|
-
const DocTable = (await import('../primitives/DocTable')).default
|
|
166
|
-
const result = renderProps(DocTable, { children: null })
|
|
167
|
-
expect(result.as).toBe('table')
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('defaults columns and rows to empty arrays', async () => {
|
|
171
|
-
const DocTable = (await import('../primitives/DocTable')).default
|
|
172
|
-
const result = renderProps(DocTable, { children: null })
|
|
173
|
-
expect(result._documentProps.columns).toEqual([])
|
|
174
|
-
expect(result._documentProps.rows).toEqual([])
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
it('passes all table options when provided', async () => {
|
|
178
|
-
const DocTable = (await import('../primitives/DocTable')).default
|
|
179
|
-
const result = renderProps(DocTable, {
|
|
180
|
-
columns: [{ header: 'Name' }],
|
|
181
|
-
rows: [['Alice']],
|
|
182
|
-
headerStyle: { fontWeight: 'bold' },
|
|
183
|
-
striped: true,
|
|
184
|
-
bordered: true,
|
|
185
|
-
caption: 'Users',
|
|
186
|
-
children: null,
|
|
187
|
-
})
|
|
188
|
-
expect(result._documentProps.columns).toEqual([{ header: 'Name' }])
|
|
189
|
-
expect(result._documentProps.rows).toEqual([['Alice']])
|
|
190
|
-
expect(result._documentProps.headerStyle).toEqual({ fontWeight: 'bold' })
|
|
191
|
-
expect(result._documentProps.striped).toBe(true)
|
|
192
|
-
expect(result._documentProps.bordered).toBe(true)
|
|
193
|
-
expect(result._documentProps.caption).toBe('Users')
|
|
194
|
-
})
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
// --------------------------------------------------------
|
|
198
|
-
// DocList (Element-based)
|
|
199
|
-
// --------------------------------------------------------
|
|
200
|
-
describe('DocList attrs', () => {
|
|
201
|
-
it('sets tag to ul by default', async () => {
|
|
202
|
-
const DocList = (await import('../primitives/DocList')).default
|
|
203
|
-
const result = renderProps(DocList, { children: null })
|
|
204
|
-
expect(result.as).toBe('ul')
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
it('sets tag to ol when ordered is true', async () => {
|
|
208
|
-
const DocList = (await import('../primitives/DocList')).default
|
|
209
|
-
const result = renderProps(DocList, { ordered: true, children: null })
|
|
210
|
-
expect(result.as).toBe('ol')
|
|
211
|
-
expect(result._documentProps.ordered).toBe(true)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('has empty _documentProps when not ordered', async () => {
|
|
215
|
-
const DocList = (await import('../primitives/DocList')).default
|
|
216
|
-
const result = renderProps(DocList, { children: null })
|
|
217
|
-
expect(result._documentProps).toEqual({})
|
|
218
|
-
})
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
// --------------------------------------------------------
|
|
222
|
-
// DocListItem (Text-based: tag -> as)
|
|
223
|
-
// --------------------------------------------------------
|
|
224
|
-
describe('DocListItem attrs', () => {
|
|
225
|
-
it('sets tag to li', async () => {
|
|
226
|
-
const DocListItem = (await import('../primitives/DocListItem')).default
|
|
227
|
-
const result = renderProps(DocListItem, { children: 'item' })
|
|
228
|
-
expect(result.as).toBe('li')
|
|
229
|
-
expect(result._documentProps).toEqual({})
|
|
230
|
-
})
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
// --------------------------------------------------------
|
|
234
|
-
// DocCode (Text-based: tag -> as)
|
|
235
|
-
// --------------------------------------------------------
|
|
236
|
-
describe('DocCode attrs', () => {
|
|
237
|
-
it('sets tag to pre', async () => {
|
|
238
|
-
const DocCode = (await import('../primitives/DocCode')).default
|
|
239
|
-
const result = renderProps(DocCode, { children: 'code' })
|
|
240
|
-
expect(result.as).toBe('pre')
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
it('passes language to _documentProps when provided', async () => {
|
|
244
|
-
const DocCode = (await import('../primitives/DocCode')).default
|
|
245
|
-
const result = renderProps(DocCode, { language: 'typescript', children: 'code' })
|
|
246
|
-
expect(result._documentProps.language).toBe('typescript')
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
it('has empty _documentProps when no language', async () => {
|
|
250
|
-
const DocCode = (await import('../primitives/DocCode')).default
|
|
251
|
-
const result = renderProps(DocCode, { children: 'code' })
|
|
252
|
-
expect(result._documentProps).toEqual({})
|
|
253
|
-
})
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
// --------------------------------------------------------
|
|
257
|
-
// DocDivider (Element-based)
|
|
258
|
-
// --------------------------------------------------------
|
|
259
|
-
describe('DocDivider attrs', () => {
|
|
260
|
-
it('sets tag to hr', async () => {
|
|
261
|
-
const DocDivider = (await import('../primitives/DocDivider')).default
|
|
262
|
-
const result = renderProps(DocDivider, { children: null })
|
|
263
|
-
expect(result.tag).toBe('hr')
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
it('passes color and thickness when provided', async () => {
|
|
267
|
-
const DocDivider = (await import('../primitives/DocDivider')).default
|
|
268
|
-
const result = renderProps(DocDivider, { color: 'red', thickness: 2, children: null })
|
|
269
|
-
expect(result._documentProps.color).toBe('red')
|
|
270
|
-
expect(result._documentProps.thickness).toBe(2)
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
it('omits color and thickness when not provided', async () => {
|
|
274
|
-
const DocDivider = (await import('../primitives/DocDivider')).default
|
|
275
|
-
const result = renderProps(DocDivider, { children: null })
|
|
276
|
-
expect(result._documentProps).toEqual({})
|
|
277
|
-
})
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
// --------------------------------------------------------
|
|
281
|
-
// DocPage (Element-based)
|
|
282
|
-
// --------------------------------------------------------
|
|
283
|
-
describe('DocPage attrs', () => {
|
|
284
|
-
it('sets tag to div', async () => {
|
|
285
|
-
const DocPage = (await import('../primitives/DocPage')).default
|
|
286
|
-
const result = renderProps(DocPage, { children: 'page' })
|
|
287
|
-
expect(result.as).toBe('div')
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
it('passes size and orientation when provided', async () => {
|
|
291
|
-
const DocPage = (await import('../primitives/DocPage')).default
|
|
292
|
-
const result = renderProps(DocPage, {
|
|
293
|
-
size: 'A4',
|
|
294
|
-
orientation: 'landscape',
|
|
295
|
-
children: 'page',
|
|
296
|
-
})
|
|
297
|
-
expect(result._documentProps.size).toBe('A4')
|
|
298
|
-
expect(result._documentProps.orientation).toBe('landscape')
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
it('omits size and orientation when not provided', async () => {
|
|
302
|
-
const DocPage = (await import('../primitives/DocPage')).default
|
|
303
|
-
const result = renderProps(DocPage, { children: 'page' })
|
|
304
|
-
expect(result._documentProps).toEqual({})
|
|
305
|
-
})
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
// --------------------------------------------------------
|
|
309
|
-
// DocPageBreak (Element-based)
|
|
310
|
-
// --------------------------------------------------------
|
|
311
|
-
describe('DocPageBreak attrs', () => {
|
|
312
|
-
it('sets tag to div with empty _documentProps', async () => {
|
|
313
|
-
const DocPageBreak = (await import('../primitives/DocPageBreak')).default
|
|
314
|
-
const result = renderProps(DocPageBreak, { children: null })
|
|
315
|
-
expect(result.as).toBe('div')
|
|
316
|
-
expect(result._documentProps).toEqual({})
|
|
317
|
-
})
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
// --------------------------------------------------------
|
|
321
|
-
// DocQuote (Element-based)
|
|
322
|
-
// --------------------------------------------------------
|
|
323
|
-
describe('DocQuote attrs', () => {
|
|
324
|
-
it('sets tag to blockquote', async () => {
|
|
325
|
-
const DocQuote = (await import('../primitives/DocQuote')).default
|
|
326
|
-
const result = renderProps(DocQuote, { children: 'quote' })
|
|
327
|
-
expect(result.as).toBe('blockquote')
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
it('passes borderColor when provided', async () => {
|
|
331
|
-
const DocQuote = (await import('../primitives/DocQuote')).default
|
|
332
|
-
const result = renderProps(DocQuote, { borderColor: '#ff0000', children: 'quote' })
|
|
333
|
-
expect(result._documentProps.borderColor).toBe('#ff0000')
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
it('has empty _documentProps when no borderColor', async () => {
|
|
337
|
-
const DocQuote = (await import('../primitives/DocQuote')).default
|
|
338
|
-
const result = renderProps(DocQuote, { children: 'quote' })
|
|
339
|
-
expect(result._documentProps).toEqual({})
|
|
340
|
-
})
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
// --------------------------------------------------------
|
|
344
|
-
// DocRow (Element-based)
|
|
345
|
-
// --------------------------------------------------------
|
|
346
|
-
describe('DocRow attrs', () => {
|
|
347
|
-
it('sets tag to div with empty _documentProps', async () => {
|
|
348
|
-
const DocRow = (await import('../primitives/DocRow')).default
|
|
349
|
-
const result = renderProps(DocRow, { children: null })
|
|
350
|
-
expect(result.as).toBe('div')
|
|
351
|
-
expect(result._documentProps).toEqual({})
|
|
352
|
-
})
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
// --------------------------------------------------------
|
|
356
|
-
// DocColumn (Element-based)
|
|
357
|
-
// --------------------------------------------------------
|
|
358
|
-
describe('DocColumn attrs', () => {
|
|
359
|
-
it('sets tag to div', async () => {
|
|
360
|
-
const DocColumn = (await import('../primitives/DocColumn')).default
|
|
361
|
-
const result = renderProps(DocColumn, { children: null })
|
|
362
|
-
expect(result.as).toBe('div')
|
|
363
|
-
})
|
|
364
|
-
|
|
365
|
-
it('passes width to _documentProps when provided', async () => {
|
|
366
|
-
const DocColumn = (await import('../primitives/DocColumn')).default
|
|
367
|
-
const result = renderProps(DocColumn, { width: '50%', children: null })
|
|
368
|
-
expect(result._documentProps.width).toBe('50%')
|
|
369
|
-
})
|
|
370
|
-
|
|
371
|
-
it('has empty _documentProps when no width', async () => {
|
|
372
|
-
const DocColumn = (await import('../primitives/DocColumn')).default
|
|
373
|
-
const result = renderProps(DocColumn, { children: null })
|
|
374
|
-
expect(result._documentProps).toEqual({})
|
|
375
|
-
})
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
// --------------------------------------------------------
|
|
379
|
-
// DocSpacer (Element-based)
|
|
380
|
-
// --------------------------------------------------------
|
|
381
|
-
describe('DocSpacer attrs', () => {
|
|
382
|
-
it('sets tag to div', async () => {
|
|
383
|
-
const DocSpacer = (await import('../primitives/DocSpacer')).default
|
|
384
|
-
const result = renderProps(DocSpacer, { children: null })
|
|
385
|
-
expect(result.as).toBe('div')
|
|
386
|
-
})
|
|
387
|
-
|
|
388
|
-
it('defaults height to 16', async () => {
|
|
389
|
-
const DocSpacer = (await import('../primitives/DocSpacer')).default
|
|
390
|
-
const result = renderProps(DocSpacer, { children: null })
|
|
391
|
-
expect(result._documentProps.height).toBe(16)
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
it('passes custom height', async () => {
|
|
395
|
-
const DocSpacer = (await import('../primitives/DocSpacer')).default
|
|
396
|
-
const result = renderProps(DocSpacer, { height: 32, children: null })
|
|
397
|
-
expect(result._documentProps.height).toBe(32)
|
|
398
|
-
})
|
|
399
|
-
})
|
|
400
|
-
|
|
401
|
-
// --------------------------------------------------------
|
|
402
|
-
// DocSection (Element-based)
|
|
403
|
-
// --------------------------------------------------------
|
|
404
|
-
describe('DocSection attrs', () => {
|
|
405
|
-
it('sets tag to div', async () => {
|
|
406
|
-
const DocSection = (await import('../primitives/DocSection')).default
|
|
407
|
-
const result = renderProps(DocSection, { children: null })
|
|
408
|
-
expect(result.as).toBe('div')
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
it('defaults direction to column', async () => {
|
|
412
|
-
const DocSection = (await import('../primitives/DocSection')).default
|
|
413
|
-
const result = renderProps(DocSection, { children: null })
|
|
414
|
-
expect(result._documentProps.direction).toBe('column')
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
it('passes direction when provided', async () => {
|
|
418
|
-
const DocSection = (await import('../primitives/DocSection')).default
|
|
419
|
-
const result = renderProps(DocSection, { direction: 'row', children: null })
|
|
420
|
-
expect(result._documentProps.direction).toBe('row')
|
|
421
|
-
})
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
// --------------------------------------------------------
|
|
425
|
-
// DocButton (Text-based: tag -> as)
|
|
426
|
-
// --------------------------------------------------------
|
|
427
|
-
describe('DocButton attrs', () => {
|
|
428
|
-
it('sets tag to a', async () => {
|
|
429
|
-
const DocButton = (await import('../primitives/DocButton')).default
|
|
430
|
-
const result = renderProps(DocButton, { children: 'Click' })
|
|
431
|
-
expect(result.as).toBe('a')
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
it('passes href to _documentProps', async () => {
|
|
435
|
-
const DocButton = (await import('../primitives/DocButton')).default
|
|
436
|
-
const result = renderProps(DocButton, { href: 'https://example.com', children: 'Click' })
|
|
437
|
-
expect(result._documentProps.href).toBe('https://example.com')
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
it('defaults href to # when not provided', async () => {
|
|
441
|
-
const DocButton = (await import('../primitives/DocButton')).default
|
|
442
|
-
const result = renderProps(DocButton, { children: 'Click' })
|
|
443
|
-
expect(result._documentProps.href).toBe('#')
|
|
444
|
-
})
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
// --------------------------------------------------------
|
|
448
|
-
// DocumentPreview (Element-based)
|
|
449
|
-
// --------------------------------------------------------
|
|
450
|
-
describe('DocumentPreview attrs', () => {
|
|
451
|
-
it('sets tag to div', async () => {
|
|
452
|
-
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
453
|
-
const result = renderProps(DocumentPreview, { children: null })
|
|
454
|
-
expect(result.as).toBe('div')
|
|
455
|
-
})
|
|
456
|
-
|
|
457
|
-
it('defaults size to A4 when not provided', async () => {
|
|
458
|
-
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
459
|
-
const result = renderProps(DocumentPreview, { children: null })
|
|
460
|
-
expect(result._documentProps.size).toBe('A4')
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
it('passes custom size', async () => {
|
|
464
|
-
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
465
|
-
const result = renderProps(DocumentPreview, { size: 'letter', children: null })
|
|
466
|
-
expect(result._documentProps.size).toBe('letter')
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
it('passes showPageBreaks when provided', async () => {
|
|
470
|
-
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
471
|
-
const result = renderProps(DocumentPreview, { showPageBreaks: true, children: null })
|
|
472
|
-
expect(result._documentProps.showPageBreaks).toBe(true)
|
|
473
|
-
})
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
// --------------------------------------------------------
|
|
477
|
-
// All primitives: displayName and IS_ROCKETSTYLE coverage
|
|
478
|
-
// --------------------------------------------------------
|
|
479
|
-
describe('all primitives have correct displayName and IS_ROCKETSTYLE', () => {
|
|
480
|
-
const primitivePairs = [
|
|
481
|
-
['DocButton', '../primitives/DocButton'],
|
|
482
|
-
['DocCode', '../primitives/DocCode'],
|
|
483
|
-
['DocColumn', '../primitives/DocColumn'],
|
|
484
|
-
['DocDivider', '../primitives/DocDivider'],
|
|
485
|
-
['DocDocument', '../primitives/DocDocument'],
|
|
486
|
-
['DocHeading', '../primitives/DocHeading'],
|
|
487
|
-
['DocImage', '../primitives/DocImage'],
|
|
488
|
-
['DocLink', '../primitives/DocLink'],
|
|
489
|
-
['DocList', '../primitives/DocList'],
|
|
490
|
-
['DocListItem', '../primitives/DocListItem'],
|
|
491
|
-
['DocPage', '../primitives/DocPage'],
|
|
492
|
-
['DocPageBreak', '../primitives/DocPageBreak'],
|
|
493
|
-
['DocQuote', '../primitives/DocQuote'],
|
|
494
|
-
['DocRow', '../primitives/DocRow'],
|
|
495
|
-
['DocSection', '../primitives/DocSection'],
|
|
496
|
-
['DocSpacer', '../primitives/DocSpacer'],
|
|
497
|
-
['DocTable', '../primitives/DocTable'],
|
|
498
|
-
['DocText', '../primitives/DocText'],
|
|
499
|
-
] as const
|
|
500
|
-
|
|
501
|
-
for (const [name, path] of primitivePairs) {
|
|
502
|
-
it(`${name} has displayName = "${name}"`, async () => {
|
|
503
|
-
const mod = await import(path)
|
|
504
|
-
expect(mod.default.displayName).toBe(name)
|
|
505
|
-
})
|
|
506
|
-
|
|
507
|
-
it(`${name} is a function`, async () => {
|
|
508
|
-
const mod = await import(path)
|
|
509
|
-
expect(typeof mod.default).toBe('function')
|
|
510
|
-
})
|
|
511
|
-
|
|
512
|
-
it(`${name} has IS_ROCKETSTYLE = true`, async () => {
|
|
513
|
-
const mod = await import(path)
|
|
514
|
-
expect(mod.default.IS_ROCKETSTYLE).toBe(true)
|
|
515
|
-
})
|
|
516
|
-
}
|
|
517
|
-
})
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import DocButton from '../primitives/DocButton'
|
|
3
|
-
import DocCode from '../primitives/DocCode'
|
|
4
|
-
import DocColumn from '../primitives/DocColumn'
|
|
5
|
-
import DocDivider from '../primitives/DocDivider'
|
|
6
|
-
import DocDocument from '../primitives/DocDocument'
|
|
7
|
-
import DocHeading from '../primitives/DocHeading'
|
|
8
|
-
import DocImage from '../primitives/DocImage'
|
|
9
|
-
import DocLink from '../primitives/DocLink'
|
|
10
|
-
import DocList from '../primitives/DocList'
|
|
11
|
-
import DocListItem from '../primitives/DocListItem'
|
|
12
|
-
import DocPage from '../primitives/DocPage'
|
|
13
|
-
import DocPageBreak from '../primitives/DocPageBreak'
|
|
14
|
-
import DocQuote from '../primitives/DocQuote'
|
|
15
|
-
import DocRow from '../primitives/DocRow'
|
|
16
|
-
import DocSection from '../primitives/DocSection'
|
|
17
|
-
import DocSpacer from '../primitives/DocSpacer'
|
|
18
|
-
import DocTable from '../primitives/DocTable'
|
|
19
|
-
import DocText from '../primitives/DocText'
|
|
20
|
-
|
|
21
|
-
describe('document primitives _documentType markers', () => {
|
|
22
|
-
const components = [
|
|
23
|
-
{ name: 'DocDocument', component: DocDocument, type: 'document' },
|
|
24
|
-
{ name: 'DocPage', component: DocPage, type: 'page' },
|
|
25
|
-
{ name: 'DocSection', component: DocSection, type: 'section' },
|
|
26
|
-
{ name: 'DocRow', component: DocRow, type: 'row' },
|
|
27
|
-
{ name: 'DocColumn', component: DocColumn, type: 'column' },
|
|
28
|
-
{ name: 'DocHeading', component: DocHeading, type: 'heading' },
|
|
29
|
-
{ name: 'DocText', component: DocText, type: 'text' },
|
|
30
|
-
{ name: 'DocLink', component: DocLink, type: 'link' },
|
|
31
|
-
{ name: 'DocImage', component: DocImage, type: 'image' },
|
|
32
|
-
{ name: 'DocTable', component: DocTable, type: 'table' },
|
|
33
|
-
{ name: 'DocList', component: DocList, type: 'list' },
|
|
34
|
-
{ name: 'DocListItem', component: DocListItem, type: 'list-item' },
|
|
35
|
-
{ name: 'DocCode', component: DocCode, type: 'code' },
|
|
36
|
-
{ name: 'DocDivider', component: DocDivider, type: 'divider' },
|
|
37
|
-
{ name: 'DocSpacer', component: DocSpacer, type: 'spacer' },
|
|
38
|
-
{ name: 'DocButton', component: DocButton, type: 'button' },
|
|
39
|
-
{ name: 'DocQuote', component: DocQuote, type: 'quote' },
|
|
40
|
-
{ name: 'DocPageBreak', component: DocPageBreak, type: 'page-break' },
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
for (const { name, component, type } of components) {
|
|
44
|
-
it(`${name} has _documentType = "${type}"`, () => {
|
|
45
|
-
expect((component as any)._documentType).toBe(type)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
it('all 18 node types are covered', () => {
|
|
50
|
-
expect(components).toHaveLength(18)
|
|
51
|
-
const types = new Set(components.map((c) => c.type))
|
|
52
|
-
expect(types.size).toBe(18)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
describe('document primitives have displayName', () => {
|
|
57
|
-
it('DocHeading', () => {
|
|
58
|
-
expect(DocHeading.displayName).toBe('DocHeading')
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('DocText', () => {
|
|
62
|
-
expect(DocText.displayName).toBe('DocText')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('DocSection', () => {
|
|
66
|
-
expect(DocSection.displayName).toBe('DocSection')
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('DocTable', () => {
|
|
70
|
-
expect(DocTable.displayName).toBe('DocTable')
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('document primitives are callable', () => {
|
|
75
|
-
it('DocHeading is a function', () => {
|
|
76
|
-
expect(typeof DocHeading).toBe('function')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('DocText is a function', () => {
|
|
80
|
-
expect(typeof DocText).toBe('function')
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('DocTable is a function', () => {
|
|
84
|
-
expect(typeof DocTable).toBe('function')
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('DocDocument is a function', () => {
|
|
88
|
-
expect(typeof DocDocument).toBe('function')
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
describe('document primitives IS_ROCKETSTYLE', () => {
|
|
93
|
-
it('DocHeading is a rocketstyle component', () => {
|
|
94
|
-
expect((DocHeading as any).IS_ROCKETSTYLE).toBe(true)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('DocText is a rocketstyle component', () => {
|
|
98
|
-
expect((DocText as any).IS_ROCKETSTYLE).toBe(true)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('DocSection is a rocketstyle component', () => {
|
|
102
|
-
expect((DocSection as any).IS_ROCKETSTYLE).toBe(true)
|
|
103
|
-
})
|
|
104
|
-
})
|