Files
Genarrative/apps/mobile-shell/src/host-bridge/runtime.test.ts
T
kdletters 071faa482c 统一 Rust 与 TypeScript 格式化门禁
纳入 AGC Cargo workspace 的统一 rustfmt 检查与格式化入口

完成项目 TypeScript/Prettier 与 Rust 全量格式化

修复 Pingora expected executable 门禁的空白敏感误报

同步开发运维文档与 AGC skill pack 格式化忽略规则
2026-09-01 16:28:34 +08:00

90 lines
2.4 KiB
TypeScript

import { Platform } from 'react-native';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import {
HOST_BRIDGE_EXPO_MOBILE_BASE_CAPABILITIES,
HOST_BRIDGE_EXPO_MOBILE_IOS_CAPABILITIES,
HOST_BRIDGE_PROTOCOL,
HOST_BRIDGE_VERSION,
type HostBridgeRequest,
} from '../../../../packages/shared/src/contracts/hostBridge';
import { MOBILE_SHELL_HOST_VERSION } from '../shell/runtime';
import {
getMobileHostBridgeRuntime,
getMobileHostBridgeRuntimeResponse,
getMobileRuntimePlatform,
} from './runtime';
vi.mock('react-native', () => ({
Platform: {
OS: 'ios',
},
}));
function request(): HostBridgeRequest {
return {
bridge: HOST_BRIDGE_PROTOCOL,
version: HOST_BRIDGE_VERSION,
id: 'runtime-request',
method: 'host.getRuntime',
};
}
function setPlatformOS(os: 'ios' | 'android') {
(Platform as { OS: 'ios' | 'android' }).OS = os;
}
beforeEach(() => {
setPlatformOS('ios');
});
describe('mobile HostBridge runtime helper', () => {
test('reports iOS runtime with host version, bridge version and iOS capabilities', () => {
expect(getMobileRuntimePlatform()).toBe('ios');
const runtime = getMobileHostBridgeRuntime();
expect(runtime).toEqual(
expect.objectContaining({
shell: 'expo_mobile',
platform: 'ios',
hostVersion: MOBILE_SHELL_HOST_VERSION,
bridgeVersion: HOST_BRIDGE_VERSION,
}),
);
expect(runtime.capabilities).toBe(HOST_BRIDGE_EXPO_MOBILE_IOS_CAPABILITIES);
});
test('reports Android runtime without iOS-only app badge capability', () => {
setPlatformOS('android');
const runtime = getMobileHostBridgeRuntime();
expect(getMobileRuntimePlatform()).toBe('android');
expect(runtime).toEqual(
expect.objectContaining({
shell: 'expo_mobile',
platform: 'android',
hostVersion: MOBILE_SHELL_HOST_VERSION,
bridgeVersion: HOST_BRIDGE_VERSION,
}),
);
expect(runtime.capabilities).toBe(
HOST_BRIDGE_EXPO_MOBILE_BASE_CAPABILITIES,
);
expect(runtime.capabilities).not.toContain('app.setBadgeCount');
});
test('wraps runtime metadata in the HostBridge response shape', () => {
const response = getMobileHostBridgeRuntimeResponse(request());
expect(response).toEqual({
bridge: HOST_BRIDGE_PROTOCOL,
version: HOST_BRIDGE_VERSION,
id: 'runtime-request',
ok: true,
result: getMobileHostBridgeRuntime(),
});
});
});