refactor(settings): separate preview validation from internal failures

This commit is contained in:
Bu5hm4nn
2026-03-26 15:00:53 +01:00
parent e860c40567
commit 38d244356c
2 changed files with 113 additions and 38 deletions

View File

@@ -0,0 +1,40 @@
from __future__ import annotations
from app.models.portfolio import PortfolioConfig
from app.pages.settings import _save_card_status_text
def test_save_card_status_text_for_clean_state() -> None:
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=145_000.0)
text = _save_card_status_text(config)
assert text.startswith("Last saved:")
assert "Unsaved changes" not in text
assert "Unsaved invalid changes" not in text
assert "Save failed" not in text
def test_save_card_status_text_for_dirty_state() -> None:
last_saved = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=145_000.0)
preview = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=150_000.0)
text = _save_card_status_text(last_saved, preview_config=preview)
assert text.startswith("Unsaved changes — Last saved:")
def test_save_card_status_text_for_invalid_state() -> None:
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=145_000.0)
text = _save_card_status_text(config, invalid=True)
assert text.startswith("Unsaved invalid changes — Last saved:")
def test_save_card_status_text_for_save_failure() -> None:
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=145_000.0)
text = _save_card_status_text(config, save_failed=True)
assert text.startswith("Save failed — Last saved:")