Files
opsxshell/test/components/BatchSessionOperations.test.tsx
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

81 lines
2.8 KiB
TypeScript

import { fireEvent, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import Sidebar from '../../src/components/layout/Sidebar'
import { useSessionStore, type Session } from '../../src/stores/sessionStore'
import { useTabStore } from '../../src/stores/tabStore'
import { unlockProForTests } from '../helpers/entitlement'
import { mockDesktopApi } from '../setup'
const sessions: Session[] = [
{ id: 'prod-a', name: 'Prod A', host: '10.0.0.1', port: 22, username: 'root', authType: 'key' },
{ id: 'prod-b', name: 'Prod B', host: '10.0.0.2', port: 22, username: 'root', authType: 'key' },
]
describe('batch session operations', () => {
beforeEach(() => {
vi.clearAllMocks()
unlockProForTests()
window.opsxApi = mockDesktopApi
vi.mocked(mockDesktopApi.sessionGetAll).mockResolvedValueOnce({ success: true, sessions })
useSessionStore.setState({ sessions: [] })
useTabStore.setState({
tabs: [{ id: 'welcome', title: '欢迎', type: 'welcome', isActive: true }],
activeTabId: 'welcome',
})
})
it('selects multiple saved sessions and opens batch exec', async () => {
const user = userEvent.setup()
render(
<Sidebar
onNewSession={vi.fn()}
onQuickConnect={vi.fn()}
onEditSession={vi.fn()}
/>
)
await screen.findByText('Prod A')
await user.click(screen.getByRole('button', { name: '批量操作' }))
await user.click(screen.getByText('Prod A'))
await user.click(screen.getByText('Prod B'))
expect(screen.getByText(/已选 2 个 SSH/)).toBeVisible()
expect(screen.queryByRole('button', { name: /打开终端/ })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: /打开 SFTP/ })).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: '批量执行' }))
expect(useTabStore.getState().tabs).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: 'batch',
batchSessionIds: ['prod-a', 'prod-b'],
}),
])
)
})
it('opens SFTP only from the saved session context menu', async () => {
const user = userEvent.setup()
render(
<Sidebar
onNewSession={vi.fn()}
onQuickConnect={vi.fn()}
onEditSession={vi.fn()}
/>
)
const sessionName = await screen.findByText('Prod A')
expect(screen.queryByTitle('SFTP')).not.toBeInTheDocument()
expect(screen.queryByText('SFTP')).not.toBeInTheDocument()
fireEvent.contextMenu(sessionName)
await user.click(screen.getByRole('button', { name: 'SFTP' }))
expect(useTabStore.getState().tabs).toEqual(expect.arrayContaining([
expect.objectContaining({ sessionId: 'prod-a', type: 'sftp' }),
]))
})
})