import { describe, it, expect } from 'vitest';
import {
	SEARCH_CONTEXT,
	KEYBOARD_MANIPULATE_CONTEXT,
	KEYBOARD_NAVIGATE_CONTEXT,
} from '../gestures/keyboard-contexts';

describe('keyboard-contexts', () => {
	const allContexts = [SEARCH_CONTEXT, KEYBOARD_MANIPULATE_CONTEXT, KEYBOARD_NAVIGATE_CONTEXT];

	it('all contexts have unique IDs', () => {
		const ids = allContexts.map((c) => c.id);
		expect(new Set(ids).size).toBe(ids.length);
	});

	it('no duplicate binding IDs within any context', () => {
		for (const ctx of allContexts) {
			const ids = ctx.bindings.map((b) => b.id);
			expect(new Set(ids).size).toBe(ids.length);
		}
	});

	it('SEARCH_CONTEXT has priority 25', () => {
		expect(SEARCH_CONTEXT.priority).toBe(25);
	});

	it('KEYBOARD_NAVIGATE_CONTEXT has higher priority than MANIPULATE', () => {
		expect(KEYBOARD_NAVIGATE_CONTEXT.priority).toBeGreaterThan(KEYBOARD_MANIPULATE_CONTEXT.priority);
	});

	it('navigate context includes arrow key bindings', () => {
		const arrowIds = KEYBOARD_NAVIGATE_CONTEXT.bindings.filter((b) => b.id.includes('arrow'));
		expect(arrowIds.length).toBeGreaterThanOrEqual(4);
	});

	it('manipulate context includes nudge bindings', () => {
		const nudgeBindings = KEYBOARD_MANIPULATE_CONTEXT.bindings.filter((b) => b.actionId.includes('nudge'));
		expect(nudgeBindings.length).toBeGreaterThanOrEqual(4);
	});

	it('all contexts are enabled by default', () => {
		for (const ctx of allContexts) {
			expect(ctx.enabled).toBe(true);
		}
	});
});
