wip
fix: docs
This commit is contained in:
@@ -129,3 +129,73 @@ exports[`sidebar shell snapshots > renders the expanded column (wordmark, capsul
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`sidebar shell snapshots > renders the expanded column in the default locale (zh, no setLocale) 1`] = `
|
||||
<div
|
||||
data-slot="sidebar"
|
||||
>
|
||||
<div
|
||||
class="root"
|
||||
style="width: 300px;"
|
||||
>
|
||||
<div
|
||||
class="logoRow"
|
||||
>
|
||||
<button
|
||||
aria-label="新建会话"
|
||||
class="brand wide"
|
||||
type="button"
|
||||
>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
data-content="951274b9"
|
||||
fill="none"
|
||||
height="24"
|
||||
viewBox="0 0 182 24"
|
||||
width="182"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
aria-label="收起侧边栏"
|
||||
class="iconButton toggle"
|
||||
type="button"
|
||||
>
|
||||
<svg
|
||||
class="panelIcon"
|
||||
data-content="35f95b0c"
|
||||
fill="none"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
width="16"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
aria-label="新建会话"
|
||||
class="newSession"
|
||||
type="button"
|
||||
>
|
||||
<svg
|
||||
data-content="c0ce4dcc"
|
||||
fill="none"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
width="14"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
/>
|
||||
<span
|
||||
class="newSessionLabel wide"
|
||||
>
|
||||
新会话
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="regionArea"
|
||||
/>
|
||||
<div
|
||||
class="footArea"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -9,30 +9,43 @@
|
||||
* the snapshots pin the shell chrome itself.
|
||||
*/
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, waitFor } from '@testing-library/react'
|
||||
import { act, cleanup, waitFor } from '@testing-library/react'
|
||||
import { SlotTestRuntime } from '@deepseek-ai/dsh-client-test-runtime'
|
||||
import { LocaleService } from '@deepseek-ai/dsh-client-locale/client'
|
||||
import { apply, inject } from '@deepseek-ai/dsh-client-ui-sidebar/client'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
async function bench() {
|
||||
/**
|
||||
* Boot the package over the slot test runtime. The default bench stays on
|
||||
* the service's default locale (zh — the fallback chain's base), pinning
|
||||
* what an untouched client shows; `locale: 'en'` pins the en copy instead.
|
||||
* The installed face backs the entry's standard `t` seat either way.
|
||||
*/
|
||||
async function bench(options: { locale?: 'en' } = {}) {
|
||||
const runtime = await SlotTestRuntime.create()
|
||||
runtime.provide('layout', { toggleSidebar: vi.fn() })
|
||||
// English locale pins the snapshots to the copy they were recorded with;
|
||||
// the installed face backs the entry's standard `t` seat.
|
||||
const locale = new LocaleService(runtime.ctx)
|
||||
locale.setLocale('en')
|
||||
if (options.locale === 'en') locale.setLocale('en')
|
||||
runtime.provide('locale', locale)
|
||||
runtime.slots.installLocale(locale)
|
||||
await runtime.declare({ 'sidebar': { kind: 'single', scope: 'root' } })
|
||||
await runtime.mount({ inject: [...inject], apply })
|
||||
return runtime
|
||||
return { runtime, locale }
|
||||
}
|
||||
|
||||
describe('sidebar shell snapshots', () => {
|
||||
it('renders the expanded column in the default locale (zh, no setLocale)', async () => {
|
||||
const { runtime } = await bench()
|
||||
const slot = runtime.renderSlot('sidebar', { collapsed: false, width: 300 })
|
||||
// Wordmark + capsule both start a session in the expanded state.
|
||||
expect(slot.view.getAllByRole('button', { name: '新建会话' })).toHaveLength(2)
|
||||
expect(slot.container).toMatchSnapshot()
|
||||
await runtime.dispose()
|
||||
})
|
||||
|
||||
it('renders the expanded column (wordmark, capsule, empty holes)', async () => {
|
||||
const runtime = await bench()
|
||||
const { runtime } = await bench({ locale: 'en' })
|
||||
const slot = runtime.renderSlot('sidebar', { collapsed: false, width: 300 })
|
||||
// Wordmark + capsule both start a session in the expanded state.
|
||||
expect(slot.view.getAllByRole('button', { name: 'New session' })).toHaveLength(2)
|
||||
@@ -41,7 +54,7 @@ describe('sidebar shell snapshots', () => {
|
||||
})
|
||||
|
||||
it('renders the collapsed rail after the crossfade settles, in place', async () => {
|
||||
const runtime = await bench()
|
||||
const { runtime } = await bench({ locale: 'en' })
|
||||
const slot = runtime.renderSlot('sidebar', { collapsed: false, width: 300 })
|
||||
const shell = slot.container.firstElementChild
|
||||
slot.update({ collapsed: true, width: 56 })
|
||||
@@ -55,4 +68,15 @@ describe('sidebar shell snapshots', () => {
|
||||
expect(slot.container.firstElementChild).toBe(shell)
|
||||
await runtime.dispose()
|
||||
})
|
||||
|
||||
it('a locale switch refreshes mounted copy without re-registration', async () => {
|
||||
const { runtime, locale } = await bench()
|
||||
const slot = runtime.renderSlot('sidebar', { collapsed: false, width: 300 })
|
||||
expect(slot.view.getAllByRole('button', { name: '新建会话' })).toHaveLength(2)
|
||||
// Same fiber, same registration: setLocale alone re-renders the outlet.
|
||||
act(() => { locale.setLocale('en') })
|
||||
expect(slot.view.getAllByRole('button', { name: 'New session' })).toHaveLength(2)
|
||||
expect(slot.view.queryByRole('button', { name: '新建会话' })).toBeNull()
|
||||
await runtime.dispose()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user