import assert from 'node:assert/strict' import test from 'node:test' import { getXWebViewSnapshot, mountXWebViewHost, openWebView, resetXWebViewRuntimeForTests, updatePageNavigation, } from '../src/runtime' test('openWebView owns an independent page stack and restores the lower page', async () => { resetXWebViewRuntimeForTests() const unmount = mountXWebViewHost() const first = openWebView({ source: { uri: 'https://first.test' }, }) const second = openWebView({ source: { uri: 'https://second.test' }, }) assert.deepEqual( getXWebViewSnapshot().pages.map(page => page.id), [first.id, second.id], ) second.close() assert.deepEqual( getXWebViewSnapshot().pages.map(page => page.id), [first.id], ) assert.equal((await second.closed).reason, 'api') unmount() }) test('dynamic navigation state belongs only to its page', () => { resetXWebViewRuntimeForTests() const unmount = mountXWebViewHost() const first = openWebView({ navigationBar: { title: { text: 'first' } }, source: { uri: 'https://first.test' }, }) const second = openWebView({ navigationBar: { title: { text: 'second' } }, source: { uri: 'https://second.test' }, }) updatePageNavigation(second.id, { title: { color: '#ffffff', text: 'changed' }, }) const pages = getXWebViewSnapshot().pages assert.equal(pages[0].presentation.titleText, 'first') assert.equal(pages[1].presentation.titleText, 'changed') first.close() second.close() unmount() })