Browse Source

test(web): cover onboarding branches

creatixchu 1 month ago
parent
commit
0f1c29c751

+ 1 - 1
packages/client/ui-settings-models/src/client/OnboardingModal.tsx

@@ -41,7 +41,7 @@ export function OnboardingModal({
       title={title}
       onClose={ignoreImplicitDismiss}
       headless
-      className={css['dialog'] ?? ''}
+      className={css.dialog as string}
     >
       <div className={css.content}>
         <h2 ref={titleRef} className={css.title} tabIndex={focusTitle ? -1 : undefined}>{title}</h2>

+ 18 - 2
packages/client/ui-settings-models/tests/apply.client.spec.ts

@@ -14,7 +14,7 @@ import { WelcomeNotice } from '../src/client/WelcomeNotice.tsx'
 // the shipped Chinese copy, so they state the browser they assume.
 usePinnedBrowserLanguages('zh-CN')
 
-async function bench() {
+async function bench(isLoopback = true) {
   const ctx = new Context()
   await ctx.plugin(SlotRegistry).await()
   const locale = new LocaleRuntime(ctx)
@@ -24,7 +24,7 @@ async function bench() {
   new TestRemote(ctx)
   // The apply path only captures the wire face; no call leaves this fake
   // until a section actually loads.
-  ctx.provide('connection', { api: {}, isLoopback: true } as never)
+  ctx.provide('connection', { api: {}, isLoopback } as never)
   return { ctx, slots: ctx.get('slots') as SlotRegistry, locale }
 }
 
@@ -142,6 +142,22 @@ describe('ui-settings-models apply', () => {
     expect(() => b.locale.register('settings.models', 'zh', {})).not.toThrow()
     expect(() => b.locale.register('settings.models', 'en', {})).not.toThrow()
   })
+
+  it('keeps remote-browser acknowledgement in process memory', async () => {
+    const b = await bench(false)
+    declare(b.slots)
+    await b.ctx.plugin({ inject: [...inject], apply }).await()
+    const entry = b.slots.entries('settings.onboarding')
+      .find(candidate => candidate.options.id === 'welcome-notice')!
+    const injected = (
+      entry.inject as unknown as () => import('../src/client/WelcomeNotice.tsx').WelcomeNoticeInjected
+    )()
+
+    await injected.controller.load()
+    expect(injected.controller.store.getSnapshot()).toEqual({
+      status: 'ready', acknowledged: false, error: null,
+    })
+  })
 })
 
 describe('pushed invalidations', () => {

+ 7 - 0
packages/client/ui-settings-models/tests/onboarding-dialog.client.spec.tsx

@@ -146,6 +146,13 @@ function harness(options: {
 }
 
 describe('DeepSeekOnboardingDialog', () => {
+  it('renders when the shell root is absent', async () => {
+    const h = harness()
+    document.getElementById('root')!.remove()
+    render(<DeepSeekOnboardingDialog {...h.props} />)
+    expect(await screen.findByRole('dialog', { name: en.onboardingTitle })).toBeTruthy()
+  })
+
   it('loads a credential-only modal, inerts the product, and focuses the key', async () => {
     const h = harness()
     render(<DeepSeekOnboardingDialog {...h.props} />)