Merge pull request #535 from omdsh-dev/feat/i18n-catalog-names
feat(i18n): 目录项与 shell 预设文案词典化,兜底错误条改皮肤令牌链
This commit is contained in:
30 files changed
+520
-60
No files matched your search
@@ -30,6 +30,14 @@ import { setupReactAct } from './test-utils.ts'
|
||||
setupReactAct()
|
||||
|
||||
const officeEntry = builtinViewerPlugins[0] as PluginEntry
|
||||
const sentinelEntry = builtinTabPlugins.find(entry => entry.id === '@dsh-external/dsh-sentinel') as PluginEntry
|
||||
|
||||
/** Resolve an i18n-friendly string-or-function value (mirror of textOf).
|
||||
* Catalog names went through the same union as descriptions, so they
|
||||
* render through t() in the active (test: en) locale. */
|
||||
function textOf(value: string | (() => string)): string {
|
||||
return typeof value === 'function' ? value() : value
|
||||
}
|
||||
|
||||
describe('PluginListBody (render)', () => {
|
||||
it('viewer kind renders the topic button and the office catalog entry', () => {
|
||||
@@ -43,7 +51,7 @@ describe('PluginListBody (render)', () => {
|
||||
expect(html).not.toContain('href=')
|
||||
// The seeded catalog entry: name, description, install script,
|
||||
// a jump button (opens the repo in a NEW browser tab) and a copy button.
|
||||
expect(html).toContain(officeEntry.name)
|
||||
expect(html).toContain(textOf(officeEntry.name))
|
||||
expect(html).toContain(officeEntry.install.replaceAll('&', '&'))
|
||||
expect(html).toContain('Open')
|
||||
expect(html).toContain('Copy')
|
||||
@@ -53,9 +61,9 @@ describe('PluginListBody (render)', () => {
|
||||
const store = createSidebarStore()
|
||||
const service = createBetterSidebarService(store)
|
||||
const html = renderToString(createElement(PluginListBody, { service, kind: 'tab' }))
|
||||
expect(html).toContain('dsh-sentinel 唤醒系统')
|
||||
expect(html).toContain(textOf(sentinelEntry.name))
|
||||
expect(html).toContain('github:fuhefei/dsh-sentinel')
|
||||
expect(html).not.toContain(officeEntry.name)
|
||||
expect(html).not.toContain(textOf(officeEntry.name))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -75,9 +83,9 @@ describe('AddPluginModal wiring', () => {
|
||||
})
|
||||
const html = document.body.innerHTML
|
||||
if (kind === 'viewer') {
|
||||
expect(html).toContain(officeEntry.name)
|
||||
expect(html).toContain(textOf(officeEntry.name))
|
||||
} else {
|
||||
expect(html).toContain('dsh-sentinel 唤醒系统')
|
||||
expect(html).toContain(textOf(sentinelEntry.name))
|
||||
}
|
||||
act(() => { root.unmount() })
|
||||
container.remove()
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
* Built-in plugin catalog data-integrity tests (both files: the TAB
|
||||
* catalog in plugins-tabs.ts and the FILE-PREVIEWER catalog in
|
||||
* plugins-viewers.ts). Every entry must be installable as data — a unique
|
||||
* id (npm package name), a GitHub URL, a non-empty localized description
|
||||
* (string or () => string), and an install script that mentions the dsh
|
||||
* plugin CLI. The catalogs are the discovery surface of the two "add
|
||||
* plugin" modals; a malformed entry would break the install flow, so the
|
||||
* shape is pinned here.
|
||||
* id (npm package name), a GitHub URL, a non-empty localized name and
|
||||
* description (string or () => string), and an install script that mentions
|
||||
* the dsh plugin CLI. The catalogs are the discovery surface of the two
|
||||
* "add plugin" modals; a malformed entry would break the install flow, so
|
||||
* the shape is pinned here.
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { builtinTabPlugins } from '../src/client/plugins-tabs.ts'
|
||||
@@ -42,9 +42,11 @@ describe('builtin plugin catalogs', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('every entry has a name, a GitHub URL, and an install script', () => {
|
||||
it('every entry has a localized name, a GitHub URL, and an install script', () => {
|
||||
for (const entry of list) {
|
||||
expect(entry.name.length).toBeGreaterThan(0)
|
||||
// Names went through the same i18n-friendly union as descriptions
|
||||
// (string or () => string), so resolve before asserting.
|
||||
expect(textOf(entry.name).length).toBeGreaterThan(0)
|
||||
expect(entry.url.startsWith('https://github.com/')).toBe(true)
|
||||
expect(entry.install.length).toBeGreaterThan(0)
|
||||
expect(entry.install).toContain('dsh plugin')
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
/**
|
||||
* Built-in shell-preset data tests: registry integrity (unique ids, non-empty
|
||||
* titles, pure strip/detect functions) and the anywhere-labs DSH Desktop
|
||||
* entry's strip values (darwin advanced 20px, win32 advanced 32px as the
|
||||
* no-WCO fallback, compatibility/plain browser nothing).
|
||||
* titles, non-empty localized descs, pure strip/detect functions) and the
|
||||
* anywhere-labs DSH Desktop entry's strip values (darwin advanced 20px,
|
||||
* win32 advanced 32px as the no-WCO fallback, compatibility/plain browser
|
||||
* nothing).
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { getShellPreset, getShellPresets, presetStripFor } from '../src/client/shell-presets.ts'
|
||||
import type { DesktopEnv } from '../src/client/desktop-env.ts'
|
||||
|
||||
/** Resolve an i18n-friendly string-or-function value (mirror of textOf).
|
||||
* Preset descs went through the same union as the plugin catalog's texts,
|
||||
* so they resolve through t() in the active (test: en) locale. */
|
||||
function textOf(value: string | (() => string)): string {
|
||||
return typeof value === 'function' ? value() : value
|
||||
}
|
||||
|
||||
const env = (partial: Partial<DesktopEnv>): DesktopEnv => ({
|
||||
desktop: false,
|
||||
mode: null,
|
||||
@@ -25,7 +33,8 @@ describe('shell presets', () => {
|
||||
expect(ids.has(preset.id)).toBe(false)
|
||||
ids.add(preset.id)
|
||||
expect(preset.title.length).toBeGreaterThan(0)
|
||||
expect(preset.desc.length).toBeGreaterThan(0)
|
||||
// Descs are i18n-friendly now (string or () => string) — resolve first.
|
||||
expect(textOf(preset.desc).length).toBeGreaterThan(0)
|
||||
// The strip function must be total — an unknown environment yields
|
||||
// undefined, never a throw.
|
||||
expect(() => presetStripFor(preset, env({ desktop: false, mode: null, platform: null }))).not.toThrow()
|
||||
|
||||
Reference in new issue
Block a user