84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import SettingsView from '../../src/components/settings/SettingsView'
|
|
import TerminalWorkspace from '../../src/components/terminal/TerminalWorkspace'
|
|
import { useAiProviderStore } from '../../src/stores/aiProviderStore'
|
|
import { useSettingsStore } from '../../src/stores/settingsStore'
|
|
import { useTabStore } from '../../src/stores/tabStore'
|
|
import { unlockProForTests } from '../helpers/entitlement'
|
|
|
|
describe('AI entry points', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
unlockProForTests()
|
|
useSettingsStore.setState({ isLoaded: true })
|
|
useAiProviderStore.setState({
|
|
providers: [],
|
|
activeProviderId: '',
|
|
isLoaded: true,
|
|
catalogProviders: [],
|
|
catalogUpdatedAt: null,
|
|
})
|
|
})
|
|
|
|
it('keeps the model configuration visible in settings navigation', () => {
|
|
render(<SettingsView />)
|
|
|
|
const entry = screen.getByTestId('settings-tab-ai')
|
|
expect(entry).toBeVisible()
|
|
expect(entry).toHaveTextContent('大模型')
|
|
expect(entry).toHaveTextContent('供应商')
|
|
expect(entry).not.toHaveTextContent('模型与测试')
|
|
|
|
fireEvent.click(entry)
|
|
expect(screen.getByRole('heading', { name: '大模型' })).toBeVisible()
|
|
expect(screen.getByRole('button', { name: '添加' })).toBeVisible()
|
|
})
|
|
|
|
it('keeps a prominent AI assistant control on SSH terminal workspaces', () => {
|
|
useTabStore.setState({
|
|
tabs: [
|
|
{
|
|
id: 'terminal-ai-test',
|
|
title: 'root@example.com',
|
|
type: 'terminal',
|
|
isActive: false,
|
|
sessionId: 'session-ai-test',
|
|
},
|
|
],
|
|
activeTabId: null,
|
|
})
|
|
|
|
render(<TerminalWorkspace tabId="terminal-ai-test" isActive={false} />)
|
|
|
|
const entry = screen.getByTestId('terminal-ai-button')
|
|
expect(entry).toBeVisible()
|
|
expect(entry).toHaveTextContent('AI 助手')
|
|
expect(entry).toHaveAttribute('aria-label', '打开终端 AI 助手')
|
|
|
|
fireEvent.click(entry)
|
|
expect(entry).toHaveAttribute('aria-label', '关闭终端 AI 助手')
|
|
})
|
|
|
|
it('hides the AI assistant control on local shell workspaces', () => {
|
|
useTabStore.setState({
|
|
tabs: [
|
|
{
|
|
id: 'local-ai-test',
|
|
title: 'Local',
|
|
type: 'terminal',
|
|
isActive: false,
|
|
isLocal: true,
|
|
localShellKind: 'zsh',
|
|
localShellPath: '/bin/zsh',
|
|
},
|
|
],
|
|
activeTabId: null,
|
|
})
|
|
|
|
render(<TerminalWorkspace tabId="local-ai-test" isActive={false} />)
|
|
|
|
expect(screen.queryByTestId('terminal-ai-button')).toBeNull()
|
|
})
|
|
})
|