Files
vault-dash/tests/test_settings_page.py

58 lines
2.0 KiB
Python

from __future__ import annotations
from app.models.portfolio import PortfolioConfig
from app.pages.settings import _save_card_status_text
def test_portfolio_config_underlying_defaults_to_gld() -> None:
"""Verify PortfolioConfig underlying field defaults to GLD."""
config = PortfolioConfig(gold_value=215_000.0, entry_price=215.0, loan_amount=145_000.0)
assert config.underlying == "GLD"
def test_portfolio_config_underlying_can_be_set_to_gc_f() -> None:
"""Verify PortfolioConfig underlying can be set to GC=F."""
config = PortfolioConfig(
gold_value=215_000.0,
entry_price=215.0,
loan_amount=145_000.0,
underlying="GC=F",
)
assert config.underlying == "GC=F"
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:")