import { describe, expect, test } from 'vitest'; import webViewBridge from './index.shared.js'; const { appendLaunchTargetToEntryUrl, resolveWebViewUrlFromRuntimeConfig, } = webViewBridge; const runtimeConfig = { sourceQuery: { clientType: 'mini_program', clientRuntime: 'wechat_mini_program', }, webViewEntryUrl: 'https://www.genarrative.world', }; describe('mini program web-view launch target', () => { test('opens the H5 public work detail when launch query carries work params', () => { expect( appendLaunchTargetToEntryUrl('https://www.genarrative.world?foo=bar', { targetPath: '/works/detail', work: 'BB-12345678', }), ).toBe( 'https://www.genarrative.world/works/detail?foo=bar&work=BB-12345678', ); const webViewUrl = resolveWebViewUrlFromRuntimeConfig( null, { targetPath: '/works/detail', work: 'BB-12345678', }, runtimeConfig, ); const url = new URL(webViewUrl); expect(url.pathname).toBe('/works/detail'); expect(url.searchParams.get('work')).toBe('BB-12345678'); expect(url.searchParams.get('clientRuntime')).toBe('wechat_mini_program'); }); test('ignores unsupported launch target paths', () => { const webViewUrl = resolveWebViewUrlFromRuntimeConfig( null, { targetPath: '/admin', work: 'BB-12345678', }, runtimeConfig, ); const url = new URL(webViewUrl); expect(url.pathname).toBe('/'); expect(url.searchParams.get('work')).toBeNull(); }); });