2024-05-27 07:54:46 +00:00
|
|
|
(defpackage #:hsx-test/element
|
|
|
|
(:use #:cl
|
|
|
|
#:fiveam
|
|
|
|
#:hsx/element))
|
|
|
|
(in-package #:hsx-test/element)
|
2024-05-25 03:00:39 +00:00
|
|
|
|
2024-05-28 03:33:01 +00:00
|
|
|
|
2024-05-26 03:26:09 +00:00
|
|
|
(def-suite element-test)
|
|
|
|
(in-suite element-test)
|
|
|
|
|
2024-05-28 11:48:39 +00:00
|
|
|
(test tag
|
2024-05-28 10:31:50 +00:00
|
|
|
(let ((elm (create-element :p
|
2024-05-27 07:03:23 +00:00
|
|
|
'(:class "red")
|
|
|
|
"Hello,"
|
|
|
|
"World")))
|
2024-05-28 10:31:50 +00:00
|
|
|
(is (eq (element-type elm) :p))
|
2024-05-26 03:26:09 +00:00
|
|
|
(is (equal (element-props elm) '(:class "red")))
|
|
|
|
(is (equal (element-children elm) (list "Hello," "World")))))
|
|
|
|
|
|
|
|
(test flatten-children
|
2024-05-28 10:31:50 +00:00
|
|
|
(let* ((elm (create-element :p
|
2024-05-25 10:38:54 +00:00
|
|
|
nil
|
|
|
|
"a"
|
|
|
|
nil
|
|
|
|
(list "b" (list nil "c"))
|
2024-05-25 15:57:06 +00:00
|
|
|
(cons "d" "e"))))
|
|
|
|
(is (equal (element-children elm) (list "a" "b" "c" "d" "e")))))
|
2024-05-25 10:38:54 +00:00
|
|
|
|
2024-05-26 03:26:09 +00:00
|
|
|
(defun comp1 (&key title children)
|
2024-05-28 10:31:50 +00:00
|
|
|
(create-element :div
|
2024-05-26 03:26:09 +00:00
|
|
|
nil
|
|
|
|
title
|
|
|
|
children))
|
|
|
|
|
2024-05-28 11:48:39 +00:00
|
|
|
(test component-accepting-keyword-args
|
2024-05-26 03:26:09 +00:00
|
|
|
(let* ((elm (create-element #'comp1
|
|
|
|
'(:title "foo")
|
|
|
|
"bar"))
|
2024-05-27 07:03:23 +00:00
|
|
|
(expanded (expand-component elm)))
|
2024-05-28 10:31:50 +00:00
|
|
|
(is (eq (element-type elm) #'comp1))
|
2024-05-26 03:26:09 +00:00
|
|
|
(is (equal (element-props elm) '(:title "foo")))
|
|
|
|
(is (equal (element-children elm) (list "bar")))
|
2024-05-28 10:31:50 +00:00
|
|
|
(is (eq (element-type expanded) :div))
|
2024-05-26 03:26:09 +00:00
|
|
|
(is (equal (element-children expanded) (list "foo" "bar")))
|
|
|
|
(signals error
|
|
|
|
(create-element #'comp1
|
|
|
|
'(:title "foo" :other-key "baz")
|
|
|
|
"bar"))))
|
|
|
|
|
|
|
|
(defun comp2 (&rest props)
|
2024-05-28 10:31:50 +00:00
|
|
|
(create-element :div
|
2024-05-26 03:26:09 +00:00
|
|
|
nil
|
|
|
|
(getf props :title)
|
|
|
|
(getf props :children)))
|
|
|
|
|
2024-05-28 11:48:39 +00:00
|
|
|
(test component-accepting-property-list
|
2024-05-27 07:03:23 +00:00
|
|
|
(let* ((elm (create-element #'comp2
|
2024-05-26 03:26:09 +00:00
|
|
|
'(:title "foo")
|
|
|
|
"bar"))
|
2024-05-27 07:03:23 +00:00
|
|
|
(expanded (expand-component elm)))
|
2024-05-28 10:31:50 +00:00
|
|
|
(is (eq (element-type elm) #'comp2))
|
2024-05-26 03:26:09 +00:00
|
|
|
(is (equal (element-props elm) '(:title "foo")))
|
|
|
|
(is (equal (element-children elm) (list "bar")))
|
2024-05-28 10:31:50 +00:00
|
|
|
(is (eq (element-type expanded) :div))
|
2024-05-26 03:26:09 +00:00
|
|
|
(is (equal (element-children expanded) (list "foo" "bar")))))
|
|
|
|
|
|
|
|
(defun comp3 (&rest props &key title children &allow-other-keys)
|
2024-05-28 10:31:50 +00:00
|
|
|
(create-element :div
|
2024-05-26 03:26:09 +00:00
|
|
|
nil
|
|
|
|
title
|
|
|
|
children
|
|
|
|
(getf props :other-key)))
|
|
|
|
|
|
|
|
(defun comp4 (&rest props &key title children)
|
2024-05-28 10:31:50 +00:00
|
|
|
(create-element :div
|
2024-05-26 03:26:09 +00:00
|
|
|
nil
|
|
|
|
title
|
|
|
|
children
|
|
|
|
(getf props :other-key)))
|
|
|
|
|
2024-05-28 11:48:39 +00:00
|
|
|
(test component-accepting-keyword-args-and-property-list
|
2024-05-26 03:26:09 +00:00
|
|
|
(let* ((elm (create-element #'comp3
|
|
|
|
'(:title "foo" :other-key "baz")
|
|
|
|
"bar"))
|
2024-05-27 07:03:23 +00:00
|
|
|
(expanded (expand-component elm)))
|
2024-05-28 10:31:50 +00:00
|
|
|
(is (eq (element-type elm) #'comp3))
|
2024-05-26 03:26:09 +00:00
|
|
|
(is (equal (element-props elm) '(:title "foo" :other-key "baz")))
|
|
|
|
(is (equal (element-children elm) (list "bar")))
|
2024-05-28 10:31:50 +00:00
|
|
|
(is (eq (element-type expanded) :div))
|
2024-05-26 03:26:09 +00:00
|
|
|
(is (equal (element-children expanded) (list "foo" "bar" "baz")))
|
|
|
|
(signals error
|
|
|
|
(create-element #'comp4
|
|
|
|
'(:title "foo" :other-key "baz")
|
|
|
|
"bar"))))
|