WorkBuddy review found 38 of 131 spec files failed at collection time (0 tests executed) — the '1015 passed' was a false green because vitest only counts 'Tests failed', not 'Test Files failed'. Root cause: dsh-client-ui-primitives@0.2.0-rc.2 declares dependencies:null but statically imports 23 external root packages. Our project declared only 18. Under pnpm strict layout, the missing 5 (dsh-client-store, dsh-util-code-language, dsh-util-workspace-path, diff, simple-icons) were unresolvable when Vite inlined the primitives package. Fixes: - Add 7 missing devDeps: dsh-client-store@0.2.0-rc.2, dsh-util-code-language@0.2.0-rc.2, dsh-util-workspace-path@0.2.0-rc.2, diff@9.0.0, simple-icons@16.35.0, zustand@5.0.15, immer@11.1.21 - vitest.config.ts: add transform plugin to strip sourceMappingURL comments from dsh-client-ui-primitives (upstream ships lib/index.js with trailing sourceMappingURL but package.json files excludes .map) - 5 spec files: add @vitest-environment jsdom directive (they import dsh-client-ui-primitives which calls window.addEventListener at module load; node environment lacks window) - Remove empty .map file hack from node_modules (ineffective + .gitignore blocks it from version control) Result: Test Files 131 passed (131), Tests 1367 passed | 9 skipped, EXIT=0. Verified: simple-icons 25 named exports all present. Typecheck + build pass.
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
/**
|
|
* Markdown preview copy-label spec: the fence copy buttons ("复制" / "Copy")
|
|
* must follow the DSH locale service through `codeLabels` — the DSH
|
|
* MarkdownText/CodeBlock are cordis-free and fall back to HARDCODED Chinese
|
|
* when the caller omits the labels, so TextEditor must pass its own
|
|
* dictionary copy (`t('copy')` / `t('copied')`), re-evaluated per render.
|
|
* Rendered with renderToString (the initial preview mode never mounts
|
|
* CodeMirror, so no DOM/effects are needed).
|
|
*/
|
|
import { describe, expect, it, afterEach } from 'vitest'
|
|
import { renderToString } from 'react-dom/server'
|
|
import { createElement } from 'react'
|
|
import './browser-globals.ts'
|
|
import { TextEditor } from '../src/client/TextEditor.tsx'
|
|
import { createSidebarStore } from '../src/client/state.ts'
|
|
import { attachLocale } from '../src/client/locales.ts'
|
|
import type { FileViewerProps } from '../src/client/service.ts'
|
|
|
|
/** Minimal structural fake of the DSH LocaleService face the sidebar uses. */
|
|
class FakeLocale {
|
|
active: string = 'zh'
|
|
getSnapshot(): { active: string } {
|
|
return { active: this.active }
|
|
}
|
|
subscribe(_fn: () => void): () => void {
|
|
return () => {}
|
|
}
|
|
register(_ns: string, _locale: string, _dict: Record<string, string>): () => void {
|
|
return () => {}
|
|
}
|
|
}
|
|
|
|
const CTX = {} as Parameters<typeof TextEditor>[0]['ctx']
|
|
|
|
/** A markdown source with one fenced code block (the copy-button surface). */
|
|
const MD_WITH_FENCE = '```ts\nconst a = 1\n```'
|
|
|
|
function viewerProps(overrides: Partial<FileViewerProps> = {}): FileViewerProps {
|
|
return {
|
|
ctx: CTX,
|
|
store: createSidebarStore(),
|
|
scope: { sessionId: 's1', cwd: '/p' },
|
|
path: '/p/a/README.md',
|
|
title: 'README.md',
|
|
viewerId: 'markdown',
|
|
content: MD_WITH_FENCE,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
afterEach(() => {
|
|
attachLocale(undefined)
|
|
})
|
|
|
|
describe('markdown preview code-block copy labels (DSH i18n following)', () => {
|
|
it('renders the fence copy button with the zh dictionary label by default', () => {
|
|
const locale = new FakeLocale()
|
|
locale.active = 'zh'
|
|
attachLocale(locale)
|
|
const html = renderToString(createElement(TextEditor, viewerProps()))
|
|
expect(html).toContain('复制')
|
|
expect(html).not.toContain('Copy')
|
|
})
|
|
|
|
it('follows the attached locale service live: en renders "Copy" instead of the zh label', () => {
|
|
const locale = new FakeLocale()
|
|
locale.active = 'en'
|
|
attachLocale(locale)
|
|
const html = renderToString(createElement(TextEditor, viewerProps()))
|
|
expect(html).toContain('Copy')
|
|
expect(html).not.toContain('复制')
|
|
})
|
|
})
|