HS generator+runtime: nth() dispatch+expect, dom-query-all SX-list passthrough, nth-of-type selector
- generate-sx-tests.py: add_action/add_assertion accept .nth(N) in PW-body
tests so 'find(sel).nth(1).dispatchEvent(...)' lands as a dispatch on
the Nth matching element, and assertions target that same element.
- shared/static/wasm/sx/dom.sx: dom-query-all hands through an already-SX
list unchanged — the bridge often pre-converts NodeLists/arrays to SX
lists, so the host-get 'length' / host-call 'item' loop was returning
empty. Guards node-list=nil and non-list types too.
- tests/hs-run-filtered.js (mock DOM): fnd() understands
':nth-of-type(N)', ':first-of-type', ':last-of-type' by matching the
stripped base selector and returning the correct-indexed sibling.
Covers upstream tests that write 'find("div:nth-of-type(2)")' to
pick the HS-owning element.
- Runtime runtime.sx: hs-sorted-by, hs-fetch format normalizer (JSON/
Object/etc.), nil-safe hs-joined-by/hs-split-by, emit-fetch chain sets
the-result when wrapped in let((it …)).
Net: take 0→6, hide 11→12, show 15→16, fetch 11→15,
collectionExpressions 13→15 (remaining are a WASM JIT bug on
{…} literals inside arrays).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1309,7 +1309,10 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) ".divs") 1) "click" nil)
|
||||
(assert (not (dom-has-class? (dom-query ".divs") "foo")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) ".divs") 1) "foo"))
|
||||
(assert (not (dom-has-class? (nth (dom-query-all (dom-body) ".divs") 2) "foo")))
|
||||
))
|
||||
(deftest "can target another div"
|
||||
(hs-cleanup!)
|
||||
@@ -10816,6 +10819,7 @@
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch (dom-query ".divs") "click" nil)
|
||||
(assert= (dom-text-content (dom-query ".divs")) "foo")
|
||||
(assert= (dom-text-content (nth (dom-query-all (dom-body) ".divs") 1)) "foo")
|
||||
))
|
||||
(deftest "can set into id ref"
|
||||
(hs-cleanup!)
|
||||
@@ -11035,6 +11039,7 @@
|
||||
(hs-activate! _el-trigger)
|
||||
(dom-dispatch (dom-query-by-id "trigger") "click" nil)
|
||||
(assert (dom-has-class? (dom-query ".item") "done"))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) ".item") 1) "done"))
|
||||
))
|
||||
(deftest "can settle me no transition"
|
||||
(hs-cleanup!)
|
||||
@@ -11467,8 +11472,12 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (dom-has-class? _el-div "unselected"))
|
||||
(assert (not (dom-has-class? _el-div "\bselected\b")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "\bselected\b"))
|
||||
(assert (not (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "unselected")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 2) "unselected"))
|
||||
))
|
||||
(deftest "can take a class and swap it with another via with"
|
||||
(hs-cleanup!)
|
||||
@@ -11482,8 +11491,12 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-class? _el-div "\bselected\b")))
|
||||
(assert (dom-has-class? _el-div "unselected"))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "\bselected\b"))
|
||||
(assert (not (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "unselected")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 2) "unselected"))
|
||||
))
|
||||
(deftest "can take a class for other elements"
|
||||
(hs-cleanup!)
|
||||
@@ -11498,7 +11511,9 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-d3)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-class? _el-div "foo")))
|
||||
(assert (not (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "foo")))
|
||||
(assert (dom-has-class? (dom-query-by-id "d3") "foo"))
|
||||
))
|
||||
(deftest "can take a class from other elements"
|
||||
@@ -11513,7 +11528,10 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-class? _el-div "foo")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "foo"))
|
||||
(assert (not (dom-has-class? (nth (dom-query-all (dom-body) "div") 2) "foo")))
|
||||
))
|
||||
(deftest "can take a class from other forms"
|
||||
(hs-cleanup!)
|
||||
@@ -11527,7 +11545,10 @@
|
||||
(dom-append (dom-body) _el-form1)
|
||||
(dom-append (dom-body) _el-form2)
|
||||
(hs-activate! _el-form1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "form") 1) "click" nil)
|
||||
(assert (not (dom-has-class? _el-form "foo")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "form") 1) "foo"))
|
||||
(assert (not (dom-has-class? (nth (dom-query-all (dom-body) "form") 2) "foo")))
|
||||
))
|
||||
(deftest "can take an attribute for other elements"
|
||||
(hs-cleanup!)
|
||||
@@ -11542,7 +11563,9 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-d3)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-attr? _el-div "data-foo")))
|
||||
(assert (not (dom-has-attr? (nth (dom-query-all (dom-body) "div") 1) "data-foo")))
|
||||
(assert= (dom-get-attr (dom-query-by-id "d3") "data-foo") "")
|
||||
))
|
||||
(deftest "can take an attribute from other elements"
|
||||
@@ -11558,7 +11581,10 @@
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(assert= (dom-get-attr _el-div "data-foo") "bar")
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-attr? _el-div "data-foo")))
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 1) "data-foo") "")
|
||||
(assert (not (dom-has-attr? (nth (dom-query-all (dom-body) "div") 2) "data-foo")))
|
||||
))
|
||||
(deftest "can take an attribute value from other elements and set specific values instead"
|
||||
(hs-cleanup!)
|
||||
@@ -11572,7 +11598,10 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert= (dom-get-attr _el-div "data-foo") "qux")
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 1) "data-foo") "baz")
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 2) "data-foo") "qux")
|
||||
))
|
||||
(deftest "can take an attribute value from other elements and set value from an expression instead"
|
||||
(hs-cleanup!)
|
||||
@@ -11587,7 +11616,10 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert= (dom-get-attr _el-div "data-foo") "qux")
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 1) "data-foo") "baz")
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 2) "data-foo") "qux")
|
||||
))
|
||||
(deftest "can take an attribute with specific value from other elements"
|
||||
(hs-cleanup!)
|
||||
@@ -11602,7 +11634,10 @@
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(assert= (dom-get-attr _el-div "data-foo") "bar")
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-attr? _el-div "data-foo")))
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 1) "data-foo") "baz")
|
||||
(assert (not (dom-has-attr? (nth (dom-query-all (dom-body) "div") 2) "data-foo")))
|
||||
))
|
||||
(deftest "can take multiple classes from other elements"
|
||||
(hs-cleanup!)
|
||||
@@ -11617,7 +11652,11 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-class? _el-div "foo")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "foo"))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "bar"))
|
||||
(assert (not (dom-has-class? (nth (dom-query-all (dom-body) "div") 2) "bar")))
|
||||
))
|
||||
(deftest "can take multiple classes from specific element"
|
||||
(hs-cleanup!)
|
||||
@@ -11633,8 +11672,12 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert (not (dom-has-class? _el-div "foo")))
|
||||
(assert (not (dom-has-class? _el-div "bar")))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "foo"))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 1) "bar"))
|
||||
(assert (dom-has-class? (nth (dom-query-all (dom-body) "div") 2) "bar"))
|
||||
))
|
||||
(deftest "giving may follow the from clause as an alternative to with"
|
||||
(hs-cleanup!)
|
||||
@@ -11648,7 +11691,10 @@
|
||||
(dom-append (dom-body) _el-div1)
|
||||
(dom-append (dom-body) _el-div2)
|
||||
(hs-activate! _el-div1)
|
||||
(dom-dispatch (nth (dom-query-all (dom-body) "div") 1) "click" nil)
|
||||
(assert= (dom-get-attr _el-div "data-foo") "qux")
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 1) "data-foo") "baz")
|
||||
(assert= (dom-get-attr (nth (dom-query-all (dom-body) "div") 2) "data-foo") "qux")
|
||||
))
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user