(defsuite "layout-error-content" (deftest "renders error number and message" (let ((html (render-to-html (quote (begin (defcomp ~test-error (&key errnum message) (div :class "error" (h1 errnum) (p message))) (~test-error :errnum "404" :message "Not Found"))) {}))) (assert-true (string-contains? html "404")) (assert-true (string-contains? html "Not Found"))))) (defsuite "layout-patterns-kwargs" (deftest "component with keyword args renders correctly" (let ((html (render-to-html (quote (begin (defcomp ~test-link (&key href label) (a :href href label)) (~test-link :href "/about" :label "About"))) {}))) (assert-true (string-contains? html "/about")) (assert-true (string-contains? html "About")))) (deftest "component with optional args" (let ((html (render-to-html (quote (begin (defcomp ~test-badge (&key href count) (a :href href (span (if count count "0")))) (~test-badge :href "/cart" :count "3"))) {}))) (assert-true (string-contains? html "3")) (assert-true (string-contains? html "/cart")))) (deftest "component with nil optional" (let ((html (render-to-html (quote (begin (defcomp ~test-opt (&key title subtitle) (div (h2 title) (when subtitle (p subtitle)))) (~test-opt :title "Hello"))) {}))) (assert-true (string-contains? html "Hello"))))) (defsuite "layout-patterns-children" (deftest "component with children" (let ((html (render-to-html (quote (begin (defcomp ~test-wrapper (&key class &rest children) (div :class class children)) (~test-wrapper :class "box" (p "inner")))) {}))) (assert-true (string-contains? html "inner")) (assert-true (string-contains? html "box")))) (deftest "component with multiple children" (let ((html (render-to-html (quote (begin (defcomp ~test-section (&rest children) (section children)) (~test-section (h2 "Title") (p "Body")))) {}))) (assert-true (string-contains? html "Title")) (assert-true (string-contains? html "Body"))))) (defsuite "layout-patterns-nesting" (deftest "nested components" (let ((html (render-to-html (quote (begin (defcomp ~test-inner (&key text) (span :class "inner" text)) (defcomp ~test-outer (&key label) (div :class "outer" (~test-inner :text label))) (~test-outer :label "nested"))) {}))) (assert-true (string-contains? html "nested")) (assert-true (string-contains? html "inner")) (assert-true (string-contains? html "outer")))) (deftest "component calling component with children" (let ((html (render-to-html (quote (begin (defcomp ~test-box (&rest children) (div :class "box" children)) (defcomp ~test-page (&key title) (~test-box (h1 title))) (~test-page :title "Page"))) {}))) (assert-true (string-contains? html "Page")) (assert-true (string-contains? html "box"))))) (defsuite "layout-patterns-conditional" (deftest "conditional rendering in component" (let ((html (render-to-html (quote (begin (defcomp ~test-cond (&key show-extra) (div (p "always") (when show-extra (p "extra")))) (~test-cond :show-extra true))) {}))) (assert-true (string-contains? html "always")) (assert-true (string-contains? html "extra")))) (deftest "conditional false hides content" (let ((html (render-to-html (quote (begin (defcomp ~test-hide (&key show) (div (when show (p "hidden")))) (~test-hide :show false))) {}))) (assert-false (string-contains? html "hidden")))))