import { describe, it, expect, beforeEach } from 'vitest';
import { createStore } from 'jotai';
import {
	collectInput,
	handlePickedPoint,
	handlePickedNode,
	cancelCommand,
} from '../commands/executor';
import {
	commandLineVisibleAtom,
	commandLineStateAtom,
} from '../commands/store-atoms';

describe('command-executor', () => {
	let store: ReturnType<typeof createStore>;

	beforeEach(() => {
		store = createStore();
	});

	describe('collectInput', () => {
		it('rejects with not-implemented error', async () => {
			const get = store.get.bind(store);
			const set = store.set.bind(store);
			await expect(
				collectInput(get, set, { name: 'test', type: 'text', prompt: 'Enter' }, {}),
			).rejects.toThrow('not yet implemented');
		});
	});

	describe('handlePickedPoint', () => {
		it('is a function', () => {
			expect(typeof handlePickedPoint).toBe('function');
		});
	});

	describe('handlePickedNode', () => {
		it('is a function', () => {
			expect(typeof handlePickedNode).toBe('function');
		});
	});

	describe('cancelCommand', () => {
		it('closes command line', () => {
			store.set(commandLineVisibleAtom, true);
			cancelCommand(store.set.bind(store));
			expect(store.get(commandLineVisibleAtom)).toBe(false);
			expect(store.get(commandLineStateAtom).phase).toBe('idle');
		});
	});
});
