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 / fonts-helpers.test.js

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

78 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 fetchFontFaceFile,
3 makeFontFaceFormData,
4 makeFontFamilyFormData,
5 } from '@launch/lib/fonts-helpers';
6
7 jest.mock('@shared/lib/utils', () => ({
8 sleep: jest.fn(() => Promise.resolve()),
9 }));
10
11 global.fetch = jest.fn();
12
13 describe('fetchFontFaceFile', () => {
14 const mockBlob = new Blob(['font-data'], { type: 'font/woff2' });
15
16 beforeEach(() => {
17 jest.clearAllMocks();
18 });
19
20 it('fetches font and returns a File object', async () => {
21 fetch.mockResolvedValueOnce({
22 ok: true,
23 blob: () => mockBlob,
24 });
25
26 const file = await fetchFontFaceFile('https://fonts.com/my-font.woff2');
27 expect(file).toBeInstanceOf(File);
28 expect(file.name).toBe('my-font.woff2');
29 expect(file.type).toBe('font/woff2');
30 });
31 });
32
33 describe('makeFontFamilyFormData', () => {
34 it('creates FormData with font_family_settings', () => {
35 const formData = makeFontFamilyFormData({
36 name: 'Roboto',
37 slug: 'roboto',
38 fontFamily: 'Roboto, sans-serif',
39 });
40
41 const entry = formData.get('font_family_settings');
42 expect(JSON.parse(entry)).toEqual({
43 name: 'Roboto',
44 slug: 'roboto',
45 fontFamily: 'Roboto, sans-serif',
46 });
47 });
48 });
49
50 describe('makeFontFaceFormData', () => {
51 it('creates FormData with correct file and settings', () => {
52 const mockFile = new File(['abc'], 'roboto.woff2', { type: 'font/woff2' });
53
54 const formData = makeFontFaceFormData({
55 fontFamilySlug: 'roboto',
56 fontFamily: 'Roboto',
57 fontStyle: 'normal',
58 fontWeight: '400',
59 fontDisplay: 'swap',
60 file: mockFile,
61 });
62
63 const fontSettings = JSON.parse(formData.get('font_face_settings'));
64
65 expect(fontSettings).toMatchObject({
66 fontFamily: 'Roboto',
67 fontStyle: 'normal',
68 fontWeight: '400',
69 fontDisplay: 'swap',
70 src: ['roboto-400-normal'],
71 });
72
73 const fileData = formData.get('roboto-400-normal');
74 expect(fileData).toBeInstanceOf(File);
75 expect(fileData.name).toBe('roboto.woff2');
76 });
77 });
78