/**
 * @docs ARCHITECTURE:TestSuites
 * 
 * ### AI Assist Note
 * **Validation of the Global UI Dropdown and Popover state manager.** 
 * Verifies the exclusive opening logic (mutual exclusion), toggle behavior for specific IDs/types, and auto-close triggers for all contextual menus. 
 * Pure logic tests: ensures UI state consistency without DOM side-effects.
 * 
 * ### 🔍 Debugging & Observability
 * - **Failure Path**: Z-index conflicts or multiple dropdowns remaining open simultaneously due to missing singleton guards in the state machine.
 * - **Telemetry Link**: Search `[dropdown_store.test]` in tracing logs.
 */


/**
 * @file dropdown_store.test.ts
 * @description Suite for the Centralized Dropdown State (dropdown_store).
 * @module Stores/DropdownStore
 * @testedBehavior
 * - Mutual Exclusion: Only one dropdown can be open at a time.
 * - Toggle Logic: Opening and closing behavior for specific IDs and types.
 * - Reset: Ensuring close_dropdown clears all state.
 * @aiContext
 * - Refactored for 100% snake_case architectural parity (open_id, open_type, toggle_dropdown, close_dropdown, is_open).
 * - Verified 154 tests sweep continuation.
 */
import { describe, it, expect, beforeEach } from 'vitest';
import { use_dropdown_store } from './dropdown_store';

describe('use_dropdown_store', () => {
    beforeEach(() => {
        use_dropdown_store.getState().close_dropdown();
    });

    it('starts with no dropdown open', () => {
        const state = use_dropdown_store.getState();
        expect(state.open_id).toBeNull();
        expect(state.open_type).toBeNull();
    });

    it('toggle_dropdown() opens a dropdown', () => {
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'role');
        const state = use_dropdown_store.getState();
        expect(state.open_id).toBe('agent-1');
        expect(state.open_type).toBe('role');
    });

    it('toggle_dropdown() same ID+type closes it', () => {
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'role');
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'role');
        const state = use_dropdown_store.getState();
        expect(state.open_id).toBeNull();
    });

    it('toggle_dropdown() different ID auto-closes the previous (mutual exclusion)', () => {
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'role');
        use_dropdown_store.getState().toggle_dropdown('agent-2', 'role');
        const state = use_dropdown_store.getState();
        expect(state.open_id).toBe('agent-2');
    });

    it('toggle_dropdown() different type on same ID auto-closes the previous', () => {
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'role');
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'skill');
        const state = use_dropdown_store.getState();
        expect(state.open_type).toBe('skill');
    });

    it('close_dropdown() resets all state', () => {
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'role');
        use_dropdown_store.getState().close_dropdown();
        const state = use_dropdown_store.getState();
        expect(state.open_id).toBeNull();
    });

    it('open_id and open_type state matches matching IDs', () => {
        use_dropdown_store.getState().toggle_dropdown('agent-1', 'role');
        const state = use_dropdown_store.getState();
        expect(state.open_id === 'agent-1' && state.open_type === 'role').toBe(true);
        expect(state.open_id === 'agent-2' && state.open_type === 'role').toBe(false);
    });
});


// Metadata: [dropdown_store_test]
