cc-haha/desktop/src/components/shared/UpdateChecker.test.tsx
程序员阿江(Relakkes) 6d56f3c21d fix: remove legacy message rewind entry
The chat surface now relies on the current-turn changes card for file rollback, so the older per-message hover rewind affordance was removed to avoid two competing rollback models.

Constraint: Current-turn undo still depends on the existing checkpoint rewind API.
Rejected: Keep both rewind entry points | duplicate rollback affordances make the product harder to explain and test.
Confidence: high
Scope-risk: moderate
Directive: Prefer adding rollback behavior through the current-turn change card instead of restoring per-message hover rewind.
Tested: bun test src/server/__tests__/sessions.test.ts
Tested: cd desktop && bun run test
Tested: cd desktop && bun run lint
Tested: cd desktop && bun run build
Not-tested: Browser E2E scripts were updated but not executed in this commit.
2026-04-30 18:28:08 +08:00

68 lines
2.3 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import { UpdateChecker } from './UpdateChecker'
import { useSettingsStore } from '../../stores/settingsStore'
import { useUpdateStore } from '../../stores/updateStore'
describe('UpdateChecker', () => {
beforeEach(() => {
useSettingsStore.setState({ locale: 'en' })
Object.defineProperty(window, '__TAURI__', {
value: {},
configurable: true,
})
useUpdateStore.setState({
status: 'available',
availableVersion: '0.1.5',
releaseNotes: '# Claude Code Haha v0.1.5\n\n[Release notes](https://example.com/releases/v0.1.5)',
progressPercent: 0,
downloadedBytes: 0,
totalBytes: null,
error: null,
checkedAt: null,
shouldPrompt: true,
initialize: vi.fn().mockResolvedValue(undefined),
checkForUpdates: vi.fn().mockResolvedValue(null),
installUpdate: vi.fn().mockResolvedValue(undefined),
dismissPrompt: vi.fn(),
})
})
it('renders markdown release notes in the update prompt', () => {
render(<UpdateChecker />)
expect(screen.getByText('v0.1.5 available')).toBeInTheDocument()
expect(screen.getByRole('heading', { name: 'Claude Code Haha v0.1.5' })).toBeInTheDocument()
const link = screen.getByRole('link', { name: 'Release notes' })
expect(link).toHaveAttribute('href', 'https://example.com/releases/v0.1.5')
expect(link).toHaveAttribute('target', '_blank')
})
it('shows downloaded bytes when the updater does not provide total size', () => {
useUpdateStore.setState({
status: 'downloading',
availableVersion: '0.1.5',
releaseNotes: '# Claude Code Haha v0.1.5',
progressPercent: 0,
downloadedBytes: 1536,
totalBytes: null,
error: null,
checkedAt: null,
shouldPrompt: true,
initialize: vi.fn().mockResolvedValue(undefined),
checkForUpdates: vi.fn().mockResolvedValue(null),
installUpdate: vi.fn().mockResolvedValue(undefined),
dismissPrompt: vi.fn(),
})
render(<UpdateChecker />)
expect(screen.getByText('Downloading update... 1.5 KB downloaded')).toBeInTheDocument()
expect(screen.queryByText(/0%/)).not.toBeInTheDocument()
})
})