Files
apes-sidebar/tests/shell-presets.spec.ts
T
Menghuan1918 fa301da29e feat(i18n): localize plugin catalog names and shell preset desc
Catalog entry names (15 tab + 4 viewer) and the dsh-desktop shell preset
desc were raw hardcoded zh strings rendered straight into the add-plugin
modals and the title-bar scheme dropdown. Mirror the existing desc
pattern exactly: PluginEntry.name / ShellPreset.desc widen to the
i18n-friendly string-or-() =>-string union, the catalogs carry lazy
t('pluginXxxName') / t('presetDshDesktopDesc') lookups, and the
add-plugin modal (render, search filter, aria-labels) plus the scheme
SelectMenu resolve them like every other copy. The plain-string arm of
the union stays as the raw-name fallback, and t() itself never yields
empty text (missing keys render the key), so a dict gap can never blank
a name.

20 new dictionary keys added to zh/en (locales.ts), ja (locales-ja.ts),
and all 18 third-language dictionaries — tests/locales.spec.ts enforces
key-set equality against zh for every shipped dict (precedent: 9cc642b),
so the 'leave other locales-* untouched' shortcut would fail the hard
parity gate; real translations are provided instead.

Spec follow-ups (behavior change: names/descs now render through t()):
- plugin-list.spec.ts: name non-empty assertion resolves the union.
- add-plugin-modal.spec.tsx: sentinel/office name assertions resolve
  from the catalog (en locale in tests) instead of pinning zh literals.
- shell-presets.spec.ts: desc non-empty assertion resolves the union.
2026-09-03 19:59:00 +08:00

76 lines
3.5 KiB
TypeScript

/**
* Built-in shell-preset data tests: registry integrity (unique ids, non-empty
* 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,
platform: null,
titlebarInset: 0,
...partial,
})
describe('shell presets', () => {
it('keeps the registry well-formed (unique ids, titles, pure strip functions)', () => {
const presets = getShellPresets()
expect(presets.length).toBeGreaterThan(0)
const ids = new Set<string>()
for (const preset of presets) {
expect(ids.has(preset.id)).toBe(false)
ids.add(preset.id)
expect(preset.title.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()
expect(() => preset.detect?.(env({ desktop: false, mode: null, platform: null }))).not.toThrow()
}
})
it('looks up presets by id; unknown/empty ids resolve to undefined', () => {
expect(getShellPreset('dsh-desktop')).toBeDefined()
expect(getShellPreset('')).toBeUndefined()
expect(getShellPreset('no-such-shell')).toBeUndefined()
})
describe('dsh-desktop (DeepSeek Harness Desktop, anywhere-labs)', () => {
const preset = getShellPreset('dsh-desktop')!
it('reserves 20px on darwin advanced (the caption row above the surfaces)', () => {
expect(presetStripFor(preset, env({ desktop: true, mode: 'advanced', platform: 'darwin' }))).toBe(20)
})
it('reserves 32px on win32 advanced as the no-WCO fallback', () => {
expect(presetStripFor(preset, env({ desktop: true, mode: 'advanced', platform: 'win32' }))).toBe(32)
})
it('reserves nothing in compatibility mode or on unknown platforms', () => {
expect(presetStripFor(preset, env({ desktop: true, mode: 'compatibility', platform: 'win32' }))).toBeUndefined()
expect(presetStripFor(preset, env({ desktop: true, mode: 'advanced', platform: 'linux' }))).toBeUndefined()
expect(presetStripFor(preset, env({ desktop: false, mode: null, platform: null }))).toBeUndefined()
})
it('detects advanced shells only as a SUGGESTION signal (never auto-applies)', () => {
expect(preset.detect?.(env({ desktop: true, mode: 'advanced', platform: 'darwin' }))).toBe(true)
expect(preset.detect?.(env({ desktop: true, mode: 'advanced', platform: 'win32' }))).toBe(true)
expect(preset.detect?.(env({ desktop: true, mode: 'compatibility', platform: 'win32' }))).toBe(false)
expect(preset.detect?.(env({ desktop: false, mode: null, platform: null }))).toBe(false)
})
})
})