refactor(settings): separate preview validation from internal failures
This commit is contained in:
40
tests/test_settings_page.py
Normal file
40
tests/test_settings_page.py
Normal 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:")
|
||||
Reference in New Issue
Block a user