Files
mono/test/sx/components.sx
giles 7fda7a8027 Replace env free-variable threading with IO-primitive auto-fetch macros
Layout components now self-resolve context (cart-mini, auth-menu, nav-tree,
rights, URLs) via new IO primitives (root-header-ctx, select-colours,
account-nav-ctx, app-rights) and defmacro wrappers (~root-header-auto,
~auth-header-row-auto, ~root-mobile-auto). This eliminates _ctx_to_env(),
HELPER_CSS_CLASSES, and verbose :key threading across all 10 services.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 18:20:57 +00:00

101 lines
4.0 KiB
Plaintext

;; Test service composition defcomps — replaces Python string concatenation
;; in test/sxc/pages/__init__.py.
;; Service filter nav links
(defcomp ~test-service-nav (&key services active-service)
(<>
(~nav-link :href "/" :label "all"
:is-selected (if (not active-service) "true" nil)
:select-colours "aria-selected:bg-sky-200 aria-selected:text-sky-900")
(map (lambda (svc)
(~nav-link :href (str "/?service=" svc) :label svc
:is-selected (if (= active-service svc) "true" nil)
:select-colours "aria-selected:bg-sky-200 aria-selected:text-sky-900"))
services)))
;; Test header menu row
(defcomp ~test-header-row (&key services active-service)
(~menu-row-sx :id "test-row" :level 1 :colour "sky"
:link-href "/" :link-label "Tests" :icon "fa fa-flask"
:nav (~test-service-nav :services services :active-service active-service)
:child-id "test-header-child"))
;; Layout: full page header stack (reads root header values from env free variables)
(defcomp ~test-layout-full (&key services active-service)
(<> (~root-header-auto)
(~header-child-sx
:inner (~test-header-row :services services :active-service active-service))))
;; Map test dicts to test-row components
(defcomp ~test-rows (&key tests)
(<> (map (lambda (t)
(~test-row
:nodeid (get t "nodeid")
:outcome (get t "outcome")
:duration (str (get t "duration"))
:longrepr (or (get t "longrepr") "")))
tests)))
;; Grouped test rows with service headers
(defcomp ~test-grouped-rows (&key sections)
(<> (map (lambda (sec)
(<> (~test-service-header
:service (get sec "service")
:total (str (get sec "total"))
:passed (str (get sec "passed"))
:failed (str (get sec "failed")))
(~test-rows :tests (get sec "tests"))))
sections)))
;; Results partial: conditional rendering based on running/result state
(defcomp ~test-results-partial (&key status summary-data tests sections has-failures)
(let* ((state (get summary-data "state")))
(<>
(~test-summary
:status (get summary-data "status")
:passed (get summary-data "passed")
:failed (get summary-data "failed")
:errors (get summary-data "errors")
:skipped (get summary-data "skipped")
:total (get summary-data "total")
:duration (get summary-data "duration")
:last-run (get summary-data "last_run")
:running (get summary-data "running")
:csrf (get summary-data "csrf")
:active-filter (get summary-data "active_filter"))
(cond
((= state "running") (~test-running-indicator))
((= state "no-results") (~test-no-results))
((= state "empty-filtered") (~test-no-results))
(true (~test-results-table
:rows (~test-grouped-rows :sections sections)
:has-failures has-failures))))))
;; Wrap results in a div with optional HTMX polling
(defcomp ~test-results-wrap (&key running inner)
(div :id "test-results" :class "space-y-6 p-4"
:sx-get (when running "/results")
:sx-trigger (when running "every 2s")
:sx-swap (when running "outerHTML")
inner))
;; Test detail section wrapper
(defcomp ~test-detail-section (&key test)
(section :id "main-panel"
:class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"
(~test-detail
:nodeid (get test "nodeid")
:outcome (get test "outcome")
:duration (str (get test "duration"))
:longrepr (or (get test "longrepr") ""))))
;; Detail page header stack (reads root header values from env free variables)
(defcomp ~test-detail-layout-full (&key services test-nodeid test-label)
(<> (~root-header-auto)
(~header-child-sx
:inner (<> (~test-header-row :services services)
(~header-child-sx :id "test-header-child"
:inner (~menu-row-sx :id "test-detail-row" :level 2 :colour "sky"
:link-href (str "/test/" test-nodeid)
:link-label test-label))))))