Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions example/__tests__/asset-loading.harness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, it, expect } from 'react-native-harness';
import { RiveFileFactory } from '@rive-app/react-native';

const OUT_OF_BAND = require('../assets/rive/out_of_band.riv');

function isExperimental() {
return RiveFileFactory.getBackend() === 'experimental';
}

describe('Asset loading with referencedAssets', () => {
// referencedAssets with raw ResolvedReferencedAsset objects only works
// on the experimental backend; legacy uses a different resolution path.
it('loads file with font asset (type: font)', async () => {
if (!isExperimental()) return;
const file = await RiveFileFactory.fromSource(OUT_OF_BAND, {
'Inter-594377': {
sourceAssetId: 'Inter-594377.ttf',
type: 'font',
},
});
expect(file).toBeDefined();
expect(file.artboardNames.length).toBeGreaterThan(0);
});

it('loads file with image asset via URL (type: image)', async () => {
if (!isExperimental()) return;
const file = await RiveFileFactory.fromSource(OUT_OF_BAND, {
'referenced-image-2929282': {
sourceUrl: 'https://picsum.photos/id/237/200/200',
type: 'image',
},
});
expect(file).toBeDefined();
expect(file.artboardNames.length).toBeGreaterThan(0);
});

it('loads file with multiple asset types', async () => {
if (!isExperimental()) return;
const file = await RiveFileFactory.fromSource(OUT_OF_BAND, {
'Inter-594377': {
sourceAssetId: 'Inter-594377.ttf',
type: 'font',
},
'referenced-image-2929282': {
sourceUrl: 'https://picsum.photos/id/237/200/200',
type: 'image',
},
});
expect(file).toBeDefined();
});

it('loads file without referencedAssets (undefined)', async () => {
const file = await RiveFileFactory.fromSource(OUT_OF_BAND, undefined);
expect(file).toBeDefined();
expect(file.artboardNames.length).toBeGreaterThan(0);
});
});
60 changes: 60 additions & 0 deletions example/__tests__/font-config.harness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, it, expect } from 'react-native-harness';
import { Platform } from 'react-native';
import { RiveFonts } from '@rive-app/react-native';

const SYSTEM_FONT = Platform.OS === 'ios' ? 'Helvetica' : 'sans-serif';

describe('RiveFonts', () => {
it('systemFallback() returns a font object', () => {
const font = RiveFonts.systemFallback();
expect(font).toBeDefined();
});

it('loadFont with system font name', async () => {
const font = await RiveFonts.loadFont({ name: SYSTEM_FONT });
expect(font).toBeDefined();
});

it('loadFont with URL', async () => {
const font = await RiveFonts.loadFont({
uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Regular.ttf',
});
expect(font).toBeDefined();
});

it('setFallbackFonts + clearFallbackFonts round-trip', async () => {
const systemFont = RiveFonts.systemFallback();
const urlFont = await RiveFonts.loadFont({
uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Regular.ttf',
});

await RiveFonts.setFallbackFonts({
default: [urlFont, systemFont],
});

await RiveFonts.clearFallbackFonts();
});

it('setFallbackFonts with weight-specific fonts', async () => {
const regular = await RiveFonts.loadFont({
uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Regular.ttf',
});
const bold = await RiveFonts.loadFont({
uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Bold.ttf',
});
const systemFont = RiveFonts.systemFallback();

await RiveFonts.setFallbackFonts({
default: [regular, systemFont],
700: [bold, systemFont],
});

await RiveFonts.clearFallbackFonts();
});

it('loadFont with invalid name throws', async () => {
await expect(
RiveFonts.loadFont({ name: 'NonExistentFont_XYZ_12345' })
).rejects.toBeDefined();
});
});
Loading