ソースを参照

test(desktop): cover update indicator fallback states

winewill 2 週間 前
親
コミット
ddc1e28e17

+ 6 - 0
packages/client/ui-settings-general/tests/components.client.spec.tsx

@@ -57,6 +57,12 @@ describe('Desktop collapsed update badge', () => {
     state = { ...state, failed: true }
     view.rerender(<DesktopUpdateBadge {...props} />)
     expect(screen.getByRole('img', { name: en['desktop.update.retry'] }).getAttribute('data-error')).toBe('true')
+    state = { failed: true, opening: false }
+    view.rerender(<DesktopUpdateBadge {...props} />)
+    expect(screen.getByRole('img', { name: en['desktop.update.retry'] }).getAttribute('data-error')).toBe('true')
+    state = { failed: false, opening: false, presentation: { phase: 'error', failure: 'install' } }
+    view.rerender(<DesktopUpdateBadge {...props} />)
+    expect(screen.getByRole('img', { name: en['desktop.update.retry'] }).getAttribute('data-error')).toBe('true')
     for (const value of ['connecting', 'disconnected'] as const) {
       connection = value
       view.rerender(<DesktopUpdateBadge {...props} />)

+ 16 - 0
packages/client/ui-settings-general/tests/desktop-update.client.spec.tsx

@@ -138,3 +138,19 @@ it('renders the same semantic update in the active Web locale', async () => {
     expect(screen.getByRole('button', { name: 'Update' })).toBeTruthy()
   } finally { f.view.unmount(); f.status.resolve(available) }
 })
+
+it('shows fallback progress and error details when the shell omits optional fields', async () => {
+  const f = fixture()
+  try {
+    await f.emit({ phase: 'downloading' })
+    const progress = screen.getByRole('button', { name: '0%…' })
+    fireEvent.focus(progress)
+    expect((await screen.findByRole('tooltip')).textContent).toBe('0%…')
+    await f.emit({ phase: 'downloading', version: '1.0.1' })
+    fireEvent.focus(screen.getByRole('button', { name: '0%…' }))
+    expect((await screen.findByRole('tooltip')).textContent).toContain('1.0.1')
+    await f.emit({ phase: 'error' })
+    fireEvent.focus(screen.getByRole('button', { name: '重试更新' }))
+    expect((await screen.findByRole('tooltip')).textContent).toBe('安装更新失败,请稍后重试。')
+  } finally { f.view.unmount(); f.status.resolve({ phase: 'idle' }) }
+})

+ 5 - 1
packages/client/ui-settings-general/tests/shell.client.spec.ts

@@ -53,7 +53,8 @@ describe('ui-settings-general shell', () => {
     let publish: ((state: DesktopUpdatePresentation) => void) | undefined
     const off = vi.fn()
     const subscribe = vi.fn((listener: typeof publish) => { publish = listener; return off })
-    vi.stubGlobal('dshDesktop', { protocolVersion: 1, updates: { status: () => initial.promise, subscribe, open: async () => {} } })
+    const open = vi.fn(async () => {})
+    vi.stubGlobal('dshDesktop', { protocolVersion: 1, updates: { status: () => initial.promise, subscribe, open } })
     onTestFinished(() => { vi.unstubAllGlobals(); initial.resolve({ phase: 'idle' }) })
     const c = await start()
     const row = injectedOf(c)
@@ -63,6 +64,9 @@ describe('ui-settings-general shell', () => {
     const status = { phase: 'available' as const, version: '1.0.1' }
     publish!(status)
     expect(row.hooks.desktopUpdate.getSnapshot().presentation).toEqual(status)
+    row.openDesktopUpdate()
+    await c.flush()
+    expect(open).toHaveBeenCalledOnce()
     await c.unload(SELF)
     await c.flush()
     expect(off).toHaveBeenCalledOnce()