A Python port of the Invisible Internet Project (I2P)
1"""Tests for desktop system tray — TDD: tests before implementation."""
2
3import pytest
4from unittest.mock import patch
5
6from i2p_apps.desktop.tray import TrayConfig, TrayMenu, MenuItem
7
8
9class TestTrayConfig:
10 def test_defaults(self):
11 cfg = TrayConfig()
12 assert cfg.console_url == "http://127.0.0.1:7657"
13 assert cfg.tooltip == "I2P Router"
14
15 def test_custom(self):
16 cfg = TrayConfig(console_url="http://localhost:8080", tooltip="My I2P")
17 assert cfg.console_url == "http://localhost:8080"
18 assert cfg.tooltip == "My I2P"
19
20
21class TestMenuItem:
22 def test_creation(self):
23 item = MenuItem(label="Open Console", action="open_console")
24 assert item.label == "Open Console"
25 assert item.action == "open_console"
26
27 def test_separator(self):
28 item = MenuItem.separator()
29 assert item.is_separator is True
30
31 def test_not_separator(self):
32 item = MenuItem(label="Quit", action="quit")
33 assert item.is_separator is False
34
35
36class TestTrayMenu:
37 def test_default_items(self):
38 menu = TrayMenu()
39 labels = [item.label for item in menu.items if not item.is_separator]
40 assert "Open Console" in labels
41 assert "Restart" in labels
42 assert any("Shutdown" in l for l in labels)
43
44 def test_item_count(self):
45 menu = TrayMenu()
46 assert len(menu.items) >= 3
47
48 def test_custom_items(self):
49 items = [
50 MenuItem(label="Custom", action="custom"),
51 MenuItem(label="Quit", action="quit"),
52 ]
53 menu = TrayMenu(items=items)
54 assert len(menu.items) == 2
55
56 def test_status_text(self):
57 menu = TrayMenu()
58 status = menu.status_text("running", 5)
59 assert "running" in status.lower() or "Running" in status
60 assert "5" in status