@pyreon/document-primitives 0.11.4 → 0.11.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/lib/index.d.ts +1 -1
- package/lib/index.js +11 -11
- package/package.json +34 -33
- package/src/DocumentPreview.ts +24 -24
- package/src/__tests__/primitives-attrs.test.ts +238 -300
- package/src/__tests__/primitives.test.ts +61 -61
- package/src/__tests__/useDocumentExport.test.ts +28 -28
- package/src/index.ts +25 -25
- package/src/primitives/DocButton.ts +17 -17
- package/src/primitives/DocCode.ts +8 -8
- package/src/primitives/DocColumn.ts +5 -5
- package/src/primitives/DocDivider.ts +6 -6
- package/src/primitives/DocDocument.ts +5 -5
- package/src/primitives/DocHeading.ts +9 -9
- package/src/primitives/DocImage.ts +6 -6
- package/src/primitives/DocLink.ts +8 -8
- package/src/primitives/DocList.ts +5 -5
- package/src/primitives/DocListItem.ts +5 -5
- package/src/primitives/DocPage.ts +7 -7
- package/src/primitives/DocPageBreak.ts +5 -5
- package/src/primitives/DocQuote.ts +9 -9
- package/src/primitives/DocRow.ts +6 -6
- package/src/primitives/DocSection.ts +8 -8
- package/src/primitives/DocSpacer.ts +5 -5
- package/src/primitives/DocTable.ts +7 -7
- package/src/primitives/DocText.ts +12 -12
- package/src/theme.ts +11 -11
- package/src/useDocumentExport.ts +3 -3
|
@@ -1,105 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { config } from "@pyreon/ui-core"
|
|
4
|
-
import { afterAll, beforeAll, describe, expect, it } from "vitest"
|
|
5
|
-
|
|
6
|
-
// Mock styled function that returns the component unchanged
|
|
7
|
-
const mockStyled = (component: any) => {
|
|
8
|
-
const taggedTemplate = (_strings: any, ..._args: any[]) => component
|
|
9
|
-
return taggedTemplate
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const mockCss = (_strings: any, ..._args: any[]) => ""
|
|
13
|
-
|
|
14
|
-
const originalStyled = config.styled
|
|
15
|
-
const originalCss = config.css
|
|
1
|
+
import { initTestConfig, renderProps } from '@pyreon/test-utils'
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
16
3
|
|
|
4
|
+
let cleanup: () => void
|
|
17
5
|
beforeAll(() => {
|
|
18
|
-
|
|
19
|
-
css: mockCss as any,
|
|
20
|
-
styled: mockStyled as any,
|
|
21
|
-
component: "div",
|
|
22
|
-
textComponent: "span",
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
afterAll(() => {
|
|
27
|
-
config.styled = originalStyled
|
|
28
|
-
config.css = originalCss
|
|
6
|
+
cleanup = initTestConfig()
|
|
29
7
|
})
|
|
30
|
-
|
|
31
|
-
/** Push a theme context and call fn, then pop context. */
|
|
32
|
-
const withThemeContext = (fn: () => any) => {
|
|
33
|
-
pushContext(
|
|
34
|
-
new Map([
|
|
35
|
-
[
|
|
36
|
-
context.id,
|
|
37
|
-
{
|
|
38
|
-
theme: { rootSize: 16 },
|
|
39
|
-
mode: "light",
|
|
40
|
-
isDark: false,
|
|
41
|
-
isLight: true,
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
]),
|
|
45
|
-
)
|
|
46
|
-
try {
|
|
47
|
-
return fn()
|
|
48
|
-
} finally {
|
|
49
|
-
popContext()
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Unwrap reactive accessors (EnhancedComponent returns a function for mode switching). */
|
|
54
|
-
const unwrap = (val: any): any => {
|
|
55
|
-
let result = val
|
|
56
|
-
while (typeof result === "function" && !result.IS_ROCKETSTYLE) result = result()
|
|
57
|
-
return result
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Call a rocketstyle component and return its rendered VNode props. */
|
|
61
|
-
const renderProps = (Component: any, props: Record<string, any> = {}) => {
|
|
62
|
-
return withThemeContext(() => {
|
|
63
|
-
const vnode = unwrap(Component(props))
|
|
64
|
-
return vnode?.props ?? vnode
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Helper: Text-based components convert `tag` to `as` through the Text component;
|
|
69
|
-
// Element-based components keep `tag` as-is.
|
|
70
|
-
// Both pass `_documentProps` through to the rendered output.
|
|
8
|
+
afterAll(() => cleanup())
|
|
71
9
|
|
|
72
10
|
// --------------------------------------------------------
|
|
73
11
|
// DocDocument (Element-based)
|
|
74
12
|
// --------------------------------------------------------
|
|
75
|
-
describe(
|
|
76
|
-
it(
|
|
77
|
-
const DocDocument = (await import(
|
|
78
|
-
const result = renderProps(DocDocument, { children:
|
|
79
|
-
expect(result.tag).toBe(
|
|
13
|
+
describe('DocDocument attrs', () => {
|
|
14
|
+
it('sets tag to div', async () => {
|
|
15
|
+
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
16
|
+
const result = renderProps(DocDocument, { children: 'test' })
|
|
17
|
+
expect(result.tag).toBe('div')
|
|
80
18
|
})
|
|
81
19
|
|
|
82
|
-
it(
|
|
83
|
-
const DocDocument = (await import(
|
|
84
|
-
const result = renderProps(DocDocument, { title:
|
|
85
|
-
expect(result._documentProps.title).toBe(
|
|
20
|
+
it('passes title to _documentProps', async () => {
|
|
21
|
+
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
22
|
+
const result = renderProps(DocDocument, { title: 'My Doc', children: 'test' })
|
|
23
|
+
expect(result._documentProps.title).toBe('My Doc')
|
|
86
24
|
})
|
|
87
25
|
|
|
88
|
-
it(
|
|
89
|
-
const DocDocument = (await import(
|
|
90
|
-
const result = renderProps(DocDocument, { author:
|
|
91
|
-
expect(result._documentProps.author).toBe(
|
|
26
|
+
it('passes author to _documentProps', async () => {
|
|
27
|
+
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
28
|
+
const result = renderProps(DocDocument, { author: 'Jane', children: 'test' })
|
|
29
|
+
expect(result._documentProps.author).toBe('Jane')
|
|
92
30
|
})
|
|
93
31
|
|
|
94
|
-
it(
|
|
95
|
-
const DocDocument = (await import(
|
|
96
|
-
const result = renderProps(DocDocument, { subject:
|
|
97
|
-
expect(result._documentProps.subject).toBe(
|
|
32
|
+
it('passes subject to _documentProps', async () => {
|
|
33
|
+
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
34
|
+
const result = renderProps(DocDocument, { subject: 'Report', children: 'test' })
|
|
35
|
+
expect(result._documentProps.subject).toBe('Report')
|
|
98
36
|
})
|
|
99
37
|
|
|
100
|
-
it(
|
|
101
|
-
const DocDocument = (await import(
|
|
102
|
-
const result = renderProps(DocDocument, { children:
|
|
38
|
+
it('omits missing optional fields from _documentProps', async () => {
|
|
39
|
+
const DocDocument = (await import('../primitives/DocDocument')).default
|
|
40
|
+
const result = renderProps(DocDocument, { children: 'test' })
|
|
103
41
|
expect(result._documentProps).toEqual({})
|
|
104
42
|
})
|
|
105
43
|
})
|
|
@@ -107,25 +45,25 @@ describe("DocDocument attrs", () => {
|
|
|
107
45
|
// --------------------------------------------------------
|
|
108
46
|
// DocHeading (Text-based: tag -> as)
|
|
109
47
|
// --------------------------------------------------------
|
|
110
|
-
describe(
|
|
111
|
-
it(
|
|
112
|
-
const DocHeading = (await import(
|
|
113
|
-
const result = renderProps(DocHeading, { children:
|
|
114
|
-
expect(result.as).toBe(
|
|
48
|
+
describe('DocHeading attrs', () => {
|
|
49
|
+
it('defaults to h1', async () => {
|
|
50
|
+
const DocHeading = (await import('../primitives/DocHeading')).default
|
|
51
|
+
const result = renderProps(DocHeading, { children: 'Hello' })
|
|
52
|
+
expect(result.as).toBe('h1')
|
|
115
53
|
expect(result._documentProps.level).toBe(1)
|
|
116
54
|
})
|
|
117
55
|
|
|
118
|
-
it(
|
|
119
|
-
const DocHeading = (await import(
|
|
120
|
-
const result = renderProps(DocHeading, { level:
|
|
121
|
-
expect(result.as).toBe(
|
|
56
|
+
it('sets tag to h2 when level is h2', async () => {
|
|
57
|
+
const DocHeading = (await import('../primitives/DocHeading')).default
|
|
58
|
+
const result = renderProps(DocHeading, { level: 'h2', children: 'Hello' })
|
|
59
|
+
expect(result.as).toBe('h2')
|
|
122
60
|
expect(result._documentProps.level).toBe(2)
|
|
123
61
|
})
|
|
124
62
|
|
|
125
|
-
it(
|
|
126
|
-
const DocHeading = (await import(
|
|
127
|
-
const result = renderProps(DocHeading, { level:
|
|
128
|
-
expect(result.as).toBe(
|
|
63
|
+
it('parses level h6', async () => {
|
|
64
|
+
const DocHeading = (await import('../primitives/DocHeading')).default
|
|
65
|
+
const result = renderProps(DocHeading, { level: 'h6', children: 'Hello' })
|
|
66
|
+
expect(result.as).toBe('h6')
|
|
129
67
|
expect(result._documentProps.level).toBe(6)
|
|
130
68
|
})
|
|
131
69
|
})
|
|
@@ -133,11 +71,11 @@ describe("DocHeading attrs", () => {
|
|
|
133
71
|
// --------------------------------------------------------
|
|
134
72
|
// DocText (Text-based: tag -> as)
|
|
135
73
|
// --------------------------------------------------------
|
|
136
|
-
describe(
|
|
137
|
-
it(
|
|
138
|
-
const DocText = (await import(
|
|
139
|
-
const result = renderProps(DocText, { children:
|
|
140
|
-
expect(result.as).toBe(
|
|
74
|
+
describe('DocText attrs', () => {
|
|
75
|
+
it('sets tag to p', async () => {
|
|
76
|
+
const DocText = (await import('../primitives/DocText')).default
|
|
77
|
+
const result = renderProps(DocText, { children: 'Hello' })
|
|
78
|
+
expect(result.as).toBe('p')
|
|
141
79
|
expect(result._documentProps).toEqual({})
|
|
142
80
|
})
|
|
143
81
|
})
|
|
@@ -145,66 +83,66 @@ describe("DocText attrs", () => {
|
|
|
145
83
|
// --------------------------------------------------------
|
|
146
84
|
// DocLink (Text-based: tag -> as)
|
|
147
85
|
// --------------------------------------------------------
|
|
148
|
-
describe(
|
|
149
|
-
it(
|
|
150
|
-
const DocLink = (await import(
|
|
151
|
-
const result = renderProps(DocLink, { children:
|
|
152
|
-
expect(result.as).toBe(
|
|
86
|
+
describe('DocLink attrs', () => {
|
|
87
|
+
it('sets tag to a', async () => {
|
|
88
|
+
const DocLink = (await import('../primitives/DocLink')).default
|
|
89
|
+
const result = renderProps(DocLink, { children: 'Click' })
|
|
90
|
+
expect(result.as).toBe('a')
|
|
153
91
|
})
|
|
154
92
|
|
|
155
|
-
it(
|
|
156
|
-
const DocLink = (await import(
|
|
157
|
-
const result = renderProps(DocLink, { href:
|
|
158
|
-
expect(result._documentProps.href).toBe(
|
|
93
|
+
it('passes href to _documentProps', async () => {
|
|
94
|
+
const DocLink = (await import('../primitives/DocLink')).default
|
|
95
|
+
const result = renderProps(DocLink, { href: 'https://example.com', children: 'Click' })
|
|
96
|
+
expect(result._documentProps.href).toBe('https://example.com')
|
|
159
97
|
})
|
|
160
98
|
|
|
161
|
-
it(
|
|
162
|
-
const DocLink = (await import(
|
|
163
|
-
const result = renderProps(DocLink, { children:
|
|
164
|
-
expect(result._documentProps.href).toBe(
|
|
99
|
+
it('defaults href to # when not provided', async () => {
|
|
100
|
+
const DocLink = (await import('../primitives/DocLink')).default
|
|
101
|
+
const result = renderProps(DocLink, { children: 'Click' })
|
|
102
|
+
expect(result._documentProps.href).toBe('#')
|
|
165
103
|
})
|
|
166
104
|
})
|
|
167
105
|
|
|
168
106
|
// --------------------------------------------------------
|
|
169
107
|
// DocImage (Element-based)
|
|
170
108
|
// --------------------------------------------------------
|
|
171
|
-
describe(
|
|
172
|
-
it(
|
|
173
|
-
const DocImage = (await import(
|
|
109
|
+
describe('DocImage attrs', () => {
|
|
110
|
+
it('sets tag to img', async () => {
|
|
111
|
+
const DocImage = (await import('../primitives/DocImage')).default
|
|
174
112
|
const result = renderProps(DocImage, { children: null })
|
|
175
|
-
expect(result.tag).toBe(
|
|
113
|
+
expect(result.tag).toBe('img')
|
|
176
114
|
})
|
|
177
115
|
|
|
178
|
-
it(
|
|
179
|
-
const DocImage = (await import(
|
|
180
|
-
const result = renderProps(DocImage, { src:
|
|
181
|
-
expect(result._documentProps.src).toBe(
|
|
116
|
+
it('passes src to _documentProps', async () => {
|
|
117
|
+
const DocImage = (await import('../primitives/DocImage')).default
|
|
118
|
+
const result = renderProps(DocImage, { src: 'photo.png', children: null })
|
|
119
|
+
expect(result._documentProps.src).toBe('photo.png')
|
|
182
120
|
})
|
|
183
121
|
|
|
184
|
-
it(
|
|
185
|
-
const DocImage = (await import(
|
|
122
|
+
it('defaults src to empty string', async () => {
|
|
123
|
+
const DocImage = (await import('../primitives/DocImage')).default
|
|
186
124
|
const result = renderProps(DocImage, { children: null })
|
|
187
|
-
expect(result._documentProps.src).toBe(
|
|
125
|
+
expect(result._documentProps.src).toBe('')
|
|
188
126
|
})
|
|
189
127
|
|
|
190
|
-
it(
|
|
191
|
-
const DocImage = (await import(
|
|
128
|
+
it('passes alt, width, height, caption when provided', async () => {
|
|
129
|
+
const DocImage = (await import('../primitives/DocImage')).default
|
|
192
130
|
const result = renderProps(DocImage, {
|
|
193
|
-
src:
|
|
194
|
-
alt:
|
|
131
|
+
src: 'photo.png',
|
|
132
|
+
alt: 'A photo',
|
|
195
133
|
width: 200,
|
|
196
134
|
height: 100,
|
|
197
|
-
caption:
|
|
135
|
+
caption: 'My photo',
|
|
198
136
|
children: null,
|
|
199
137
|
})
|
|
200
|
-
expect(result._documentProps.alt).toBe(
|
|
138
|
+
expect(result._documentProps.alt).toBe('A photo')
|
|
201
139
|
expect(result._documentProps.width).toBe(200)
|
|
202
140
|
expect(result._documentProps.height).toBe(100)
|
|
203
|
-
expect(result._documentProps.caption).toBe(
|
|
141
|
+
expect(result._documentProps.caption).toBe('My photo')
|
|
204
142
|
})
|
|
205
143
|
|
|
206
|
-
it(
|
|
207
|
-
const DocImage = (await import(
|
|
144
|
+
it('omits alt, width, height, caption when not provided', async () => {
|
|
145
|
+
const DocImage = (await import('../primitives/DocImage')).default
|
|
208
146
|
const result = renderProps(DocImage, { children: null })
|
|
209
147
|
expect(result._documentProps.alt).toBeUndefined()
|
|
210
148
|
expect(result._documentProps.width).toBeUndefined()
|
|
@@ -216,59 +154,59 @@ describe("DocImage attrs", () => {
|
|
|
216
154
|
// --------------------------------------------------------
|
|
217
155
|
// DocTable (Element-based)
|
|
218
156
|
// --------------------------------------------------------
|
|
219
|
-
describe(
|
|
220
|
-
it(
|
|
221
|
-
const DocTable = (await import(
|
|
157
|
+
describe('DocTable attrs', () => {
|
|
158
|
+
it('sets tag to table', async () => {
|
|
159
|
+
const DocTable = (await import('../primitives/DocTable')).default
|
|
222
160
|
const result = renderProps(DocTable, { children: null })
|
|
223
|
-
expect(result.tag).toBe(
|
|
161
|
+
expect(result.tag).toBe('table')
|
|
224
162
|
})
|
|
225
163
|
|
|
226
|
-
it(
|
|
227
|
-
const DocTable = (await import(
|
|
164
|
+
it('defaults columns and rows to empty arrays', async () => {
|
|
165
|
+
const DocTable = (await import('../primitives/DocTable')).default
|
|
228
166
|
const result = renderProps(DocTable, { children: null })
|
|
229
167
|
expect(result._documentProps.columns).toEqual([])
|
|
230
168
|
expect(result._documentProps.rows).toEqual([])
|
|
231
169
|
})
|
|
232
170
|
|
|
233
|
-
it(
|
|
234
|
-
const DocTable = (await import(
|
|
171
|
+
it('passes all table options when provided', async () => {
|
|
172
|
+
const DocTable = (await import('../primitives/DocTable')).default
|
|
235
173
|
const result = renderProps(DocTable, {
|
|
236
|
-
columns: [{ header:
|
|
237
|
-
rows: [[
|
|
238
|
-
headerStyle: { fontWeight:
|
|
174
|
+
columns: [{ header: 'Name' }],
|
|
175
|
+
rows: [['Alice']],
|
|
176
|
+
headerStyle: { fontWeight: 'bold' },
|
|
239
177
|
striped: true,
|
|
240
178
|
bordered: true,
|
|
241
|
-
caption:
|
|
179
|
+
caption: 'Users',
|
|
242
180
|
children: null,
|
|
243
181
|
})
|
|
244
|
-
expect(result._documentProps.columns).toEqual([{ header:
|
|
245
|
-
expect(result._documentProps.rows).toEqual([[
|
|
246
|
-
expect(result._documentProps.headerStyle).toEqual({ fontWeight:
|
|
182
|
+
expect(result._documentProps.columns).toEqual([{ header: 'Name' }])
|
|
183
|
+
expect(result._documentProps.rows).toEqual([['Alice']])
|
|
184
|
+
expect(result._documentProps.headerStyle).toEqual({ fontWeight: 'bold' })
|
|
247
185
|
expect(result._documentProps.striped).toBe(true)
|
|
248
186
|
expect(result._documentProps.bordered).toBe(true)
|
|
249
|
-
expect(result._documentProps.caption).toBe(
|
|
187
|
+
expect(result._documentProps.caption).toBe('Users')
|
|
250
188
|
})
|
|
251
189
|
})
|
|
252
190
|
|
|
253
191
|
// --------------------------------------------------------
|
|
254
192
|
// DocList (Element-based)
|
|
255
193
|
// --------------------------------------------------------
|
|
256
|
-
describe(
|
|
257
|
-
it(
|
|
258
|
-
const DocList = (await import(
|
|
194
|
+
describe('DocList attrs', () => {
|
|
195
|
+
it('sets tag to ul by default', async () => {
|
|
196
|
+
const DocList = (await import('../primitives/DocList')).default
|
|
259
197
|
const result = renderProps(DocList, { children: null })
|
|
260
|
-
expect(result.tag).toBe(
|
|
198
|
+
expect(result.tag).toBe('ul')
|
|
261
199
|
})
|
|
262
200
|
|
|
263
|
-
it(
|
|
264
|
-
const DocList = (await import(
|
|
201
|
+
it('sets tag to ol when ordered is true', async () => {
|
|
202
|
+
const DocList = (await import('../primitives/DocList')).default
|
|
265
203
|
const result = renderProps(DocList, { ordered: true, children: null })
|
|
266
|
-
expect(result.tag).toBe(
|
|
204
|
+
expect(result.tag).toBe('ol')
|
|
267
205
|
expect(result._documentProps.ordered).toBe(true)
|
|
268
206
|
})
|
|
269
207
|
|
|
270
|
-
it(
|
|
271
|
-
const DocList = (await import(
|
|
208
|
+
it('has empty _documentProps when not ordered', async () => {
|
|
209
|
+
const DocList = (await import('../primitives/DocList')).default
|
|
272
210
|
const result = renderProps(DocList, { children: null })
|
|
273
211
|
expect(result._documentProps).toEqual({})
|
|
274
212
|
})
|
|
@@ -277,11 +215,11 @@ describe("DocList attrs", () => {
|
|
|
277
215
|
// --------------------------------------------------------
|
|
278
216
|
// DocListItem (Text-based: tag -> as)
|
|
279
217
|
// --------------------------------------------------------
|
|
280
|
-
describe(
|
|
281
|
-
it(
|
|
282
|
-
const DocListItem = (await import(
|
|
283
|
-
const result = renderProps(DocListItem, { children:
|
|
284
|
-
expect(result.as).toBe(
|
|
218
|
+
describe('DocListItem attrs', () => {
|
|
219
|
+
it('sets tag to li', async () => {
|
|
220
|
+
const DocListItem = (await import('../primitives/DocListItem')).default
|
|
221
|
+
const result = renderProps(DocListItem, { children: 'item' })
|
|
222
|
+
expect(result.as).toBe('li')
|
|
285
223
|
expect(result._documentProps).toEqual({})
|
|
286
224
|
})
|
|
287
225
|
})
|
|
@@ -289,22 +227,22 @@ describe("DocListItem attrs", () => {
|
|
|
289
227
|
// --------------------------------------------------------
|
|
290
228
|
// DocCode (Text-based: tag -> as)
|
|
291
229
|
// --------------------------------------------------------
|
|
292
|
-
describe(
|
|
293
|
-
it(
|
|
294
|
-
const DocCode = (await import(
|
|
295
|
-
const result = renderProps(DocCode, { children:
|
|
296
|
-
expect(result.as).toBe(
|
|
230
|
+
describe('DocCode attrs', () => {
|
|
231
|
+
it('sets tag to pre', async () => {
|
|
232
|
+
const DocCode = (await import('../primitives/DocCode')).default
|
|
233
|
+
const result = renderProps(DocCode, { children: 'code' })
|
|
234
|
+
expect(result.as).toBe('pre')
|
|
297
235
|
})
|
|
298
236
|
|
|
299
|
-
it(
|
|
300
|
-
const DocCode = (await import(
|
|
301
|
-
const result = renderProps(DocCode, { language:
|
|
302
|
-
expect(result._documentProps.language).toBe(
|
|
237
|
+
it('passes language to _documentProps when provided', async () => {
|
|
238
|
+
const DocCode = (await import('../primitives/DocCode')).default
|
|
239
|
+
const result = renderProps(DocCode, { language: 'typescript', children: 'code' })
|
|
240
|
+
expect(result._documentProps.language).toBe('typescript')
|
|
303
241
|
})
|
|
304
242
|
|
|
305
|
-
it(
|
|
306
|
-
const DocCode = (await import(
|
|
307
|
-
const result = renderProps(DocCode, { children:
|
|
243
|
+
it('has empty _documentProps when no language', async () => {
|
|
244
|
+
const DocCode = (await import('../primitives/DocCode')).default
|
|
245
|
+
const result = renderProps(DocCode, { children: 'code' })
|
|
308
246
|
expect(result._documentProps).toEqual({})
|
|
309
247
|
})
|
|
310
248
|
})
|
|
@@ -312,22 +250,22 @@ describe("DocCode attrs", () => {
|
|
|
312
250
|
// --------------------------------------------------------
|
|
313
251
|
// DocDivider (Element-based)
|
|
314
252
|
// --------------------------------------------------------
|
|
315
|
-
describe(
|
|
316
|
-
it(
|
|
317
|
-
const DocDivider = (await import(
|
|
253
|
+
describe('DocDivider attrs', () => {
|
|
254
|
+
it('sets tag to hr', async () => {
|
|
255
|
+
const DocDivider = (await import('../primitives/DocDivider')).default
|
|
318
256
|
const result = renderProps(DocDivider, { children: null })
|
|
319
|
-
expect(result.tag).toBe(
|
|
257
|
+
expect(result.tag).toBe('hr')
|
|
320
258
|
})
|
|
321
259
|
|
|
322
|
-
it(
|
|
323
|
-
const DocDivider = (await import(
|
|
324
|
-
const result = renderProps(DocDivider, { color:
|
|
325
|
-
expect(result._documentProps.color).toBe(
|
|
260
|
+
it('passes color and thickness when provided', async () => {
|
|
261
|
+
const DocDivider = (await import('../primitives/DocDivider')).default
|
|
262
|
+
const result = renderProps(DocDivider, { color: 'red', thickness: 2, children: null })
|
|
263
|
+
expect(result._documentProps.color).toBe('red')
|
|
326
264
|
expect(result._documentProps.thickness).toBe(2)
|
|
327
265
|
})
|
|
328
266
|
|
|
329
|
-
it(
|
|
330
|
-
const DocDivider = (await import(
|
|
267
|
+
it('omits color and thickness when not provided', async () => {
|
|
268
|
+
const DocDivider = (await import('../primitives/DocDivider')).default
|
|
331
269
|
const result = renderProps(DocDivider, { children: null })
|
|
332
270
|
expect(result._documentProps).toEqual({})
|
|
333
271
|
})
|
|
@@ -336,27 +274,27 @@ describe("DocDivider attrs", () => {
|
|
|
336
274
|
// --------------------------------------------------------
|
|
337
275
|
// DocPage (Element-based)
|
|
338
276
|
// --------------------------------------------------------
|
|
339
|
-
describe(
|
|
340
|
-
it(
|
|
341
|
-
const DocPage = (await import(
|
|
342
|
-
const result = renderProps(DocPage, { children:
|
|
343
|
-
expect(result.tag).toBe(
|
|
277
|
+
describe('DocPage attrs', () => {
|
|
278
|
+
it('sets tag to div', async () => {
|
|
279
|
+
const DocPage = (await import('../primitives/DocPage')).default
|
|
280
|
+
const result = renderProps(DocPage, { children: 'page' })
|
|
281
|
+
expect(result.tag).toBe('div')
|
|
344
282
|
})
|
|
345
283
|
|
|
346
|
-
it(
|
|
347
|
-
const DocPage = (await import(
|
|
284
|
+
it('passes size and orientation when provided', async () => {
|
|
285
|
+
const DocPage = (await import('../primitives/DocPage')).default
|
|
348
286
|
const result = renderProps(DocPage, {
|
|
349
|
-
size:
|
|
350
|
-
orientation:
|
|
351
|
-
children:
|
|
287
|
+
size: 'A4',
|
|
288
|
+
orientation: 'landscape',
|
|
289
|
+
children: 'page',
|
|
352
290
|
})
|
|
353
|
-
expect(result._documentProps.size).toBe(
|
|
354
|
-
expect(result._documentProps.orientation).toBe(
|
|
291
|
+
expect(result._documentProps.size).toBe('A4')
|
|
292
|
+
expect(result._documentProps.orientation).toBe('landscape')
|
|
355
293
|
})
|
|
356
294
|
|
|
357
|
-
it(
|
|
358
|
-
const DocPage = (await import(
|
|
359
|
-
const result = renderProps(DocPage, { children:
|
|
295
|
+
it('omits size and orientation when not provided', async () => {
|
|
296
|
+
const DocPage = (await import('../primitives/DocPage')).default
|
|
297
|
+
const result = renderProps(DocPage, { children: 'page' })
|
|
360
298
|
expect(result._documentProps).toEqual({})
|
|
361
299
|
})
|
|
362
300
|
})
|
|
@@ -364,11 +302,11 @@ describe("DocPage attrs", () => {
|
|
|
364
302
|
// --------------------------------------------------------
|
|
365
303
|
// DocPageBreak (Element-based)
|
|
366
304
|
// --------------------------------------------------------
|
|
367
|
-
describe(
|
|
368
|
-
it(
|
|
369
|
-
const DocPageBreak = (await import(
|
|
305
|
+
describe('DocPageBreak attrs', () => {
|
|
306
|
+
it('sets tag to div with empty _documentProps', async () => {
|
|
307
|
+
const DocPageBreak = (await import('../primitives/DocPageBreak')).default
|
|
370
308
|
const result = renderProps(DocPageBreak, { children: null })
|
|
371
|
-
expect(result.tag).toBe(
|
|
309
|
+
expect(result.tag).toBe('div')
|
|
372
310
|
expect(result._documentProps).toEqual({})
|
|
373
311
|
})
|
|
374
312
|
})
|
|
@@ -376,22 +314,22 @@ describe("DocPageBreak attrs", () => {
|
|
|
376
314
|
// --------------------------------------------------------
|
|
377
315
|
// DocQuote (Element-based)
|
|
378
316
|
// --------------------------------------------------------
|
|
379
|
-
describe(
|
|
380
|
-
it(
|
|
381
|
-
const DocQuote = (await import(
|
|
382
|
-
const result = renderProps(DocQuote, { children:
|
|
383
|
-
expect(result.tag).toBe(
|
|
317
|
+
describe('DocQuote attrs', () => {
|
|
318
|
+
it('sets tag to blockquote', async () => {
|
|
319
|
+
const DocQuote = (await import('../primitives/DocQuote')).default
|
|
320
|
+
const result = renderProps(DocQuote, { children: 'quote' })
|
|
321
|
+
expect(result.tag).toBe('blockquote')
|
|
384
322
|
})
|
|
385
323
|
|
|
386
|
-
it(
|
|
387
|
-
const DocQuote = (await import(
|
|
388
|
-
const result = renderProps(DocQuote, { borderColor:
|
|
389
|
-
expect(result._documentProps.borderColor).toBe(
|
|
324
|
+
it('passes borderColor when provided', async () => {
|
|
325
|
+
const DocQuote = (await import('../primitives/DocQuote')).default
|
|
326
|
+
const result = renderProps(DocQuote, { borderColor: '#ff0000', children: 'quote' })
|
|
327
|
+
expect(result._documentProps.borderColor).toBe('#ff0000')
|
|
390
328
|
})
|
|
391
329
|
|
|
392
|
-
it(
|
|
393
|
-
const DocQuote = (await import(
|
|
394
|
-
const result = renderProps(DocQuote, { children:
|
|
330
|
+
it('has empty _documentProps when no borderColor', async () => {
|
|
331
|
+
const DocQuote = (await import('../primitives/DocQuote')).default
|
|
332
|
+
const result = renderProps(DocQuote, { children: 'quote' })
|
|
395
333
|
expect(result._documentProps).toEqual({})
|
|
396
334
|
})
|
|
397
335
|
})
|
|
@@ -399,11 +337,11 @@ describe("DocQuote attrs", () => {
|
|
|
399
337
|
// --------------------------------------------------------
|
|
400
338
|
// DocRow (Element-based)
|
|
401
339
|
// --------------------------------------------------------
|
|
402
|
-
describe(
|
|
403
|
-
it(
|
|
404
|
-
const DocRow = (await import(
|
|
340
|
+
describe('DocRow attrs', () => {
|
|
341
|
+
it('sets tag to div with empty _documentProps', async () => {
|
|
342
|
+
const DocRow = (await import('../primitives/DocRow')).default
|
|
405
343
|
const result = renderProps(DocRow, { children: null })
|
|
406
|
-
expect(result.tag).toBe(
|
|
344
|
+
expect(result.tag).toBe('div')
|
|
407
345
|
expect(result._documentProps).toEqual({})
|
|
408
346
|
})
|
|
409
347
|
})
|
|
@@ -411,21 +349,21 @@ describe("DocRow attrs", () => {
|
|
|
411
349
|
// --------------------------------------------------------
|
|
412
350
|
// DocColumn (Element-based)
|
|
413
351
|
// --------------------------------------------------------
|
|
414
|
-
describe(
|
|
415
|
-
it(
|
|
416
|
-
const DocColumn = (await import(
|
|
352
|
+
describe('DocColumn attrs', () => {
|
|
353
|
+
it('sets tag to div', async () => {
|
|
354
|
+
const DocColumn = (await import('../primitives/DocColumn')).default
|
|
417
355
|
const result = renderProps(DocColumn, { children: null })
|
|
418
|
-
expect(result.tag).toBe(
|
|
356
|
+
expect(result.tag).toBe('div')
|
|
419
357
|
})
|
|
420
358
|
|
|
421
|
-
it(
|
|
422
|
-
const DocColumn = (await import(
|
|
423
|
-
const result = renderProps(DocColumn, { width:
|
|
424
|
-
expect(result._documentProps.width).toBe(
|
|
359
|
+
it('passes width to _documentProps when provided', async () => {
|
|
360
|
+
const DocColumn = (await import('../primitives/DocColumn')).default
|
|
361
|
+
const result = renderProps(DocColumn, { width: '50%', children: null })
|
|
362
|
+
expect(result._documentProps.width).toBe('50%')
|
|
425
363
|
})
|
|
426
364
|
|
|
427
|
-
it(
|
|
428
|
-
const DocColumn = (await import(
|
|
365
|
+
it('has empty _documentProps when no width', async () => {
|
|
366
|
+
const DocColumn = (await import('../primitives/DocColumn')).default
|
|
429
367
|
const result = renderProps(DocColumn, { children: null })
|
|
430
368
|
expect(result._documentProps).toEqual({})
|
|
431
369
|
})
|
|
@@ -434,21 +372,21 @@ describe("DocColumn attrs", () => {
|
|
|
434
372
|
// --------------------------------------------------------
|
|
435
373
|
// DocSpacer (Element-based)
|
|
436
374
|
// --------------------------------------------------------
|
|
437
|
-
describe(
|
|
438
|
-
it(
|
|
439
|
-
const DocSpacer = (await import(
|
|
375
|
+
describe('DocSpacer attrs', () => {
|
|
376
|
+
it('sets tag to div', async () => {
|
|
377
|
+
const DocSpacer = (await import('../primitives/DocSpacer')).default
|
|
440
378
|
const result = renderProps(DocSpacer, { children: null })
|
|
441
|
-
expect(result.tag).toBe(
|
|
379
|
+
expect(result.tag).toBe('div')
|
|
442
380
|
})
|
|
443
381
|
|
|
444
|
-
it(
|
|
445
|
-
const DocSpacer = (await import(
|
|
382
|
+
it('defaults height to 16', async () => {
|
|
383
|
+
const DocSpacer = (await import('../primitives/DocSpacer')).default
|
|
446
384
|
const result = renderProps(DocSpacer, { children: null })
|
|
447
385
|
expect(result._documentProps.height).toBe(16)
|
|
448
386
|
})
|
|
449
387
|
|
|
450
|
-
it(
|
|
451
|
-
const DocSpacer = (await import(
|
|
388
|
+
it('passes custom height', async () => {
|
|
389
|
+
const DocSpacer = (await import('../primitives/DocSpacer')).default
|
|
452
390
|
const result = renderProps(DocSpacer, { height: 32, children: null })
|
|
453
391
|
expect(result._documentProps.height).toBe(32)
|
|
454
392
|
})
|
|
@@ -457,73 +395,73 @@ describe("DocSpacer attrs", () => {
|
|
|
457
395
|
// --------------------------------------------------------
|
|
458
396
|
// DocSection (Element-based)
|
|
459
397
|
// --------------------------------------------------------
|
|
460
|
-
describe(
|
|
461
|
-
it(
|
|
462
|
-
const DocSection = (await import(
|
|
398
|
+
describe('DocSection attrs', () => {
|
|
399
|
+
it('sets tag to div', async () => {
|
|
400
|
+
const DocSection = (await import('../primitives/DocSection')).default
|
|
463
401
|
const result = renderProps(DocSection, { children: null })
|
|
464
|
-
expect(result.tag).toBe(
|
|
402
|
+
expect(result.tag).toBe('div')
|
|
465
403
|
})
|
|
466
404
|
|
|
467
|
-
it(
|
|
468
|
-
const DocSection = (await import(
|
|
405
|
+
it('defaults direction to column', async () => {
|
|
406
|
+
const DocSection = (await import('../primitives/DocSection')).default
|
|
469
407
|
const result = renderProps(DocSection, { children: null })
|
|
470
|
-
expect(result._documentProps.direction).toBe(
|
|
408
|
+
expect(result._documentProps.direction).toBe('column')
|
|
471
409
|
})
|
|
472
410
|
|
|
473
|
-
it(
|
|
474
|
-
const DocSection = (await import(
|
|
475
|
-
const result = renderProps(DocSection, { direction:
|
|
476
|
-
expect(result._documentProps.direction).toBe(
|
|
411
|
+
it('passes direction when provided', async () => {
|
|
412
|
+
const DocSection = (await import('../primitives/DocSection')).default
|
|
413
|
+
const result = renderProps(DocSection, { direction: 'row', children: null })
|
|
414
|
+
expect(result._documentProps.direction).toBe('row')
|
|
477
415
|
})
|
|
478
416
|
})
|
|
479
417
|
|
|
480
418
|
// --------------------------------------------------------
|
|
481
419
|
// DocButton (Text-based: tag -> as)
|
|
482
420
|
// --------------------------------------------------------
|
|
483
|
-
describe(
|
|
484
|
-
it(
|
|
485
|
-
const DocButton = (await import(
|
|
486
|
-
const result = renderProps(DocButton, { children:
|
|
487
|
-
expect(result.as).toBe(
|
|
421
|
+
describe('DocButton attrs', () => {
|
|
422
|
+
it('sets tag to a', async () => {
|
|
423
|
+
const DocButton = (await import('../primitives/DocButton')).default
|
|
424
|
+
const result = renderProps(DocButton, { children: 'Click' })
|
|
425
|
+
expect(result.as).toBe('a')
|
|
488
426
|
})
|
|
489
427
|
|
|
490
|
-
it(
|
|
491
|
-
const DocButton = (await import(
|
|
492
|
-
const result = renderProps(DocButton, { href:
|
|
493
|
-
expect(result._documentProps.href).toBe(
|
|
428
|
+
it('passes href to _documentProps', async () => {
|
|
429
|
+
const DocButton = (await import('../primitives/DocButton')).default
|
|
430
|
+
const result = renderProps(DocButton, { href: 'https://example.com', children: 'Click' })
|
|
431
|
+
expect(result._documentProps.href).toBe('https://example.com')
|
|
494
432
|
})
|
|
495
433
|
|
|
496
|
-
it(
|
|
497
|
-
const DocButton = (await import(
|
|
498
|
-
const result = renderProps(DocButton, { children:
|
|
499
|
-
expect(result._documentProps.href).toBe(
|
|
434
|
+
it('defaults href to # when not provided', async () => {
|
|
435
|
+
const DocButton = (await import('../primitives/DocButton')).default
|
|
436
|
+
const result = renderProps(DocButton, { children: 'Click' })
|
|
437
|
+
expect(result._documentProps.href).toBe('#')
|
|
500
438
|
})
|
|
501
439
|
})
|
|
502
440
|
|
|
503
441
|
// --------------------------------------------------------
|
|
504
442
|
// DocumentPreview (Element-based)
|
|
505
443
|
// --------------------------------------------------------
|
|
506
|
-
describe(
|
|
507
|
-
it(
|
|
508
|
-
const DocumentPreview = (await import(
|
|
444
|
+
describe('DocumentPreview attrs', () => {
|
|
445
|
+
it('sets tag to div', async () => {
|
|
446
|
+
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
509
447
|
const result = renderProps(DocumentPreview, { children: null })
|
|
510
|
-
expect(result.tag).toBe(
|
|
448
|
+
expect(result.tag).toBe('div')
|
|
511
449
|
})
|
|
512
450
|
|
|
513
|
-
it(
|
|
514
|
-
const DocumentPreview = (await import(
|
|
451
|
+
it('defaults size to A4 when not provided', async () => {
|
|
452
|
+
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
515
453
|
const result = renderProps(DocumentPreview, { children: null })
|
|
516
|
-
expect(result._documentProps.size).toBe(
|
|
454
|
+
expect(result._documentProps.size).toBe('A4')
|
|
517
455
|
})
|
|
518
456
|
|
|
519
|
-
it(
|
|
520
|
-
const DocumentPreview = (await import(
|
|
521
|
-
const result = renderProps(DocumentPreview, { size:
|
|
522
|
-
expect(result._documentProps.size).toBe(
|
|
457
|
+
it('passes custom size', async () => {
|
|
458
|
+
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
459
|
+
const result = renderProps(DocumentPreview, { size: 'letter', children: null })
|
|
460
|
+
expect(result._documentProps.size).toBe('letter')
|
|
523
461
|
})
|
|
524
462
|
|
|
525
|
-
it(
|
|
526
|
-
const DocumentPreview = (await import(
|
|
463
|
+
it('passes showPageBreaks when provided', async () => {
|
|
464
|
+
const DocumentPreview = (await import('../DocumentPreview')).default
|
|
527
465
|
const result = renderProps(DocumentPreview, { showPageBreaks: true, children: null })
|
|
528
466
|
expect(result._documentProps.showPageBreaks).toBe(true)
|
|
529
467
|
})
|
|
@@ -532,26 +470,26 @@ describe("DocumentPreview attrs", () => {
|
|
|
532
470
|
// --------------------------------------------------------
|
|
533
471
|
// All primitives: displayName and IS_ROCKETSTYLE coverage
|
|
534
472
|
// --------------------------------------------------------
|
|
535
|
-
describe(
|
|
473
|
+
describe('all primitives have correct displayName and IS_ROCKETSTYLE', () => {
|
|
536
474
|
const primitivePairs = [
|
|
537
|
-
[
|
|
538
|
-
[
|
|
539
|
-
[
|
|
540
|
-
[
|
|
541
|
-
[
|
|
542
|
-
[
|
|
543
|
-
[
|
|
544
|
-
[
|
|
545
|
-
[
|
|
546
|
-
[
|
|
547
|
-
[
|
|
548
|
-
[
|
|
549
|
-
[
|
|
550
|
-
[
|
|
551
|
-
[
|
|
552
|
-
[
|
|
553
|
-
[
|
|
554
|
-
[
|
|
475
|
+
['DocButton', '../primitives/DocButton'],
|
|
476
|
+
['DocCode', '../primitives/DocCode'],
|
|
477
|
+
['DocColumn', '../primitives/DocColumn'],
|
|
478
|
+
['DocDivider', '../primitives/DocDivider'],
|
|
479
|
+
['DocDocument', '../primitives/DocDocument'],
|
|
480
|
+
['DocHeading', '../primitives/DocHeading'],
|
|
481
|
+
['DocImage', '../primitives/DocImage'],
|
|
482
|
+
['DocLink', '../primitives/DocLink'],
|
|
483
|
+
['DocList', '../primitives/DocList'],
|
|
484
|
+
['DocListItem', '../primitives/DocListItem'],
|
|
485
|
+
['DocPage', '../primitives/DocPage'],
|
|
486
|
+
['DocPageBreak', '../primitives/DocPageBreak'],
|
|
487
|
+
['DocQuote', '../primitives/DocQuote'],
|
|
488
|
+
['DocRow', '../primitives/DocRow'],
|
|
489
|
+
['DocSection', '../primitives/DocSection'],
|
|
490
|
+
['DocSpacer', '../primitives/DocSpacer'],
|
|
491
|
+
['DocTable', '../primitives/DocTable'],
|
|
492
|
+
['DocText', '../primitives/DocText'],
|
|
555
493
|
] as const
|
|
556
494
|
|
|
557
495
|
for (const [name, path] of primitivePairs) {
|
|
@@ -562,7 +500,7 @@ describe("all primitives have correct displayName and IS_ROCKETSTYLE", () => {
|
|
|
562
500
|
|
|
563
501
|
it(`${name} is a function`, async () => {
|
|
564
502
|
const mod = await import(path)
|
|
565
|
-
expect(typeof mod.default).toBe(
|
|
503
|
+
expect(typeof mod.default).toBe('function')
|
|
566
504
|
})
|
|
567
505
|
|
|
568
506
|
it(`${name} has IS_ROCKETSTYLE = true`, async () => {
|