41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
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:")
|