@teleporthq/teleport-project-generator-next 0.45.11 → 0.45.13
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.
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { GeneratedFolder, ProjectUIDL } from '@teleporthq/teleport-types'
|
|
2
|
+
import uidlSample from '../../../examples/test-samples/project-sample.json'
|
|
3
|
+
import { createNextProjectGenerator } from '../src'
|
|
4
|
+
import NextTemplate from '../src/project-template'
|
|
5
|
+
|
|
6
|
+
const template = JSON.parse(JSON.stringify(NextTemplate)) as GeneratedFolder
|
|
7
|
+
|
|
8
|
+
const allFiles = (folder: GeneratedFolder): Array<{ path: string; content: string }> => [
|
|
9
|
+
...folder.files.map((file) => ({ path: `${file.name}.${file.fileType}`, content: file.content })),
|
|
10
|
+
...folder.subFolders.flatMap((sub) =>
|
|
11
|
+
allFiles(sub).map((file) => ({ ...file, path: `${sub.name}/${file.path}` }))
|
|
12
|
+
),
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const sampleWithHeadingClass = (): ProjectUIDL => {
|
|
16
|
+
const uidl = JSON.parse(JSON.stringify(uidlSample)) as ProjectUIDL
|
|
17
|
+
uidl.root.styleSetDefinitions = {
|
|
18
|
+
...(uidl.root.styleSetDefinitions || {}),
|
|
19
|
+
'brand-heading': {
|
|
20
|
+
type: 'reusable-project-style-map',
|
|
21
|
+
content: { fontFamily: 'Roboto' },
|
|
22
|
+
} as never,
|
|
23
|
+
}
|
|
24
|
+
return uidl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('Google fonts get a size-matched stand-in in the generated Next project', () => {
|
|
28
|
+
it('declares the stand-in once in the head and names it after the font everywhere', async () => {
|
|
29
|
+
const output = await createNextProjectGenerator().generateProject(
|
|
30
|
+
sampleWithHeadingClass(),
|
|
31
|
+
template
|
|
32
|
+
)
|
|
33
|
+
const files = allFiles(output)
|
|
34
|
+
const document = files.find((file) => file.path === 'pages/_document.js')
|
|
35
|
+
|
|
36
|
+
expect(document?.content).toContain('font-family: Roboto Fallback;')
|
|
37
|
+
expect(document?.content).toContain('size-adjust:')
|
|
38
|
+
expect(document?.content).toContain("font-family: 'Roboto', Roboto Fallback, sans-serif;")
|
|
39
|
+
expect(document?.content.match(/font-family: Roboto Fallback;/g)).toHaveLength(1)
|
|
40
|
+
|
|
41
|
+
const brandHeading = files.find((file) =>
|
|
42
|
+
/brand-heading\s*\{[^}]*font-family/.test(file.content)
|
|
43
|
+
)
|
|
44
|
+
expect(brandHeading?.content).toMatch(
|
|
45
|
+
/brand-heading\s*\{[^}]*font-family: Roboto, Roboto Fallback;/
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
})
|