61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
from pathlib import Path
|
|
import sys
|
|
|
|
from streamlit.testing.v1 import AppTest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
from dashboard.app import get_transfer_review_items
|
|
from scripts.ci_fixture_db import create_ci_fixture_db
|
|
|
|
|
|
def test_get_transfer_review_items_accepts_transactions_key():
|
|
payload = {
|
|
"success": True,
|
|
"transactions": [
|
|
{"id": "tx_1", "amount": 10000},
|
|
],
|
|
}
|
|
|
|
assert get_transfer_review_items(payload) == payload["transactions"]
|
|
|
|
|
|
def test_get_transfer_review_items_prefers_review_items_when_present():
|
|
payload = {
|
|
"success": True,
|
|
"review_items": [
|
|
{"id": "tx_legacy", "amount": 20000},
|
|
],
|
|
"transactions": [
|
|
{"id": "tx_new", "amount": 30000},
|
|
],
|
|
}
|
|
|
|
assert get_transfer_review_items(payload) == payload["review_items"]
|
|
|
|
|
|
def test_get_transfer_review_items_returns_empty_for_unsuccessful_payload():
|
|
assert get_transfer_review_items({"success": False, "transactions": [{"id": "tx_1"}]}) == []
|
|
assert get_transfer_review_items(None) == []
|
|
|
|
|
|
def test_streamlit_apptest_core_pages_use_synthetic_fixture_db(tmp_path, monkeypatch):
|
|
fixture = tmp_path / "fixture.sqlite3"
|
|
create_ci_fixture_db(fixture)
|
|
monkeypatch.setenv("JARCA_LEDGER_DB_PATH", str(fixture))
|
|
|
|
app_path = Path(__file__).resolve().parents[1] / "dashboard" / "app.py"
|
|
page_expectations = {
|
|
"요약": "가계부 운영 대시보드",
|
|
"자산/마감": "월말 스냅샷 Preview / Close",
|
|
"분류 규칙": "분류 규칙",
|
|
"확인필요 큐": "KB↔토스뱅크 확인필요 큐",
|
|
}
|
|
for page, expected_text in page_expectations.items():
|
|
at = AppTest.from_file(str(app_path), default_timeout=10)
|
|
at.query_params["page"] = page
|
|
at.run()
|
|
assert not at.exception
|
|
body_text = "\n".join(str(item.value) for item in list(at.text) + list(at.markdown) + list(at.caption))
|
|
assert expected_text in body_text
|