51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { I18nProvider } from '@/i18n'
|
|
|
|
const { openFileWithSystemApp } = vi.hoisted(() => ({ openFileWithSystemApp: vi.fn() }))
|
|
|
|
vi.mock('@/lib/desktop-fs', () => ({ isDesktopFsRemoteMode: () => false }))
|
|
vi.mock('@/lib/office-files', () => ({ openFileWithSystemApp }))
|
|
|
|
import { FileEntryContextMenu } from './file-actions'
|
|
|
|
function renderMenu(isDirectory = false) {
|
|
return render(
|
|
<I18nProvider configClient={null} initialLocale="zh">
|
|
<FileEntryContextMenu
|
|
isDirectory={isDirectory}
|
|
name={isDirectory ? 'src' : 'notes.md'}
|
|
path={`/w/${isDirectory ? 'src' : 'notes.md'}`}
|
|
>
|
|
<button type="button">Row</button>
|
|
</FileEntryContextMenu>
|
|
</I18nProvider>
|
|
)
|
|
}
|
|
|
|
beforeEach(() => {
|
|
openFileWithSystemApp.mockReset().mockResolvedValue(true)
|
|
})
|
|
|
|
afterEach(cleanup)
|
|
|
|
describe('FileEntryContextMenu system open action', () => {
|
|
it('opens files with the system app', async () => {
|
|
renderMenu()
|
|
|
|
fireEvent.contextMenu(screen.getByRole('button', { name: 'Row' }))
|
|
fireEvent.click(await screen.findByRole('menuitem', { name: '用系统应用打开' }))
|
|
|
|
expect(openFileWithSystemApp).toHaveBeenCalledWith('/w/notes.md')
|
|
})
|
|
|
|
it('does not offer system open for directories', () => {
|
|
renderMenu(true)
|
|
|
|
fireEvent.contextMenu(screen.getByRole('button', { name: 'Row' }))
|
|
|
|
expect(screen.queryByRole('menuitem', { name: '用系统应用打开' })).toBeNull()
|
|
})
|
|
})
|