import { describe, it, expect, beforeEach } from 'vitest';
import { commandRegistry } from '../commands/registry';
import {
	copyCommand,
	cutCommand,
	pasteCommand,
	duplicateCommand,
	deleteSelectedCommand,
	registerClipboardCommands,
} from '../commands/builtins/clipboard-commands';

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

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

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

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

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

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

	it('all commands have descriptions', () => {
		const commands = [copyCommand, cutCommand, pasteCommand, duplicateCommand, deleteSelectedCommand];
		for (const cmd of commands) {
			expect(cmd.description).toBeTruthy();
		}
	});

	it('all commands have category', () => {
		const commands = [copyCommand, cutCommand, pasteCommand, duplicateCommand, deleteSelectedCommand];
		for (const cmd of commands) {
			expect(cmd.category).toBeTruthy();
		}
	});

	it('all commands have execute function', () => {
		const commands = [copyCommand, cutCommand, pasteCommand, duplicateCommand, deleteSelectedCommand];
		for (const cmd of commands) {
			expect(cmd.execute).toBeTypeOf('function');
		}
	});

	it('registerClipboardCommands registers all 5 commands', () => {
		registerClipboardCommands();
		expect(commandRegistry.has('copy')).toBe(true);
		expect(commandRegistry.has('cut')).toBe(true);
		expect(commandRegistry.has('paste')).toBe(true);
		expect(commandRegistry.has('duplicate')).toBe(true);
		expect(commandRegistry.has('deleteSelected')).toBe(true);
	});

	it('commands have aliases', () => {
		registerClipboardCommands();
		// At least some should have aliases
		const allCommands = [copyCommand, cutCommand, pasteCommand, duplicateCommand, deleteSelectedCommand];
		const hasAliases = allCommands.some((cmd) => cmd.aliases && cmd.aliases.length > 0);
		expect(hasAliases).toBe(true);
	});
});
