|
|
@@ -8,10 +8,11 @@ import { LocaleRuntime } from '@deepseek-ai/dsh-client-locale/client'
|
|
|
import { TestRemote } from '@deepseek-ai/dsh-client-test-runtime'
|
|
|
import { apply as settingsApply, inject as settingsInject } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
|
import { apply, inject, SETTINGS_NS } from '@deepseek-ai/dsh-client-ui-theme/client'
|
|
|
-import type { AppearanceRowInjected, ThemeRuntime } from '@deepseek-ai/dsh-client-ui-theme/client'
|
|
|
+import type { AppearanceRowInjected, FontSizeRowInjected, ThemeRuntime } from '@deepseek-ai/dsh-client-ui-theme/client'
|
|
|
import { THEME_SETTINGS_NAMESPACE, ThemeSettingsSchema } from '../src/theme-settings.ts'
|
|
|
import { AppearanceRow } from '../src/client/AppearanceRow.tsx'
|
|
|
-import type { createAppearanceRowStore } from '../src/client/settings-store.ts'
|
|
|
+import { FontSizeRow } from '../src/client/FontSizeRow.tsx'
|
|
|
+import type { createAppearanceRowStore, createFontSizeRowStore } from '../src/client/settings-store.ts'
|
|
|
|
|
|
// These specs assert the shipped Chinese copy. The lane has no jsdom `window`,
|
|
|
// so browser-language detection never runs and a fresh LocaleRuntime opens on
|
|
|
@@ -31,11 +32,11 @@ async function bench(isLoopback = true) {
|
|
|
const locale = new LocaleRuntime(ctx)
|
|
|
locale.setLocale('zh')
|
|
|
ctx.provide('locale', locale)
|
|
|
- let preference = 'system'
|
|
|
+ const section: Record<string, unknown> = { preference: 'system', fontSize: 14 }
|
|
|
const namespace = () => ({
|
|
|
ns: THEME_SETTINGS_NAMESPACE,
|
|
|
schema: ThemeSettingsSchema.toJSON(),
|
|
|
- value: { preference },
|
|
|
+ value: { ...section },
|
|
|
applies: 'live' as const,
|
|
|
secrets: [],
|
|
|
revision: 0,
|
|
|
@@ -47,8 +48,9 @@ async function bench(isLoopback = true) {
|
|
|
value: { writable: true, hasDocument: true, namespaces: [namespace()] },
|
|
|
},
|
|
|
}))
|
|
|
- const mutate = vi.fn((request: { ops: { value: string }[] }) => {
|
|
|
- preference = request.ops[0]!.value
|
|
|
+ const mutate = vi.fn((request: { ops: { path: string[]; value: unknown }[] }) => {
|
|
|
+ const op = request.ops[0]!
|
|
|
+ section[op.path[0]!] = op.value
|
|
|
return Promise.resolve({
|
|
|
rpcId: 'theme-mutate' as never,
|
|
|
result: { ok: true as const, value: namespace() },
|
|
|
@@ -59,7 +61,7 @@ async function bench(isLoopback = true) {
|
|
|
await ctx.plugin({ inject: [...settingsInject], apply: settingsApply }).await()
|
|
|
return {
|
|
|
ctx, slots: ctx.get('slots') as SlotRegistry, locale, describe, mutate, events,
|
|
|
- setHostPreference: (next: string) => { preference = next },
|
|
|
+ setHostSection: (next: Record<string, unknown>) => { Object.assign(section, next) },
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -81,20 +83,33 @@ function faceOf(slots: SlotRegistry) {
|
|
|
return { entry, instance, face }
|
|
|
}
|
|
|
|
|
|
+/** The same choreography for the font-size row entry. */
|
|
|
+function fontSizeFaceOf(slots: SlotRegistry) {
|
|
|
+ const entry = slots.entries(SLOT).find(e => e.component === FontSizeRow)!
|
|
|
+ const handle = entry.store as ReturnType<typeof createFontSizeRowStore>
|
|
|
+ const instance = handle.create()
|
|
|
+ const face = (entry.inject as unknown as (a: typeof instance.actions) => FontSizeRowInjected)(instance.actions)
|
|
|
+ return { entry, instance, face }
|
|
|
+}
|
|
|
+
|
|
|
describe('ui-theme apply', () => {
|
|
|
it('declares the slot and locale services', () => {
|
|
|
expect(inject).toEqual(['slots', 'locale', 'connection', 'remote', 'settingsScope'])
|
|
|
})
|
|
|
|
|
|
- it('provides the service, registers localized copy, and registers the row (declaration before or after apply)', async () => {
|
|
|
+ it('provides the service, registers localized copy, and registers both rows (declaration before or after apply)', async () => {
|
|
|
const before = await bench()
|
|
|
declareItems(before.slots)
|
|
|
await before.ctx.plugin({ inject: [...inject], apply }).await()
|
|
|
expect(before.locale.bind(SETTINGS_NS)('appearance.title')).toBe('外观')
|
|
|
+ expect(before.locale.bind(SETTINGS_NS)('fontSize.title')).toBe('字号大小')
|
|
|
before.locale.setLocale('en')
|
|
|
expect(before.locale.bind(SETTINGS_NS)('appearance.title')).toBe('Appearance')
|
|
|
const entry = before.slots.entries(SLOT).find(e => e.component === AppearanceRow)!
|
|
|
expect(entry.options).toMatchObject({ id: 'appearance', order: 10 })
|
|
|
+ const fontEntry = before.slots.entries(SLOT).find(e => e.component === FontSizeRow)!
|
|
|
+ expect(fontEntry.options).toMatchObject({ id: 'font-size', order: 11 })
|
|
|
+ expect(fontEntry.locale).toBe(SETTINGS_NS)
|
|
|
|
|
|
const after = await bench()
|
|
|
const fiber = after.ctx.plugin({ inject: [...inject], apply })
|
|
|
@@ -103,6 +118,7 @@ describe('ui-theme apply', () => {
|
|
|
declareItems(after.slots)
|
|
|
await Promise.resolve()
|
|
|
expect(after.slots.entries(SLOT).some(e => e.component === AppearanceRow)).toBe(true)
|
|
|
+ expect(after.slots.entries(SLOT).some(e => e.component === FontSizeRow)).toBe(true)
|
|
|
})
|
|
|
|
|
|
it('projects service snapshots into the row store and routes face writes back', async () => {
|
|
|
@@ -125,25 +141,44 @@ describe('ui-theme apply', () => {
|
|
|
await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(2) })
|
|
|
})
|
|
|
|
|
|
+ it('projects font-size snapshots into its row store and routes face writes back', async () => {
|
|
|
+ const b = await bench()
|
|
|
+ declareItems(b.slots)
|
|
|
+ await b.ctx.plugin({ inject: [...inject], apply }).await()
|
|
|
+ const theme = b.ctx.get('theme') as ThemeRuntime
|
|
|
+ // An event ahead of any inject hits the unbound-actions arm.
|
|
|
+ theme.setFontSize(16)
|
|
|
+
|
|
|
+ const { instance, face } = fontSizeFaceOf(b.slots)
|
|
|
+ // The inject-time re-sync sealed the init window: the mirror is current.
|
|
|
+ expect(instance.getSnapshot().fontSize).toBe(16)
|
|
|
+
|
|
|
+ face.setFontSize(12)
|
|
|
+ expect(theme.getTheme().fontSize).toBe(12)
|
|
|
+ expect(instance.getSnapshot().fontSize).toBe(12)
|
|
|
+ await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(2) })
|
|
|
+ })
|
|
|
+
|
|
|
it('loads Host settings at boot, refreshes its namespace, and keeps remote browsers process-local', async () => {
|
|
|
const b = await bench()
|
|
|
// The shared mirror read once at bench time; a Host-side change reaches it
|
|
|
// through the document invalidation, exactly as production announces one.
|
|
|
- b.setHostPreference('dark')
|
|
|
+ b.setHostSection({ preference: 'dark', fontSize: 17 })
|
|
|
b.events.emit('settings/document-updated', [THEME_SETTINGS_NAMESPACE, 0])
|
|
|
declareItems(b.slots)
|
|
|
await b.ctx.plugin({ inject: [...inject], apply }).await()
|
|
|
const theme = b.ctx.get('theme') as ThemeRuntime
|
|
|
await vi.waitFor(() => { expect(theme.getTheme().preference).toBe('dark') })
|
|
|
+ expect(theme.getTheme().fontSize).toBe(17)
|
|
|
// The mirror refreshes on every document commit (ns-agnostic); the scope's
|
|
|
// derived value only moves when its own namespace changed.
|
|
|
b.events.emit('settings/document-updated', ['unrelated', 0])
|
|
|
await vi.waitFor(() => { expect(b.describe).toHaveBeenCalledTimes(3) })
|
|
|
expect(theme.getTheme().preference).toBe('dark')
|
|
|
- b.setHostPreference('light')
|
|
|
+ b.setHostSection({ preference: 'light' })
|
|
|
b.events.emit('settings/document-updated', [THEME_SETTINGS_NAMESPACE, 0])
|
|
|
await vi.waitFor(() => { expect(theme.getTheme().preference).toBe('light') })
|
|
|
- b.setHostPreference('dark')
|
|
|
+ b.setHostSection({ preference: 'dark' })
|
|
|
b.ctx.emit('connection/reset')
|
|
|
await vi.waitFor(() => { expect(theme.getTheme().preference).toBe('dark') })
|
|
|
|
|
|
@@ -159,7 +194,7 @@ describe('ui-theme apply', () => {
|
|
|
|
|
|
it('activates before a slow settings refresh and converges when it settles', async () => {
|
|
|
const b = await bench()
|
|
|
- b.setHostPreference('dark')
|
|
|
+ b.setHostSection({ preference: 'dark' })
|
|
|
const describe = b.describe.getMockImplementation()!
|
|
|
const pending = deferred<Awaited<ReturnType<typeof describe>>>()
|
|
|
b.describe.mockImplementationOnce(() => pending.promise)
|
|
|
@@ -177,7 +212,7 @@ describe('ui-theme apply', () => {
|
|
|
|
|
|
it('ignores an invalid preference crossing the settings wire', async () => {
|
|
|
const b = await bench()
|
|
|
- b.setHostPreference('sepia')
|
|
|
+ b.setHostSection({ preference: 'sepia' })
|
|
|
b.events.emit('settings/document-updated', [THEME_SETTINGS_NAMESPACE, 0])
|
|
|
await b.ctx.plugin({ inject: [...inject], apply }).await()
|
|
|
const theme = b.ctx.get('theme') as ThemeRuntime
|
|
|
@@ -189,24 +224,25 @@ describe('ui-theme apply', () => {
|
|
|
const b = await bench()
|
|
|
const host = declareItems(b.slots)
|
|
|
await b.ctx.plugin({ inject: [...inject], apply }).await()
|
|
|
- expect(b.slots.entries(SLOT)).toHaveLength(1)
|
|
|
+ expect(b.slots.entries(SLOT)).toHaveLength(2)
|
|
|
|
|
|
- // Collapse: the declarer dies, the cascade removes our entry while the
|
|
|
- // apply closure still holds its (now stale) disposer.
|
|
|
+ // Collapse: the declarer dies, the cascade removes our entries while the
|
|
|
+ // apply closure still holds its (now stale) disposers.
|
|
|
host()
|
|
|
expect(b.slots.entries(SLOT)).toHaveLength(0)
|
|
|
|
|
|
declareItems(b.slots)
|
|
|
await Promise.resolve()
|
|
|
expect(b.slots.entries(SLOT).some(e => e.component === AppearanceRow)).toBe(true)
|
|
|
+ expect(b.slots.entries(SLOT).some(e => e.component === FontSizeRow)).toBe(true)
|
|
|
})
|
|
|
|
|
|
- it('teardown removes the row and the dictionaries; teardown without a declaration is quiet', async () => {
|
|
|
+ it('teardown removes the rows and the dictionaries; teardown without a declaration is quiet', async () => {
|
|
|
const b = await bench()
|
|
|
declareItems(b.slots)
|
|
|
const fiber = b.ctx.plugin({ inject: [...inject], apply })
|
|
|
await fiber.await()
|
|
|
- expect(b.slots.entries(SLOT)).toHaveLength(1)
|
|
|
+ expect(b.slots.entries(SLOT)).toHaveLength(2)
|
|
|
await fiber.dispose()
|
|
|
expect(b.slots.entries(SLOT)).toHaveLength(0)
|
|
|
// Dictionary disposal: translation falls back to the bare key.
|