A Python port of the Invisible Internet Project (I2P)
at main 75 lines 2.3 kB view raw
1"""Tests for system tray data classes and menu configuration.""" 2 3import pytest 4 5from i2p_apps.desktop.tray import MenuItem, TrayConfig, TrayMenu 6 7 8class TestTrayConfig: 9 def test_defaults(self): 10 c = TrayConfig() 11 assert c.console_url == "http://127.0.0.1:7657" 12 assert c.tooltip == "I2P Router" 13 14 def test_custom(self): 15 c = TrayConfig(console_url="http://localhost:9999", tooltip="Test") 16 assert c.console_url == "http://localhost:9999" 17 assert c.tooltip == "Test" 18 19 20class TestMenuItem: 21 def test_creation(self): 22 mi = MenuItem(label="Open Console", action="open_console") 23 assert mi.label == "Open Console" 24 assert mi.action == "open_console" 25 assert mi.is_separator is False 26 27 def test_separator(self): 28 sep = MenuItem.separator() 29 assert sep.is_separator is True 30 assert sep.label == "" 31 assert sep.action == "" 32 33 def test_defaults(self): 34 mi = MenuItem() 35 assert mi.label == "" 36 assert mi.action == "" 37 assert mi.is_separator is False 38 39 40class TestTrayMenu: 41 def test_default_items(self): 42 menu = TrayMenu() 43 assert len(menu.items) > 0 44 # First item should be Open Console 45 assert menu.items[0].action == "open_console" 46 # Should contain separators 47 seps = [i for i in menu.items if i.is_separator] 48 assert len(seps) >= 2 49 50 def test_custom_items(self): 51 items = [ 52 MenuItem(label="Test", action="test"), 53 MenuItem.separator(), 54 ] 55 menu = TrayMenu(items=items) 56 assert len(menu.items) == 2 57 58 def test_status_text(self): 59 text = TrayMenu.status_text("running", 42) 60 assert "Running" in text 61 assert "42" in text 62 63 def test_status_text_different_states(self): 64 text = TrayMenu.status_text("starting", 0) 65 assert "Starting" in text 66 assert "0" in text 67 68 def test_default_items_actions(self): 69 menu = TrayMenu() 70 actions = [i.action for i in menu.items if not i.is_separator] 71 assert "open_console" in actions 72 assert "restart" in actions 73 assert "shutdown_graceful" in actions 74 assert "shutdown" in actions 75 assert "cancel_shutdown" in actions