diff --git a/design-system/components/alerts.css b/design-system/components/alerts.css index 5ce223a..6b105c9 100644 --- a/design-system/components/alerts.css +++ b/design-system/components/alerts.css @@ -47,3 +47,12 @@ border-color: #f0b3af; color: var(--color-error); } + +/* "Nothing here yet" / "nothing matches" message at the top of a page or + list (the empty_state() macro in the dashboard's _macros.html). */ +.empty-state { + margin-top: var(--space-6); +} +.empty-state__action { + margin: var(--space-3) 0 0; +} diff --git a/src/secfoo/web/static/design-system/components/alerts.css b/src/secfoo/web/static/design-system/components/alerts.css index 5ce223a..6b105c9 100644 --- a/src/secfoo/web/static/design-system/components/alerts.css +++ b/src/secfoo/web/static/design-system/components/alerts.css @@ -47,3 +47,12 @@ border-color: #f0b3af; color: var(--color-error); } + +/* "Nothing here yet" / "nothing matches" message at the top of a page or + list (the empty_state() macro in the dashboard's _macros.html). */ +.empty-state { + margin-top: var(--space-6); +} +.empty-state__action { + margin: var(--space-3) 0 0; +} diff --git a/src/secfoo/web/templates/_macros.html b/src/secfoo/web/templates/_macros.html index 46688d9..e316a5b 100644 --- a/src/secfoo/web/templates/_macros.html +++ b/src/secfoo/web/templates/_macros.html @@ -13,3 +13,18 @@ {{ a.responsible_ai_status }} {%- else %}—{% endif -%} {% endmacro %} + +{#- Shared "nothing here yet" box: says what's missing and how to start. + Use for a page or list that has no data at all (not for "your filters + matched nothing" -- that should offer to clear the filters instead). -#} +{% macro empty_state(title, action_href=None, action_label=None) %} +
{{ skill.description }}
+{% if run_count == 0 %} +{% call empty_state("No " ~ skill.name ~ " runs yet", "/assessments", "Go to assessments") %} + The figures below fill in after the first run. Start one from an + assessment's Run Assessment page, or run +secfoo run --skill {{ skill.id }}.
+{% endcall %}
+{% endif %}
+
{% if dash %}
{% include "activities/architecture_dashboard.html" %}
{% endif %}
diff --git a/src/secfoo/web/templates/assessments/list.html b/src/secfoo/web/templates/assessments/list.html
index fc313ac..8e7db8f 100644
--- a/src/secfoo/web/templates/assessments/list.html
+++ b/src/secfoo/web/templates/assessments/list.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% from "_macros.html" import findings_badges, responsible_ai_badges %}
+{% from "_macros.html" import findings_badges, responsible_ai_badges, empty_state %}
{% block title %}secfoo — Assessments{% endblock %}
{% block content %}
diff --git a/tests/test_web/test_activity_routes.py b/tests/test_web/test_activity_routes.py index 6c03fa4..4ef4010 100644 --- a/tests/test_web/test_activity_routes.py +++ b/tests/test_web/test_activity_routes.py @@ -51,6 +51,23 @@ def test_activity_page_empty_state(client): assert "No project has been scanned with this activity yet" in resp.text +@pytest.mark.parametrize("skill_id", ["sast", "security-architecture-review", "threat-modeling", "prompt-review"]) +def test_activity_page_explains_why_it_is_empty_before_the_first_run(client, skill_id): + # The dashboards render all-zero charts with no data, so the top of the + # page has to say nothing has run yet, and how to start. + resp = client.get(f"/activities/{skill_id}") + assert resp.status_code == 200 + assert "runs yet" in resp.text + assert f"secfoo run --skill {skill_id}" in resp.text + + +def test_activity_page_hides_the_no_runs_message_once_it_has_run(client): + _seed_run(skill_id="sast", high=1) + resp = client.get("/activities/sast") + assert resp.status_code == 200 + assert "runs yet" not in resp.text + + def test_activity_page_shows_per_project_rollup(client): _seed_run(skill_id="sast", project_name="acme/app", high=2, medium=1) _seed_run(skill_id="sast", project_name="acme/other", high=1) diff --git a/tests/test_web/test_assessment_routes.py b/tests/test_web/test_assessment_routes.py index 55af9d7..dce43ff 100644 --- a/tests/test_web/test_assessment_routes.py +++ b/tests/test_web/test_assessment_routes.py @@ -29,9 +29,22 @@ def _create_assessment(*, assessment_type: str = "internal", status: str = "read def test_assessments_list_empty_state(client): + # No assessments at all: say so and offer to create one -- not + # "no assessments match these filters", which reads as a filter problem. resp = client.get("/assessments") assert resp.status_code == 200 - assert "No assessments match" in resp.text + assert "No assessments yet" in resp.text + assert "No assessments match" not in resp.text + assert 'href="/assessments/new"' in resp.text + + +def test_assessments_list_filters_matching_nothing_offers_to_clear_them(client): + _create_assessment(status="ready") + resp = client.get("/assessments?status=completed") + assert resp.status_code == 200 + assert "No assessments match these filters" in resp.text + assert "Clear filters" in resp.text + assert "No assessments yet" not in resp.text def test_assessments_list_shows_created_assessment(client): diff --git a/tests/test_web/test_routes.py b/tests/test_web/test_routes.py index 27c7b0e..f1e5745 100644 --- a/tests/test_web/test_routes.py +++ b/tests/test_web/test_routes.py @@ -145,3 +145,19 @@ def test_mermaid_init_js_sanitizes_agent_generated_content(): content = (STATIC_DIR / "js" / "mermaid-init.js").read_text() assert 'securityLevel: "strict"' in content + + +def test_third_party_page_explains_it_is_empty(client): + resp = client.get("/third-party") + assert resp.status_code == 200 + assert "No third-party assessments yet" in resp.text + + +def test_third_party_page_hides_the_empty_message_once_one_exists(client, tmp_path): + project_id, _run_uuid = _seed_run(tmp_path) + repo = RunRepository() + repo.create_assessment(project_id=project_id, assessment_type="third_party", status="ready") + repo.close() + resp = client.get("/third-party") + assert resp.status_code == 200 + assert "No third-party assessments yet" not in resp.text