platform-core/tests/serviceGeneration/test_style_resolver.py
ValueOn AG d61e29bcac
Some checks failed
Deploy Plattform-Core (Int) / test (push) Failing after 24s
Deploy Plattform-Core (Int) / deploy (push) Has been skipped
fixes private model and udb scoping sources
2026-06-03 09:37:03 +02:00

93 lines
3.1 KiB
Python

# Copyright (c) 2025 Patrick Motsch
# All rights reserved.
import pytest
from modules.serviceCenter.services.serviceGeneration.styleDefaults import (
resolveStyle,
resolveTheme,
DEFAULT_STYLE,
THEME_PRESETS,
)
def test_resolve_none_returns_defaults():
result = resolveStyle(None)
assert result == DEFAULT_STYLE
def test_resolve_empty_returns_defaults():
result = resolveStyle({})
assert result == DEFAULT_STYLE
def test_override_single_color():
result = resolveStyle({"colors": {"primary": "#FF0000"}})
assert result["colors"]["primary"] == "#FF0000"
assert result["colors"]["secondary"] == DEFAULT_STYLE["colors"]["secondary"]
def test_override_nested_heading():
result = resolveStyle({"headings": {"h1": {"sizePt": 30}}})
assert result["headings"]["h1"]["sizePt"] == 30
assert result["headings"]["h1"]["weight"] == "bold"
def test_override_font():
result = resolveStyle({"fonts": {"primary": "Arial"}})
assert result["fonts"]["primary"] == "Arial"
assert result["fonts"]["monospace"] == "Consolas"
def test_full_style_passthrough():
custom = {"fonts": {"primary": "Helvetica", "monospace": "Monaco"}}
result = resolveStyle(custom)
assert result["fonts"]["primary"] == "Helvetica"
assert result["fonts"]["monospace"] == "Monaco"
def test_override_document_title_partial_merge():
result = resolveStyle({"documentTitle": {"sizePt": 32}})
assert result["documentTitle"]["sizePt"] == 32
assert result["documentTitle"]["align"] == "center"
assert result["headings"]["h1"]["sizePt"] == DEFAULT_STYLE["headings"]["h1"]["sizePt"]
# ── Theme presets (A3) ─────────────────────────────────────────────
def test_resolve_theme_unknown_is_empty():
assert resolveTheme(None) == {}
assert resolveTheme("does-not-exist") == {}
def test_resolve_theme_case_insensitive():
assert resolveTheme("FINANCE") == THEME_PRESETS["finance"]
def test_general_theme_equals_defaults():
assert resolveStyle(None, "general") == DEFAULT_STYLE
def test_theme_applies_preset_over_defaults():
result = resolveStyle(None, "legal")
# legal preset changes the primary font to a serif and justifies body text
assert result["fonts"]["primary"] == "Times New Roman"
assert result["paragraph"]["align"] == "justify"
# untouched keys still come from DEFAULT_STYLE
assert result["page"]["format"] == DEFAULT_STYLE["page"]["format"]
def test_explicit_style_overrides_theme():
# theme sets finance green; explicit style must win
result = resolveStyle({"colors": {"primary": "#FF0000"}}, "finance")
assert result["colors"]["primary"] == "#FF0000"
# non-overridden theme key still applies
assert result["table"]["headerBg"] == THEME_PRESETS["finance"]["table"]["headerBg"]
def test_marketing_theme_enlarges_title_and_images():
result = resolveStyle(None, "marketing")
assert result["documentTitle"]["sizePt"] == 34
assert result["image"]["defaultWidthPt"] == 540
def test_unknown_theme_falls_back_to_defaults():
assert resolveStyle(None, "rainbow") == DEFAULT_STYLE