39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { TabContextMenu } from '../../src/components/layout/tabbar/TabContextMenu'
|
|
import { tabSupportsReconnect } from '../../src/utils/tabReconnect'
|
|
|
|
describe('TabContextMenu', () => {
|
|
it('lists SFTP, clone, reconnect, then close actions', () => {
|
|
const onReconnect = vi.fn()
|
|
render(
|
|
<TabContextMenu
|
|
isOpen
|
|
position={{ x: 8, y: 8 }}
|
|
onClose={vi.fn()}
|
|
onCloseTab={vi.fn()}
|
|
onCloseOthers={vi.fn()}
|
|
onCloseRight={vi.fn()}
|
|
onCloseLeft={vi.fn()}
|
|
onCloseAll={vi.fn()}
|
|
onClone={vi.fn()}
|
|
onOpenSftp={vi.fn()}
|
|
onReconnect={onReconnect}
|
|
/>
|
|
)
|
|
|
|
const labels = screen.getAllByRole('button').map((button) => button.textContent)
|
|
expect(labels.slice(0, 4)).toEqual(['打开 SFTP', '克隆标签', '重新连接', '关闭'])
|
|
fireEvent.click(screen.getByRole('button', { name: '重新连接' }))
|
|
expect(onReconnect).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('offers reconnect for SSH / SFTP / desktop tabs only', () => {
|
|
expect(tabSupportsReconnect({ type: 'terminal' })).toBe(true)
|
|
expect(tabSupportsReconnect({ type: 'sftp' })).toBe(true)
|
|
expect(tabSupportsReconnect({ type: 'rdp' })).toBe(true)
|
|
expect(tabSupportsReconnect({ type: 'welcome' })).toBe(false)
|
|
expect(tabSupportsReconnect({ type: 'settings' })).toBe(false)
|
|
})
|
|
})
|