Files
opsxshell/test/components/App.acceptance.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

127 lines
4.4 KiB
TypeScript

import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, describe, expect, it, vi } from 'vitest'
import App from '../../src/app/App'
import { useSessionStore } from '../../src/stores/sessionStore'
import { decodeBase64ToText } from '../../src/utils/textBase64'
import { decryptSessionBackup } from '../../src/utils/sessionBackupCrypto'
import { mockDesktopApi } from '../setup'
import { unlockProForTests } from '../helpers/entitlement'
describe('App foundation acceptance', () => {
afterEach(() => {
window.opsxApi = mockDesktopApi
})
it('renders the application shell with the native desktop contract', async () => {
render(<App />)
expect(await screen.findByRole('heading', { name: 'OpsXShell' })).toBeVisible()
expect(mockDesktopApi.onMenuOpenSettings).toHaveBeenCalled()
const titleBar = document.querySelector('header[data-tauri-drag-region]')
expect(titleBar).toBeTruthy()
expect(titleBar).toHaveAttribute('data-tauri-drag-region')
})
it('renders the shell while the native bridge is unavailable', async () => {
Object.defineProperty(window, 'opsxApi', {
configurable: true,
value: undefined,
writable: true,
})
render(<App />)
expect(await screen.findByRole('heading', { name: 'OpsXShell' })).toBeVisible()
})
it('opens quick connect with a queued ssh:// target', async () => {
vi.clearAllMocks()
window.opsxApi = mockDesktopApi
vi.mocked(mockDesktopApi.takePendingSshLinks).mockResolvedValueOnce([
{ host: 'opsbase.cn', port: 55555, username: 'root' },
])
render(<App />)
expect(await screen.findByDisplayValue('root@opsbase.cn:55555')).toBeVisible()
expect(mockDesktopApi.onSshLinkAvailable).toHaveBeenCalled()
})
it('delegates title-bar double click to a single native drag-region handler', async () => {
vi.clearAllMocks()
window.opsxApi = mockDesktopApi
render(<App />)
await screen.findByRole('heading', { name: 'OpsXShell' })
const titleBar = document.querySelector('header[data-tauri-drag-region]')
expect(titleBar).toHaveAttribute('data-tauri-drag-region')
expect(titleBar).not.toHaveClass('titlebar-drag')
fireEvent.doubleClick(titleBar!)
expect(mockDesktopApi.toggleMaximize).not.toHaveBeenCalled()
})
it('writes encrypted exported sessions to the selected backup file', async () => {
const user = userEvent.setup()
vi.clearAllMocks()
unlockProForTests()
vi.mocked(mockDesktopApi.licenseGet).mockResolvedValue({
plan: 'pro',
deviceId: 'test-device',
activated: true,
features: ['*'],
})
window.opsxApi = mockDesktopApi
useSessionStore.setState({
sessions: [
{
id: 'session-1',
name: 'Production',
host: 'prod.example.com',
port: 22,
username: 'root',
authType: 'agent',
},
],
})
vi.mocked(mockDesktopApi.showSaveDialog).mockResolvedValueOnce({
canceled: false,
filePath: '/tmp/opsxshell-sessions.bak',
})
render(<App />)
await waitFor(() => expect(mockDesktopApi.onMenuExportSessions).toHaveBeenCalled())
const callback = vi.mocked(mockDesktopApi.onMenuExportSessions).mock.calls[0][0]
const exportPromise = callback()
const passwordInput = await screen.findByPlaceholderText('输入备份密码')
await user.type(passwordInput, 'backup-secret')
await user.click(screen.getByRole('button', { name: '确认' }))
const confirmInput = await screen.findByPlaceholderText('再次输入备份密码')
await user.type(confirmInput, 'backup-secret')
await user.click(screen.getByRole('button', { name: '确认' }))
await exportPromise
expect(mockDesktopApi.showSaveDialog).toHaveBeenCalledWith(
expect.objectContaining({
defaultPath: 'opsxshell-sessions.bak',
})
)
expect(mockDesktopApi.writeFile).toHaveBeenCalledWith(
'/tmp/opsxshell-sessions.bak',
expect.any(String)
)
const [, encoded] = vi.mocked(mockDesktopApi.writeFile).mock.calls[0]
const decoded = decodeBase64ToText(String(encoded))
expect(decoded).toContain('"format": "opsxshell-backup"')
expect(decoded).not.toContain('prod.example.com')
const envelope = JSON.parse(decoded)
const plaintext = await decryptSessionBackup(envelope, 'backup-secret')
expect(plaintext).toContain('"prod.example.com"')
})
})