mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-16 14:49:09 +02:00
React import is required for JSX but eslint flags it as unused. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
/**
|
|
* @vitest-environment jsdom
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
import * as React from 'react'
|
|
import { act } from 'react'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { createRoot, type Root } from 'react-dom/client'
|
|
import { FileTree } from '../../../../src/renderer/src/components/FileTree'
|
|
|
|
const flushPromises = (): Promise<void> =>
|
|
new Promise((resolve) => {
|
|
setTimeout(resolve, 0)
|
|
})
|
|
|
|
describe('FileTree', () => {
|
|
let container: HTMLDivElement
|
|
let root: Root
|
|
|
|
const electronAPI = {
|
|
listDirectory: vi.fn(),
|
|
detectApps: vi.fn(),
|
|
openWith: vi.fn()
|
|
}
|
|
|
|
beforeEach(() => {
|
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
|
container = document.createElement('div')
|
|
document.body.appendChild(container)
|
|
root = createRoot(container)
|
|
electronAPI.listDirectory.mockResolvedValue([])
|
|
electronAPI.detectApps.mockResolvedValue([])
|
|
;(window as typeof window & { electronAPI: typeof electronAPI }).electronAPI = electronAPI
|
|
})
|
|
|
|
afterEach(() => {
|
|
act(() => {
|
|
root.unmount()
|
|
})
|
|
container.remove()
|
|
globalThis.IS_REACT_ACT_ENVIRONMENT = false
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('shows the root row even when the directory is empty', async () => {
|
|
act(() => {
|
|
root.render(<FileTree rootPath="/tmp/project" />)
|
|
})
|
|
|
|
await act(async () => {
|
|
await flushPromises()
|
|
})
|
|
|
|
expect(electronAPI.listDirectory).toHaveBeenCalledWith('/tmp/project')
|
|
expect(container.textContent).toContain('project')
|
|
expect(container.textContent).toContain('(empty)')
|
|
expect(container.textContent).not.toContain('Empty directory')
|
|
})
|
|
})
|