import { describe, it, expect } from 'vitest';
import {
	CanvasEventType,
	EVENT_TYPE_INFO,
	ActionCategory,
	BuiltInActionId,
	DEFAULT_MAPPINGS,
} from '../core/settings-types';

describe('settings-types', () => {
	describe('CanvasEventType', () => {
		it('has 12 event types', () => {
			const values = Object.values(CanvasEventType);
			expect(values).toHaveLength(12);
		});

		it('includes node, edge, and background events', () => {
			expect(CanvasEventType.NodeClick).toBe('node:click');
			expect(CanvasEventType.EdgeClick).toBe('edge:click');
			expect(CanvasEventType.BackgroundClick).toBe('background:click');
		});
	});

	describe('EVENT_TYPE_INFO', () => {
		it('has an entry for every CanvasEventType', () => {
			const allTypes = Object.values(CanvasEventType);
			for (const type of allTypes) {
				expect(EVENT_TYPE_INFO[type]).toBeDefined();
				expect(EVENT_TYPE_INFO[type].type).toBe(type);
			}
		});

		it('every entry has label and description', () => {
			for (const info of Object.values(EVENT_TYPE_INFO)) {
				expect(info.label).toBeTruthy();
				expect(info.description).toBeTruthy();
			}
		});

		it('categories are valid', () => {
			for (const info of Object.values(EVENT_TYPE_INFO)) {
				expect(['node', 'edge', 'background']).toContain(info.category);
			}
		});
	});

	describe('ActionCategory', () => {
		it('has expected categories', () => {
			expect(ActionCategory.None).toBe('none');
			expect(ActionCategory.Selection).toBe('selection');
			expect(ActionCategory.Viewport).toBe('viewport');
			expect(ActionCategory.Node).toBe('node');
		});
	});

	describe('BuiltInActionId', () => {
		it('has unique values', () => {
			const values = Object.values(BuiltInActionId);
			expect(new Set(values).size).toBe(values.length);
		});

		it('includes undo/redo', () => {
			expect(BuiltInActionId.Undo).toBe('undo');
			expect(BuiltInActionId.Redo).toBe('redo');
		});
	});

	describe('DEFAULT_MAPPINGS', () => {
		it('has mapping for every event type', () => {
			const allTypes = Object.values(CanvasEventType);
			for (const type of allTypes) {
				expect(DEFAULT_MAPPINGS[type]).toBeDefined();
			}
		});

		it('node double-click maps to fit-to-view', () => {
			expect(DEFAULT_MAPPINGS[CanvasEventType.NodeDoubleClick]).toBe(BuiltInActionId.FitToView);
		});
	});
});
