import { mock } from 'vitest-mock-extended' import { Resource, SpaceResource } from '@ownclouders/web-client' import { useFileActions, Action, useOpenWithDefaultApp, FileAction } from '../../../../src/composables' import { getComposableWrapper } from '../../../../src/testing' vi.mock('../../../../src/composables/actions/files', async (importOriginal) => ({ ...(await importOriginal()), useFileActions: vi.fn() })) describe('useOpenWithDefaultApp', () => { it('should be valid', () => { expect(useOpenWithDefaultApp).toBeDefined() }) describe('method "openWithDefaultApp"', () => { it('should call the default action handler for files', () => { getWrapper({ setup: ({ openWithDefaultApp }, { defaultEditorAction }) => { openWithDefaultApp({ space: mock(), resource: mock({ isFolder: false }) }) expect(defaultEditorAction.handler).toHaveBeenCalled() } }) }) it('should not call the default action handler for folders', () => { getWrapper({ setup: ({ openWithDefaultApp }, { defaultEditorAction }) => { openWithDefaultApp({ space: mock(), resource: mock({ isFolder: true }) }) expect(defaultEditorAction.handler).not.toHaveBeenCalled() } }) }) }) }) function getWrapper({ setup, defaultEditorAction = mock({ handler: vi.fn() }) }: { setup: ( instance: ReturnType, mocks: { defaultEditorAction: FileAction } ) => void defaultEditorAction?: FileAction }) { vi.mocked(useFileActions).mockReturnValue( mock>({ getDefaultAction: () => defaultEditorAction }) ) const mocks = { defaultEditorAction } return { wrapper: getComposableWrapper(() => { const instance = useOpenWithDefaultApp() setup(instance, mocks) }) } }