@cdc/markup-include 4.26.2 → 4.26.4
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/CONFIG.md +113 -0
- package/README.md +38 -14
- package/dist/cdcmarkupinclude.js +20835 -12893
- package/examples/minimal-example.json +11 -0
- package/package.json +4 -4
- package/src/CdcMarkupInclude.tsx +192 -108
- package/src/ConfigContext.ts +1 -0
- package/src/_stories/MarkupInclude.Editor.stories.tsx +57 -17
- package/src/_stories/MarkupInclude.smoke.stories.tsx +33 -0
- package/src/_stories/MarkupInclude.stories.tsx +81 -0
- package/src/cdcMarkupInclude.style.css +15 -11
- package/src/components/EditorPanel/EditorPanel.styles.css +1 -1
- package/src/components/EditorPanel/EditorPanel.tsx +271 -16
- package/src/data/initial-state.js +7 -1
- package/src/scss/main.scss +81 -10
- package/src/test/CdcMarkupInclude.test.jsx +74 -3
|
@@ -1,11 +1,82 @@
|
|
|
1
|
-
import path from 'path'
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import vm from 'node:vm'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import { render, screen } from '@testing-library/react'
|
|
2
6
|
import { testStandaloneBuild } from '@cdc/core/helpers/tests/testStandaloneBuild.ts'
|
|
3
|
-
import { describe, it, expect } from 'vitest'
|
|
7
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
8
|
+
import CdcMarkupInclude from '../CdcMarkupInclude'
|
|
9
|
+
|
|
10
|
+
vi.mock('@cdc/core/components/EditorPanel/components/MarkupVariablesEditor', () => ({
|
|
11
|
+
default: ({ data }) => <div data-testid='markup-variables-editor-data'>{JSON.stringify(data)}</div>
|
|
12
|
+
}))
|
|
13
|
+
|
|
14
|
+
const extractMarkedExampleConfig = (content, label) => {
|
|
15
|
+
const match = content.match(
|
|
16
|
+
/<!-- README_EXAMPLE_CONFIG_START -->\s*```jsx\s*([\s\S]*?)\s*```\s*<!-- README_EXAMPLE_CONFIG_END -->/
|
|
17
|
+
)
|
|
18
|
+
expect(match, `${label} should contain a marked README example block`).toBeTruthy()
|
|
19
|
+
const configMatch = match[1].match(/const config = (\{[\s\S]*?\})\n\nfunction App\(\)/)
|
|
20
|
+
expect(configMatch, `${label} should define const config before function App()`).toBeTruthy()
|
|
21
|
+
return vm.runInNewContext(`(${configMatch[1]})`)
|
|
22
|
+
}
|
|
4
23
|
|
|
5
24
|
describe('Markup Include', () => {
|
|
6
25
|
it('Can be built in isolation', async () => {
|
|
7
26
|
const pkgDir = path.join(__dirname, '..')
|
|
8
|
-
const result = testStandaloneBuild(pkgDir)
|
|
27
|
+
const result = await testStandaloneBuild(pkgDir)
|
|
9
28
|
expect(result).toBe(true)
|
|
10
29
|
}, 300000)
|
|
30
|
+
|
|
31
|
+
it('uses dashboard rawData for markup variable editor choices when editing', async () => {
|
|
32
|
+
const filteredData = [{ category: 'Filtered only' }]
|
|
33
|
+
const fullData = [{ category: 'Value A' }, { category: 'Value B' }]
|
|
34
|
+
|
|
35
|
+
render(
|
|
36
|
+
<CdcMarkupInclude
|
|
37
|
+
config={{
|
|
38
|
+
type: 'markup-include',
|
|
39
|
+
theme: 'theme-blue',
|
|
40
|
+
dataKey: 'test-dataset',
|
|
41
|
+
data: filteredData,
|
|
42
|
+
markupVariables: [],
|
|
43
|
+
contentEditor: {
|
|
44
|
+
title: '',
|
|
45
|
+
inlineHTML: '<p>Example</p>',
|
|
46
|
+
useInlineHTML: true,
|
|
47
|
+
srcUrl: ''
|
|
48
|
+
},
|
|
49
|
+
visual: {
|
|
50
|
+
border: false,
|
|
51
|
+
accent: false,
|
|
52
|
+
background: false,
|
|
53
|
+
hideBackgroundColor: false,
|
|
54
|
+
borderColorTheme: false
|
|
55
|
+
}
|
|
56
|
+
}}
|
|
57
|
+
datasets={{
|
|
58
|
+
'test-dataset': {
|
|
59
|
+
data: [{ category: 'Dataset fallback' }]
|
|
60
|
+
}
|
|
61
|
+
}}
|
|
62
|
+
rawData={fullData}
|
|
63
|
+
isDashboard={true}
|
|
64
|
+
isEditor={true}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect(JSON.parse((await screen.findByTestId('markup-variables-editor-data')).textContent)).toEqual(fullData)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('keeps the minimal example in sync with the README docs', () => {
|
|
72
|
+
const pkgRoot = path.join(__dirname, '..', '..')
|
|
73
|
+
const minimalExamplePath = path.join(pkgRoot, 'examples', 'minimal-example.json')
|
|
74
|
+
const readmePath = path.join(pkgRoot, 'README.md')
|
|
75
|
+
|
|
76
|
+
const minimalExample = JSON.parse(fs.readFileSync(minimalExamplePath, 'utf8'))
|
|
77
|
+
const readmeBlock = extractMarkedExampleConfig(fs.readFileSync(readmePath, 'utf8'), 'README.md')
|
|
78
|
+
|
|
79
|
+
expect(readmeBlock).toEqual(minimalExample)
|
|
80
|
+
expect(minimalExample.version).toBeTruthy()
|
|
81
|
+
})
|
|
11
82
|
})
|