import { describe, it, expect } from 'vitest';
import { renderHook } from '@testing-library/react';
import React from 'react';
import { Provider, createStore } from 'jotai';
import { useActionExecutor } from '../hooks/useActionExecutor';

function wrapper({ children }: { children: React.ReactNode }) {
	const store = createStore();
	return React.createElement(Provider, { store }, children);
}

describe('useActionExecutor hook', () => {
	it('returns executeActionById function', () => {
		const { result } = renderHook(() => useActionExecutor(), { wrapper });
		expect(typeof result.current.executeActionById).toBe('function');
	});

	it('returns executeEventAction function', () => {
		const { result } = renderHook(() => useActionExecutor(), { wrapper });
		expect(typeof result.current.executeEventAction).toBe('function');
	});

	it('returns getActionForEvent function', () => {
		const { result } = renderHook(() => useActionExecutor(), { wrapper });
		expect(typeof result.current.getActionForEvent).toBe('function');
	});

	it('returns helpers object', () => {
		const { result } = renderHook(() => useActionExecutor(), { wrapper });
		expect(result.current.helpers).toBeDefined();
		expect(typeof result.current.helpers.selectNode).toBe('function');
		expect(typeof result.current.helpers.clearSelection).toBe('function');
	});

	it('returns mappings object', () => {
		const { result } = renderHook(() => useActionExecutor(), { wrapper });
		expect(result.current.mappings).toBeDefined();
	});

	it('accepts options', () => {
		const onDelete = async () => {};
		const { result } = renderHook(
			() => useActionExecutor({ onDeleteNode: onDelete }),
			{ wrapper },
		);
		expect(result.current.helpers).toBeDefined();
	});
});
