You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.3 KiB
Python

"""Tests for HTML report rendering, retention pruning, and terminal links."""
from datetime import date, timedelta
from gimme_job.proactive import html_report
def test_render_html_styles_status_and_links():
md = (
"# 2026-09-12 Orthodontist Job Report\n"
"NEW 1 / REOPENED 0\n\n"
"## NEW (1)\n"
"- Staff Dentist [AZ] — Acme\n"
" https://example.com/jobs/1\n"
"## VERIFY (1)\n"
"- Orthodontist\n"
)
page = html_report.render_html(md, "Test Report")
assert "<!doctype html>" in page
assert '<h2 class="status new">NEW (1)</h2>' in page
assert '<h2 class="status verify">VERIFY (1)</h2>' in page
assert '<a href="https://example.com/jobs/1">' in page
assert "<title>Test Report</title>" in page
def test_render_html_keeps_existing_markdown_links():
page = html_report.render_html("[apply](https://example.com/a)", "T")
assert page.count("https://example.com/a") == 1
def test_write_html_report_and_prune(monkeypatch, tmp_path):
monkeypatch.setattr(html_report, "reports_dir", lambda: tmp_path)
today = date(2026, 9, 12)
old = today - timedelta(days=31)
recent = today - timedelta(days=3)
(tmp_path / f"proactive-{old.isoformat()}.html").write_text("old")
(tmp_path / f"proactive-{old.isoformat()}.md").write_text("old")
(tmp_path / f"outreach-{old.isoformat()}.md").write_text("old")
(tmp_path / f"{old.isoformat()}.md").write_text("old") # notifier fallback
(tmp_path / f"proactive-{recent.isoformat()}.html").write_text("keep")
(tmp_path / "notes.txt").write_text("keep")
path = html_report.write_html_report("# hi", today, prefix="proactive", title="T")
assert path.name == f"proactive-{today.isoformat()}.html"
assert "hi" in path.read_text(encoding="utf-8")
removed = html_report.prune_reports(30, now=today)
assert removed == 4
assert not (tmp_path / f"proactive-{old.isoformat()}.html").exists()
assert (tmp_path / f"proactive-{recent.isoformat()}.html").exists()
assert (tmp_path / "notes.txt").exists()
assert path.exists()
def test_terminal_link_is_osc8(tmp_path):
p = tmp_path / "report.html"
link = html_report.terminal_link(p, "click me")
assert "\x1b]8;;file://" in link
assert "click me" in link
assert link.endswith("\x1b]8;;\x1b\\")