Files
BoosAPI/desktop/libs/markstream-vue/test/react-inline-image-links.test.tsx
boos e0a5f57793 feat(desktop): embed BoosAPI Desktop client as a subproject
Vendor the rebranded BoosAPI Desktop client (Tauri + Vue) into metapi as
a monorepo subdirectory under desktop/. Source only — node_modules,
dist, Cargo target and the upstream .git history are excluded.

desktop/ keeps its own independent Cargo workspace (desktop/src-tauri
with crates/*); it is not part of the backend boosapi crate, so a
`cargo check` at the metapi root still compiles only the backend. Build
the desktop app from desktop/src-tauri per desktop/README.md.

Note: app icons are still placeholder assets pending the final BoosAPI
logo. The updater signing keys live outside the repo and are not
included.
2026-06-22 11:32:57 +08:00

81 lines
2.8 KiB
TypeScript

/**
* @vitest-environment jsdom
*/
import { afterEach, describe, expect, it } from 'vitest'
/* eslint-disable antfu/no-import-node-modules-by-path */
import React, { act, StrictMode } from '../packages/markstream-react/node_modules/react'
import { createRoot } from '../packages/markstream-react/node_modules/react-dom/client'
import { renderToStaticMarkup } from '../packages/markstream-react/node_modules/react-dom/server'
import { NodeRenderer } from '../packages/markstream-react/src/components/NodeRenderer'
import { NodeRenderer as ServerNodeRenderer } from '../packages/markstream-react/src/server'
const markdown = `[![NPM version](https://img.shields.io/npm/v/markstream-vue?color=a1b858&label=)](https://www.npmjs.com/package/markstream-vue)
[![中文版](https://img.shields.io/badge/docs-中文文档-blue)](README.zh-CN.md)`
async function flushReact() {
await act(async () => {
await Promise.resolve()
await Promise.resolve()
})
}
afterEach(() => {
document.body.innerHTML = ''
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = false
})
describe('markstream-react paragraph media-only links', () => {
it('keeps image links inline without inserting text spans between them on the client', async () => {
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
const host = document.createElement('div')
document.body.appendChild(host)
const root = createRoot(host)
await act(async () => {
root.render(
React.createElement(StrictMode, null, React.createElement(NodeRenderer as any, {
content: markdown,
typewriter: false,
batchRendering: false,
viewportPriority: false,
deferNodesUntilVisible: false,
})),
)
})
await flushReact()
const paragraph = host.querySelector('p.paragraph-node') as HTMLParagraphElement | null
expect(paragraph).not.toBeNull()
expect(Array.from(paragraph!.children).map(child => child.tagName)).toEqual(['A', 'A'])
expect(paragraph!.querySelectorAll('.text-node')).toHaveLength(0)
const links = paragraph!.querySelectorAll('a.link-node')
expect(links).toHaveLength(2)
expect(links[0]?.querySelector('img')).not.toBeNull()
expect(links[1]?.querySelector('img')).not.toBeNull()
expect(links[1]?.getAttribute('href')).toBe('README.zh-CN.md')
await act(async () => {
root.unmount()
})
})
it('keeps image links inline without inserting text spans during SSR', () => {
const html = renderToStaticMarkup(
React.createElement(ServerNodeRenderer as any, {
content: markdown,
typewriter: false,
}),
)
expect(html).toContain('<p')
expect(html).toContain('href="README.zh-CN.md"')
expect(html).toContain('<a')
expect(html).toContain('<img')
expect(html).not.toContain('class="text-node')
expect(html).toContain('</a> <a')
})
})