60 lines
2.0 KiB
TypeScript
60 lines
2.0 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'
|
|
|
|
describe('AI entry points', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
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('Provider、模型与测试')
|
|
|
|
fireEvent.click(entry)
|
|
expect(screen.getByRole('heading', { name: '大模型' })).toBeVisible()
|
|
expect(screen.getByRole('button', { name: '添加' })).toBeVisible()
|
|
})
|
|
|
|
it('keeps a prominent AI assistant control wired into every terminal workspace', () => {
|
|
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 助手')
|
|
})
|
|
})
|