PluginProbe
Extendify / 3.1.1
Extendify v3.1.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / unit / Launch / lib / preview-helpers.test.js

preview-helpers.test.js in Extendify 3.1.1, at tests/unit/Launch/lib/preview-helpers.test.js

104 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getFontOverrides } from '@launch/lib/preview-helpers';
2
3 describe('getFontOverrides', () => {
4 it('returns empty strings if no title is provided', () => {
5 const result = getFontOverrides({});
6 expect(result).toEqual({ customFontLinks: '', fontOverrides: '' });
7 });
8
9 it('returns fontOverrides for heading and body font variables', () => {
10 const variation = {
11 title: 'My Variation',
12 styles: {
13 elements: {
14 heading: {
15 typography: {
16 fontFamily: 'var(--wp--preset--font-family--custom-heading)',
17 },
18 },
19 },
20 typography: {
21 fontFamily: 'var(--wp--preset--font-family--custom-body)',
22 },
23 },
24 };
25
26 const { fontOverrides } = getFontOverrides(variation);
27
28 expect(fontOverrides).toContain('--wp--preset--font-family--heading');
29 expect(fontOverrides).toContain('--wp--preset--font-family--body');
30 expect(fontOverrides).toContain(
31 'font-family: var(--wp--preset--font-family--custom-heading)',
32 );
33 expect(fontOverrides).toContain(
34 'font-family: var(--wp--preset--font-family--custom-body)',
35 );
36 });
37
38 it('generates link tags and root variables for custom fonts', () => {
39 const variation = {
40 title: 'My Variation',
41 settings: {
42 typography: {
43 fontFamilies: {
44 custom: [
45 {
46 slug: 'myfont',
47 css: 'https://fonts.com/myfont.css',
48 fontFamily: 'MyFont',
49 },
50 {
51 slug: 'myfont-bold',
52 css: 'https://fonts.com/myfont-bold.css',
53 fontFamily: 'MyFont Bold',
54 },
55 ],
56 },
57 },
58 },
59 };
60
61 const { customFontLinks, fontOverrides } = getFontOverrides(variation);
62
63 expect(customFontLinks).toContain('<link id="ext-custom-font-myfont"');
64 expect(customFontLinks).toContain('href="https://fonts.com/myfont.css"');
65 expect(customFontLinks).toContain('<link id="ext-custom-font-myfont-bold"');
66
67 expect(fontOverrides).toContain('--wp--preset--font-family--myfont');
68 expect(fontOverrides).toContain('--wp--preset--font-family--myfont-bold');
69 expect(fontOverrides).toContain(':root');
70 expect(fontOverrides).toContain('"MyFont Bold"');
71 });
72
73 it('avoids duplicate font links and overrides', () => {
74 const variation = {
75 title: 'My Variation',
76 settings: {
77 typography: {
78 fontFamilies: {
79 custom: [
80 {
81 slug: 'myfont',
82 css: 'https://fonts.com/myfont.css',
83 fontFamily: 'MyFont',
84 },
85 {
86 slug: 'myfont',
87 css: 'https://fonts.com/myfont.css',
88 fontFamily: 'MyFont',
89 },
90 ],
91 },
92 },
93 },
94 };
95
96 const { customFontLinks, fontOverrides } = getFontOverrides(variation);
97
98 expect(customFontLinks.match(/myfont\.css/g)).toHaveLength(1);
99 expect(
100 fontOverrides.match(/--wp--preset--font-family--myfont/g),
101 ).toHaveLength(1);
102 });
103 });
104