import pytest
import time
from src.api_hook_client import ApiHookClient

def test_task_dag_popout(live_gui):
 client = ApiHookClient()
 
 # 1. Check initial state
 state = client.get_gui_state()
 assert state.get("ui_separate_task_dag") is False
 
 # 2. Enable popout and ensure window is shown
 client.set_value("ui_separate_task_dag", True)
 # We need to manually set show_windows["Task DAG"] as well since we are bypassing the checkbox logic
 show_windows = state.get("show_windows", {})
 show_windows["Task DAG"] = True
 client.set_value("show_windows", show_windows)
 time.sleep(1)
 
 # 3. Verify state
 state = client.get_gui_state()
 assert state.get("ui_separate_task_dag") is True
 assert state.get("show_windows", {}).get("Task DAG") is True
 
 # 4. Disable popout
 client.set_value("ui_separate_task_dag", False)
 time.sleep(1)
 
 state = client.get_gui_state()
 assert state.get("ui_separate_task_dag") is False
