feat: Implement runtime branding management and add branding settings to UI
This commit is contained in:
parent
f022d984b6
commit
ca7105a6bc
8 changed files with 493 additions and 64 deletions
74
tests/unit/test_branding_manager.py
Normal file
74
tests/unit/test_branding_manager.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
"""Tests for runtime branding template management."""
|
||||
|
||||
from webdrop_bridge.config import Config
|
||||
from webdrop_bridge.core.branding_manager import BrandingManager
|
||||
|
||||
|
||||
def test_builtin_brandings_are_available(tmp_path):
|
||||
"""Built-in default and Agravity templates should always be available."""
|
||||
manager = BrandingManager(base_dir=tmp_path)
|
||||
|
||||
brandings = manager.list_templates()
|
||||
template_ids = [template.template_id for template in brandings]
|
||||
|
||||
assert "default" in template_ids
|
||||
assert "agravity" in template_ids
|
||||
|
||||
|
||||
def test_active_branding_persists_across_manager_instances(tmp_path):
|
||||
"""Selected active branding should persist on disk."""
|
||||
manager = BrandingManager(base_dir=tmp_path)
|
||||
manager.set_active_branding_id("agravity")
|
||||
|
||||
reloaded_manager = BrandingManager(base_dir=tmp_path)
|
||||
|
||||
assert reloaded_manager.get_active_branding_id() == "agravity"
|
||||
|
||||
|
||||
def test_apply_branding_updates_cosmetic_fields_only(tmp_path):
|
||||
"""Applying a branding template should not overwrite setup-specific values."""
|
||||
allowed_root = tmp_path / "allowed"
|
||||
allowed_root.mkdir()
|
||||
|
||||
config = Config(
|
||||
app_name="WebDrop Bridge",
|
||||
app_version="1.0.0",
|
||||
log_level="INFO",
|
||||
log_file=None,
|
||||
allowed_roots=[allowed_root],
|
||||
allowed_urls=["example.com"],
|
||||
webapp_url="http://localhost:8080",
|
||||
window_width=1024,
|
||||
window_height=768,
|
||||
enable_logging=True,
|
||||
active_branding_id="agravity",
|
||||
)
|
||||
|
||||
manager = BrandingManager(base_dir=tmp_path)
|
||||
manager.apply_to_config(config)
|
||||
|
||||
assert config.active_branding_id == "agravity"
|
||||
assert config.app_name == "Agravity Bridge"
|
||||
assert config.webapp_url == "http://localhost:8080"
|
||||
assert config.allowed_roots == [allowed_root]
|
||||
assert config.toolbar_icon_home.endswith("home.ico")
|
||||
|
||||
|
||||
def test_config_from_env_uses_persisted_active_branding(tmp_path, monkeypatch):
|
||||
"""Config loading should apply the persisted active branding automatically."""
|
||||
branding_dir = tmp_path / "branding-state"
|
||||
manager = BrandingManager(base_dir=branding_dir)
|
||||
manager.set_active_branding_id("agravity")
|
||||
|
||||
monkeypatch.setenv("WEBDROP_BRANDING_DIR", str(branding_dir))
|
||||
|
||||
root = tmp_path / "root"
|
||||
root.mkdir()
|
||||
env_file = tmp_path / ".env"
|
||||
env_file.write_text(f"ALLOWED_ROOTS={root}\n", encoding="utf-8")
|
||||
|
||||
config = Config.from_env(str(env_file))
|
||||
|
||||
assert config.active_branding_id == "agravity"
|
||||
assert config.app_name == "Agravity Bridge"
|
||||
assert config.get_config_path().name == "config.json"
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
"""Tests for settings dialog."""
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from webdrop_bridge.config import Config, ConfigurationError
|
||||
from webdrop_bridge.config import Config
|
||||
from webdrop_bridge.ui.settings_dialog import SettingsDialog
|
||||
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ class TestSettingsDialogInitialization:
|
|||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs is not None
|
||||
assert dialog.tabs.count() == 7 # General + previous 6 tabs
|
||||
assert dialog.tabs.count() == 8 # General + Branding + previous 6 tabs
|
||||
|
||||
def test_dialog_has_general_tab(self, qtbot, sample_config):
|
||||
"""Test General tab exists."""
|
||||
|
|
@ -53,47 +52,54 @@ class TestSettingsDialogInitialization:
|
|||
|
||||
assert dialog.tabs.tabText(0) == "General"
|
||||
|
||||
def test_dialog_has_branding_tab(self, qtbot, sample_config):
|
||||
"""Test Branding tab exists."""
|
||||
dialog = SettingsDialog(sample_config)
|
||||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs.tabText(1) == "Branding"
|
||||
|
||||
def test_dialog_has_web_source_tab(self, qtbot, sample_config):
|
||||
"""Test Web Source tab exists."""
|
||||
dialog = SettingsDialog(sample_config)
|
||||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs.tabText(1) == "Web Source"
|
||||
assert dialog.tabs.tabText(2) == "Web Source"
|
||||
|
||||
def test_dialog_has_paths_tab(self, qtbot, sample_config):
|
||||
"""Test Paths tab exists."""
|
||||
dialog = SettingsDialog(sample_config)
|
||||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs.tabText(2) == "Paths"
|
||||
assert dialog.tabs.tabText(3) == "Paths"
|
||||
|
||||
def test_dialog_has_urls_tab(self, qtbot, sample_config):
|
||||
"""Test URLs tab exists."""
|
||||
dialog = SettingsDialog(sample_config)
|
||||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs.tabText(3) == "URLs"
|
||||
assert dialog.tabs.tabText(4) == "URLs"
|
||||
|
||||
def test_dialog_has_logging_tab(self, qtbot, sample_config):
|
||||
"""Test Logging tab exists."""
|
||||
dialog = SettingsDialog(sample_config)
|
||||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs.tabText(4) == "Logging"
|
||||
assert dialog.tabs.tabText(5) == "Logging"
|
||||
|
||||
def test_dialog_has_window_tab(self, qtbot, sample_config):
|
||||
"""Test Window tab exists."""
|
||||
dialog = SettingsDialog(sample_config)
|
||||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs.tabText(5) == "Window"
|
||||
assert dialog.tabs.tabText(6) == "Window"
|
||||
|
||||
def test_dialog_has_profiles_tab(self, qtbot, sample_config):
|
||||
"""Test Setups tab exists with clearer wording."""
|
||||
dialog = SettingsDialog(sample_config)
|
||||
qtbot.addWidget(dialog)
|
||||
|
||||
assert dialog.tabs.tabText(6) == "Setups"
|
||||
assert dialog.tabs.tabText(7) == "Setups"
|
||||
|
||||
def test_profiles_actions_have_explanatory_tooltips(self, qtbot, sample_config):
|
||||
"""Test profile/config actions expose helpful explanations."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue