hsx/tests/element.lisp

58 lines
2.1 KiB
Common Lisp
Raw Normal View History

2024-05-25 03:00:39 +00:00
(defpackage :piccolo-test/element
(:use :cl
:fiveam
:piccolo/element))
(in-package :piccolo-test/element)
(def-suite create-element)
(in-suite create-element)
(test create-html-element
(let* ((inner (create-element "span"
'(:class "red")
"World!"))
(outer (create-element "p"
nil
"Hello,"
inner)))
(with-accessors ((kind element-kind)
(props element-props)) inner
(is (string= kind "span"))
(is (equal props `(:class "red" :children ("World!")))))
(with-accessors ((kind element-kind)
(props element-props)) outer
(is (string= kind "p"))
(is (equal props `(:children ("Hello," ,inner)))))))
2024-05-25 10:38:54 +00:00
(test flatten-element-children
(let* ((elm (create-element "p"
nil
"a"
nil
(list "b" (list nil "c"))
(cons "d" "e")))
(children (getf (element-props elm) :children)))
(is (equal children (list "a" "b" "c" "d" "e")))))
2024-05-25 03:00:39 +00:00
(test create-component-element
(labels ((comp (&key variant children)
(create-element "p"
`(:class ,variant)
"Hello,"
children)))
(let* ((inner (create-element "span"
nil
"World!"))
(outer (create-element #'comp
'(:variant "red")
inner)))
(with-accessors ((kind element-kind)
(props element-props)) outer
(is (eql kind #'comp))
(is (equal props `(:variant "red" :children (,inner)))))
(with-accessors ((kind element-kind)
(props element-props)) (expand outer)
(is (string= kind "p"))
(is (equal props `(:class "red" :children ("Hello," ,inner))))))))