OffGridSchedula / tests /test_ui.py
ParetoOptimal's picture
Initial Commit
0366d65
Raw
History Blame Contribute Delete
1.9 kB
import pandas as pd
import pytest
from server import impact
from ui.blocks import (
_count_conflicts,
_load_sample,
_on_analyze,
_on_make_ics,
_refresh,
build_demo,
)
@pytest.fixture(autouse=True)
def _clean_impact():
impact.reset()
yield
impact.reset()
def test_build_demo_constructs():
demo = build_demo()
assert demo.__class__.__name__ == "Blocks"
def test_analyze_generator_shape_and_export():
last = None
for out in _on_analyze("Mom: dinner Sunday 6pm", None, None):
assert len(out) == 5 # thinking, table, plan_md, reply, status
last = out
_, rows, _, reply, _ = last
assert rows and rows[0][0]
assert reply
path, msg = _on_make_ics(rows)
assert path and "Wrote" in msg
def test_export_records_capture():
*_, last = list(_on_analyze("Mom: dinner Sunday 6pm", None, None))
rows = last[1]
before = impact.this_week()["events_captured"]
_on_make_ics(rows)
assert impact.this_week()["events_captured"] == before + len(rows)
def test_count_conflicts_reads_markdown():
md = "**Conflicts:**\n- ⚠️ event #0 **overlap** vs Dentist\n- ⚠️ event #1 **tight** vs Standup"
assert _count_conflicts(md) == 2
assert _count_conflicts("_No conflicts or clarifications._") == 0
def test_sample_button_yields_events():
thread = _load_sample()
assert thread and isinstance(thread, str)
*_, last = list(_on_analyze(thread, None, None))
rows = last[1]
assert rows and rows[0][0] # the sample produces at least one event in stub mode
def test_refresh_returns_chart_and_impact():
out = _refresh()
assert len(out) == 6
assert isinstance(out[3], pd.DataFrame)
assert list(out[3].columns) == ["stage", "count"]
assert "captured" in out[5] # the This-week impact panel HTML