5 Power-Aktionen (lock, logout, hibernate, reboot, shutdown), GTK4 + Layer Shell UI mit Catppuccin Mocha Theme, Multi-Monitor-Support, Inline-Confirmation, DE/EN i18n, TOML-Config mit Wallpaper-Fallback. 54 Tests grün.
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
# ABOUTME: Tests for the power menu panel UI module.
|
|
# ABOUTME: Verifies action button creation, confirmation flow, and dismiss behavior.
|
|
|
|
from unittest.mock import MagicMock, patch, PropertyMock
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
from moonset.i18n import load_strings
|
|
from moonset.panel import (
|
|
ACTION_DEFINITIONS,
|
|
ActionDef,
|
|
)
|
|
|
|
|
|
class TestActionDefinitions:
|
|
"""Tests for action definition structure."""
|
|
|
|
def test_has_five_actions(self) -> None:
|
|
assert len(ACTION_DEFINITIONS) == 5
|
|
|
|
def test_action_order_by_destructiveness(self) -> None:
|
|
names = [a.name for a in ACTION_DEFINITIONS]
|
|
assert names == ["lock", "logout", "hibernate", "reboot", "shutdown"]
|
|
|
|
def test_lock_has_no_confirmation(self) -> None:
|
|
lock_def = ACTION_DEFINITIONS[0]
|
|
assert lock_def.name == "lock"
|
|
assert lock_def.needs_confirm is False
|
|
|
|
def test_destructive_actions_need_confirmation(self) -> None:
|
|
for action_def in ACTION_DEFINITIONS[1:]:
|
|
assert action_def.needs_confirm is True, (
|
|
f"{action_def.name} should need confirmation"
|
|
)
|
|
|
|
def test_all_actions_have_icon_names(self) -> None:
|
|
for action_def in ACTION_DEFINITIONS:
|
|
assert action_def.icon_name, f"{action_def.name} missing icon_name"
|
|
assert action_def.icon_name.endswith("-symbolic")
|
|
|
|
def test_all_actions_have_callable_functions(self) -> None:
|
|
for action_def in ACTION_DEFINITIONS:
|
|
assert callable(action_def.action_fn)
|
|
|
|
def test_action_labels_from_strings(self) -> None:
|
|
strings = load_strings("en")
|
|
for action_def in ACTION_DEFINITIONS:
|
|
label = action_def.get_label(strings)
|
|
assert label, f"{action_def.name} has empty label"
|
|
|
|
def test_action_error_messages_from_strings(self) -> None:
|
|
strings = load_strings("en")
|
|
for action_def in ACTION_DEFINITIONS:
|
|
error_msg = action_def.get_error_message(strings)
|
|
assert error_msg, f"{action_def.name} has empty error message"
|
|
|
|
def test_confirmable_actions_have_confirm_prompts(self) -> None:
|
|
strings = load_strings("en")
|
|
for action_def in ACTION_DEFINITIONS:
|
|
if action_def.needs_confirm:
|
|
prompt = action_def.get_confirm_prompt(strings)
|
|
assert prompt, f"{action_def.name} has empty confirm prompt"
|
|
|
|
def test_lock_confirm_prompt_is_none(self) -> None:
|
|
strings = load_strings("en")
|
|
lock_def = ACTION_DEFINITIONS[0]
|
|
assert lock_def.get_confirm_prompt(strings) is None
|