import pytest
from unittest.mock import MagicMock, patch
from imgui_bundle import imgui
from src.theme_nerv_fx import AlertPulsing

def test_alert_pulsing_update():
 ap = AlertPulsing()
 assert ap.active is False
 
 ap.update("error: something failed")
 assert ap.active is True
 
 ap.update("ok: all good")
 assert ap.active is False
 
 ap.update("Error: Case Insensitive")
 assert ap.active is True

def test_alert_pulsing_render_inactive():
 ap = AlertPulsing()
 ap.active = False
 
 with patch("src.theme_nerv_fx.imgui.get_foreground_draw_list") as mock_get_draw_list:
  ap.render(100.0, 100.0)
  mock_get_draw_list.assert_not_called()

def test_alert_pulsing_render_active():
 ap = AlertPulsing()
 ap.active = True
 
 mock_draw_list = MagicMock()
 with patch("src.theme_nerv_fx.imgui.get_foreground_draw_list", return_value=mock_draw_list) as mock_get_draw_list, \
      patch("src.theme_nerv_fx.imgui.get_color_u32", return_value=0xFF0000FF) as mock_get_color, \
      patch("time.time", return_value=1.0):
  
  ap.render(800.0, 600.0)
  
  mock_get_draw_list.assert_called_once()
  mock_get_color.assert_called_once()
  mock_draw_list.add_rect.assert_called_once()
  
  # Check arguments of add_rect
  # add_rect(p_min, p_max, col, rounding, flags, thickness)
  args, kwargs = mock_draw_list.add_rect.call_args
  assert args[0] == (0.0, 0.0)
  assert args[1] == (800.0, 600.0)
  assert args[2] == 0xFF0000FF
  assert args[3] == 0.0
  assert args[4] == 0
  assert args[5] == 10.0
