1import { Asset } from 'expo-asset';
2
3import * as Font from '../Font';
4import * as FontLoader from '../FontLoader';
5
6describe('loadSingleFontAsync', () => {
7  it(`only excepts FontResource`, async () => {
8    expect(() => FontLoader.loadSingleFontAsync('foo', 10 as any)).toThrow(
9      'Expected font asset of type'
10    );
11    expect(() => FontLoader.loadSingleFontAsync('foo', { uri: 10 as any })).toThrow(
12      'Expected font asset of type'
13    );
14    expect(() => FontLoader.loadSingleFontAsync('foo', Asset.fromURI('foo'))).toThrow(
15      'Expected font asset of type'
16    );
17  });
18  it(`rejects expo-asset`, async () => {
19    expect(() => FontLoader.loadSingleFontAsync('foo', Asset.fromURI('foo'))).toThrow(
20      'Expected font asset of type'
21    );
22    expect(() =>
23      FontLoader.loadSingleFontAsync('foo', { uri: Asset.fromURI('foo') } as any)
24    ).toThrow('Expected font asset of type');
25  });
26});
27
28describe('getNativeFontName', () => {
29  // Sanity test platform resolution
30  it(`never changes`, () => {
31    for (const value of ['foo', false, null, undefined, true, {}, 'System']) {
32      expect(FontLoader.getNativeFontName(value as any)).toBe(value);
33    }
34  });
35});
36
37describe('fontFamilyNeedsScoping', () => {
38  // Sanity test platform resolution
39  it(`never needs scoping in the browser`, () => {
40    for (const value of ['foo', false, null, undefined, true, {}, 'System']) {
41      expect(FontLoader.fontFamilyNeedsScoping(value as any)).toBe(false);
42    }
43  });
44});
45
46describe('getAssetForSource', () => {
47  it(`parses font display`, () => {
48    expect((FontLoader.getAssetForSource('foo') as any).display).toBe(Font.FontDisplay.AUTO);
49    expect((FontLoader.getAssetForSource({ uri: 'foo' }) as any).display).toBe(
50      Font.FontDisplay.AUTO
51    );
52    expect(
53      (FontLoader.getAssetForSource({ uri: 'foo', display: Font.FontDisplay.SWAP }) as any).display
54    ).toBe(Font.FontDisplay.SWAP);
55    expect(
56      (FontLoader.getAssetForSource({ default: 'foo', display: Font.FontDisplay.SWAP }) as any)
57        .display
58    ).toBe(Font.FontDisplay.SWAP);
59  });
60});
61