import { describe, expect, test } from 'vitest'; import { HOST_BRIDGE_PROTOCOL, HOST_BRIDGE_VERSION, } from '../../../../packages/shared/src/contracts/hostBridge'; import { parseMobileWebViewHistoryStateMessage } from './webViewHistory'; describe('parseMobileWebViewHistoryStateMessage', () => { test('解析移动 WebView H5 路由栈状态消息', () => { expect( parseMobileWebViewHistoryStateMessage( JSON.stringify({ type: 'genarrative.mobile.historyState', canGoBack: true, }), ), ).toEqual({ canGoBack: true, }); expect( parseMobileWebViewHistoryStateMessage( JSON.stringify({ type: 'genarrative.mobile.historyState', canGoBack: false, }), ), ).toEqual({ canGoBack: false, }); }); test('忽略非移动路由状态消息', () => { expect(parseMobileWebViewHistoryStateMessage('not-json')).toBeNull(); expect( parseMobileWebViewHistoryStateMessage( JSON.stringify({ bridge: HOST_BRIDGE_PROTOCOL, version: HOST_BRIDGE_VERSION, method: 'host.getRuntime', }), ), ).toBeNull(); expect( parseMobileWebViewHistoryStateMessage( JSON.stringify({ type: 'genarrative.mobile.historyState', canGoBack: 'true', }), ), ).toBeNull(); }); });