import { describe, it, expect, beforeEach } from 'vitest';
import { commandRegistry } from '../commands/registry';
import {
	groupNodesCommand,
	ungroupNodesCommand,
	collapseGroupCommand,
	expandGroupCommand,
	registerGroupCommands,
} from '../commands/builtins/group-commands';

describe('group-commands', () => {
	beforeEach(() => {
		commandRegistry.clear();
	});

	it('groupNodesCommand has correct name', () => {
		expect(groupNodesCommand.name).toBe('groupNodes');
	});

	it('ungroupNodesCommand has correct name', () => {
		expect(ungroupNodesCommand.name).toBe('ungroupNodes');
	});

	it('collapseGroupCommand has correct name', () => {
		expect(collapseGroupCommand.name).toBe('collapseGroup');
	});

	it('expandGroupCommand has correct name', () => {
		expect(expandGroupCommand.name).toBe('expandGroup');
	});

	it('all commands have descriptions', () => {
		const commands = [groupNodesCommand, ungroupNodesCommand, collapseGroupCommand, expandGroupCommand];
		for (const cmd of commands) {
			expect(cmd.description).toBeTruthy();
		}
	});

	it('all commands have category', () => {
		const commands = [groupNodesCommand, ungroupNodesCommand, collapseGroupCommand, expandGroupCommand];
		for (const cmd of commands) {
			expect(cmd.category).toBeTruthy();
		}
	});

	it('all commands have execute function', () => {
		const commands = [groupNodesCommand, ungroupNodesCommand, collapseGroupCommand, expandGroupCommand];
		for (const cmd of commands) {
			expect(cmd.execute).toBeTypeOf('function');
		}
	});

	it('groupNodesCommand requires node inputs', () => {
		expect(groupNodesCommand.inputs.length).toBeGreaterThan(0);
	});

	it('registerGroupCommands registers all 4 commands', () => {
		registerGroupCommands();
		expect(commandRegistry.has('groupNodes')).toBe(true);
		expect(commandRegistry.has('ungroupNodes')).toBe(true);
		expect(commandRegistry.has('collapseGroup')).toBe(true);
		expect(commandRegistry.has('expandGroup')).toBe(true);
	});

	it('group and ungroup are in same category', () => {
		expect(groupNodesCommand.category).toBe(ungroupNodesCommand.category);
	});
});
