Files
opsxshell/test/components/AiEntryPoints.test.tsx
T
Logan.Li b0d0e3a5f3 feat(i18n): add multi-language support (ja/ko/vi/ru/zh-TW) with system auto-detection
- Extend AppLanguage to 7 locales: zh-CN, zh-TW, en, ja, ko, vi, ru
- Auto-detect system language via navigator.languages; fallback to English
- Add BCP47 locale mapping for date formatting and sorting
- Create 50 translation JSON files (5 languages × 10 namespaces, 1137 keys each)
- Update language selector with native language names
- Extend locale key parity test to cover all 7 languages (70 assertions)
- Add VNC/RDP desktop, serial terminal, AI agent, port forwarding, and SFTP features
- Add credential encryption, host metrics, session backup crypto, and zmodem bridge
- Update Rust backend: desktop services, host metrics, SSH/SFTP enhancements
2026-08-12 00:07:48 +08:00

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('Provider')
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()
})
})