import { describe, it, expect, beforeEach } from 'vitest';
import { commandRegistry } from '../commands/registry';
import {
	fitToViewCommand,
	fitSelectionCommand,
	resetViewportCommand,
	zoomInCommand,
	zoomOutCommand,
	registerViewportCommands,
} from '../commands/builtins/viewport-commands';

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

	it('fitToViewCommand has correct shape', () => {
		expect(fitToViewCommand.name).toBeTruthy();
		expect(fitToViewCommand.category).toBe('viewport');
		expect(typeof fitToViewCommand.execute).toBe('function');
	});

	it('fitSelectionCommand has correct shape', () => {
		expect(fitSelectionCommand.name).toBeTruthy();
		expect(fitSelectionCommand.category).toBe('viewport');
	});

	it('resetViewportCommand has correct shape', () => {
		expect(resetViewportCommand.name).toBeTruthy();
		expect(typeof resetViewportCommand.execute).toBe('function');
	});

	it('zoomInCommand has correct shape', () => {
		expect(zoomInCommand.name).toBeTruthy();
		expect(typeof zoomInCommand.execute).toBe('function');
	});

	it('zoomOutCommand has correct shape', () => {
		expect(zoomOutCommand.name).toBeTruthy();
		expect(typeof zoomOutCommand.execute).toBe('function');
	});

	it('registerViewportCommands registers all 5', () => {
		registerViewportCommands();
		expect(commandRegistry.has(fitToViewCommand.name)).toBe(true);
		expect(commandRegistry.has(resetViewportCommand.name)).toBe(true);
		expect(commandRegistry.has(zoomInCommand.name)).toBe(true);
		expect(commandRegistry.has(zoomOutCommand.name)).toBe(true);
	});

	it('all viewport commands have descriptions', () => {
		const cmds = [fitToViewCommand, fitSelectionCommand, resetViewportCommand, zoomInCommand, zoomOutCommand];
		for (const cmd of cmds) {
			expect(cmd.description).toBeTruthy();
		}
	});
});
