Refine runs table state layout

This commit is contained in:
Abel Luck 2026-03-31 12:25:46 +02:00
parent db1d9b44b7
commit ba33491479
6 changed files with 241 additions and 31 deletions

View file

@ -4,7 +4,7 @@ import re
from email.utils import parsedate_to_datetime
from io import BytesIO
from lxml import etree
import lxml.etree as etree
from scrapy.http import TextResponse
from scrapy.settings import Settings

View file

@ -49,6 +49,40 @@ def test_load_runs_view_humanizes_completed_execution_summary_bytes(
assert view["completed"][0]["stats"] == "14 requests • 11 items • 15.7 MiB"
def test_load_runs_view_projects_completed_execution_duration(
tmp_path: Path,
) -> None:
initialize_database(tmp_path / "jobs-completed-duration.db")
source = create_source(
name="Completed source",
slug="completed-source",
source_type="feed",
notes="",
spider_arguments="",
enabled=False,
cron_minute="*/5",
cron_hour="*",
cron_day_of_month="*",
cron_day_of_week="*",
cron_month="*",
feed_url="https://example.com/completed.xml",
)
job = Job.get(Job.source == source)
JobExecution.create(
job=job,
running_status=JobExecutionStatus.SUCCEEDED,
started_at=datetime(2026, 3, 30, 11, 59, 12, tzinfo=UTC),
ended_at=datetime(2026, 3, 30, 12, 0, tzinfo=UTC),
)
view = load_runs_view(
log_dir=tmp_path / "out" / "logs",
now=datetime(2026, 3, 30, 12, 30, tzinfo=UTC),
)
assert view["completed"][0]["duration"] == "00:00:48"
def test_load_runs_view_humanizes_running_execution_summary_bytes(
tmp_path: Path,
) -> None:

View file

@ -145,6 +145,48 @@ def test_runs_page_renders_completed_execution_end_time_as_relative_hoverable_ti
assert ">2 hours ago<" in body
def test_runs_page_renders_completed_execution_state_cell_with_duration_and_end_time() -> (
None
):
ended_at = "2026-01-15T10:00:00+00:00"
body = str(
runs_page(
completed_executions=(
{
"source": "Completed source",
"slug": "completed-source",
"job_id": 7,
"execution_id": 42,
"ended_at": "2 hours ago",
"ended_at_iso": ended_at,
"duration": "00:00:48",
"status": "Succeeded",
"status_tone": "done",
"stats": "1 requests • 1 items • 1 bytes",
"summary": "Worker exited successfully",
"log_href": "/job/7/execution/42/logs",
},
)
)
)
assert re.search(
r"<th[^>]*>State</th>\s*<th[^>]*>Source</th>\s*<th[^>]*>Summary</th>",
body,
)
assert not re.search(
r"<th[^>]*>#</th>\s*<th[^>]*>State</th>\s*<th[^>]*>Source</th>\s*<th[^>]*>Summary</th>",
body,
)
assert ">#42<" in body
assert ">Ended<" not in body
assert ">00:00:48<" in body
assert 'data-ended-at="2026-01-15T10:00:00+00:00"' in body
assert "M12 6v6h4.5" in body
assert "M6.75 3v2.25M17.25 3v2.25" in body
assert "Succeeded" in body
def test_runs_page_renders_combined_running_jobs_table() -> None:
body = str(
runs_page(
@ -178,6 +220,40 @@ def test_runs_page_renders_combined_running_jobs_table() -> None:
assert "/actions/queued-executions/42/cancel" in body
def test_runs_page_moves_scheduled_jobs_state_column_to_second_position() -> None:
body = str(
runs_page(
upcoming_jobs=(
{
"source": "Parity source",
"slug": "parity-source",
"job_id": 7,
"next_run": "in 5 minutes",
"next_run_at": "2026-03-30T12:35:00+00:00",
"schedule": "*/5 * * * *",
"enabled_label": "Enabled",
"enabled_tone": "scheduled",
"run_disabled": False,
"run_reason": "Ready",
"toggle_label": "Disable",
"toggle_post_path": "/actions/jobs/7/toggle-enabled",
"run_post_path": "/actions/jobs/7/run-now",
"delete_post_path": "/actions/jobs/7/delete",
},
)
)
)
assert re.search(
r"<th[^>]*>Source</th>\s*<th[^>]*>State</th>\s*<th[^>]*>Next run</th>",
body,
)
assert re.search(
r"Parity source.*?>Enabled<.*?>in 5 minutes<.*?>\*/5 \* \* \* \*<",
body,
)
def test_sources_page_removes_view_runs_action_and_last_run_caption() -> None:
body = str(
sources_page(