Add infrastructure test coverage: 7 new test files, ~268 tests
New test suites for previously untested infrastructure: - lib/tests/test-stdlib.sx: 47 pure functions (equality, predicates, math, collections, strings) - web/tests/test-adapter-html.sx: HTML adapter (islands, lakes, marshes, components, kwargs) - web/tests/test-adapter-dom.sx: form predicates and constants - web/tests/test-boot-helpers.sx: callable? predicate - web/tests/test-page-helpers.sx: pure data transforms (spec explorer) - web/tests/test-layout.sx: layout component patterns (kwargs, children, nesting, conditionals) - web/tests/test-tw-layout.sx: tw-resolve-layout (display, flex, gap, position, z-index, etc.) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,73 +1,122 @@
|
||||
(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")))))
|
||||
(defcomp ~tl-link (&key href label) (a :href href label))
|
||||
|
||||
(defcomp
|
||||
~tl-badge
|
||||
(&key href count)
|
||||
(a :href href (span (if count count "0"))))
|
||||
|
||||
(defcomp
|
||||
~tl-error
|
||||
(&key errnum message image)
|
||||
(div
|
||||
:class "error"
|
||||
(h1 errnum)
|
||||
(p message)
|
||||
(when image (img :src image))))
|
||||
|
||||
(defcomp ~tl-wrapper (&key class &rest children) (div :class class children))
|
||||
|
||||
(defcomp ~tl-inner (&key text) (span :class "inner" text))
|
||||
|
||||
(defcomp
|
||||
~tl-outer
|
||||
(&key label)
|
||||
(div :class "outer" (~tl-inner :text label)))
|
||||
|
||||
(defcomp
|
||||
~tl-toggle
|
||||
(&key show-extra)
|
||||
(div (p "always") (when show-extra (p "extra"))))
|
||||
|
||||
(defcomp ~tl-clear (&key id) (div :id id))
|
||||
|
||||
(defsuite
|
||||
"layout-patterns-kwargs"
|
||||
"layout-link-pattern"
|
||||
(deftest
|
||||
"component with keyword args renders correctly"
|
||||
"renders anchor with href and label"
|
||||
(let
|
||||
((html (render-to-html (quote (begin (defcomp ~test-link (&key href label) (a :href href label)) (~test-link :href "/about" :label "About"))) {})))
|
||||
((html (render-to-html (quote (~tl-link :href "/about" :label "About")) {})))
|
||||
(assert-true (string-contains? html "/about"))
|
||||
(assert-true (string-contains? html "About"))))
|
||||
(assert-true (string-contains? html "About")))))
|
||||
|
||||
(defsuite
|
||||
"layout-badge-pattern"
|
||||
(deftest
|
||||
"component with optional args"
|
||||
"renders badge with count"
|
||||
(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"))) {})))
|
||||
((html (render-to-html (quote (~tl-badge :href "/cart" :count "3")) {})))
|
||||
(assert-true (string-contains? html "3"))
|
||||
(assert-true (string-contains? html "/cart"))))
|
||||
(deftest
|
||||
"component with nil optional"
|
||||
"renders default count when nil"
|
||||
(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")))))
|
||||
((html (render-to-html (quote (~tl-badge :href "/cart")) {})))
|
||||
(assert-true (string-contains? html "0")))))
|
||||
|
||||
(defsuite
|
||||
"layout-patterns-children"
|
||||
"layout-error-pattern"
|
||||
(deftest
|
||||
"component with children"
|
||||
"renders error with number and message"
|
||||
(let
|
||||
((html (render-to-html (quote (begin (defcomp ~test-wrapper (&key class &rest children) (div :class class children)) (~test-wrapper :class "box" (p "inner")))) {})))
|
||||
((html (render-to-html (quote (~tl-error :errnum "404" :message "Not Found")) {})))
|
||||
(assert-true (string-contains? html "404"))
|
||||
(assert-true (string-contains? html "Not Found"))))
|
||||
(deftest
|
||||
"renders with image when provided"
|
||||
(let
|
||||
((html (render-to-html (quote (~tl-error :errnum "500" :message "Error" :image "/err.png")) {})))
|
||||
(assert-true (string-contains? html "500"))
|
||||
(assert-true (string-contains? html "/err.png"))))
|
||||
(deftest
|
||||
"omits image when nil"
|
||||
(let
|
||||
((html (render-to-html (quote (~tl-error :errnum "404" :message "Missing")) {})))
|
||||
(assert-false (string-contains? html "img")))))
|
||||
|
||||
(defsuite
|
||||
"layout-children-pattern"
|
||||
(deftest
|
||||
"renders children inside wrapper"
|
||||
(let
|
||||
((html (render-to-html (quote (~tl-wrapper :class "box" (p "inner"))) {})))
|
||||
(assert-true (string-contains? html "inner"))
|
||||
(assert-true (string-contains? html "box"))))
|
||||
(deftest
|
||||
"component with multiple children"
|
||||
"renders multiple children"
|
||||
(let
|
||||
((html (render-to-html (quote (begin (defcomp ~test-section (&rest children) (section children)) (~test-section (h2 "Title") (p "Body")))) {})))
|
||||
((html (render-to-html (quote (~tl-wrapper :class "section" (h2 "Title") (p "Body"))) {})))
|
||||
(assert-true (string-contains? html "Title"))
|
||||
(assert-true (string-contains? html "Body")))))
|
||||
|
||||
(defsuite
|
||||
"layout-patterns-nesting"
|
||||
"layout-nesting-pattern"
|
||||
(deftest
|
||||
"nested components"
|
||||
"nested component calls"
|
||||
(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"))) {})))
|
||||
((html (render-to-html (quote (~tl-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")))))
|
||||
(assert-true (string-contains? html "outer")))))
|
||||
|
||||
(defsuite
|
||||
"layout-patterns-conditional"
|
||||
"layout-conditional-pattern"
|
||||
(deftest
|
||||
"conditional rendering in component"
|
||||
"shows extra when true"
|
||||
(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))) {})))
|
||||
((html (render-to-html (quote (~tl-toggle :show-extra true)) {})))
|
||||
(assert-true (string-contains? html "always"))
|
||||
(assert-true (string-contains? html "extra"))))
|
||||
(deftest
|
||||
"conditional false hides content"
|
||||
"hides extra when false"
|
||||
(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")))))
|
||||
((html (render-to-html (quote (~tl-toggle :show-extra false)) {})))
|
||||
(assert-true (string-contains? html "always"))
|
||||
(assert-false (string-contains? html "extra")))))
|
||||
|
||||
(defsuite
|
||||
"layout-clear-pattern"
|
||||
(deftest
|
||||
"renders div with id"
|
||||
(let
|
||||
((html (render-to-html (quote (~tl-clear :id "sidebar")) {})))
|
||||
(assert-true (string-contains? html "sidebar")))))
|
||||
|
||||
Reference in New Issue
Block a user