;; AUTO-GENERATED from spec/tests/hyperscript-upstream-tests.json
;; DO NOT EDIT — regenerate with:
;;   python3 tests/playwright/generate-sx-tests.py --emit-pages

(defcomp ()
  (~docs/page :title "Hyperscript: append (13 tests — 12 runnable)"
    (p :style "color:#57534e;margin-bottom:1rem" "Live cards for the upstream append tests. 12 of 13 are reproducible in-browser; the remainder show their source for reference.")
    (p :style "color:#78716c;font-size:0.875rem;margin-bottom:1rem"
      "Theme: " (a :href "/sx/(applications.(hyperscript.gallery-dom))"
        :style "color:#7c3aed" "dom"))
    (div :style "display:flex;flex-direction:column"
      (~hyperscript/hs-test-card
  :name "can append a string to another string"
  :html "<div _=\"on click
                            set value to 'Hello there.' then
                            append ' General Kenobi.' to value then
                            set my.innerHTML to value\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"Hello there. General Kenobi.\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click  set value to 'Hello there.' then append ' General Kenobi.' to value then set my.innerHTML to value\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"Hello there. General Kenobi.\")
  ))")
(~hyperscript/hs-test-card
  :name "can append a value into an array"
  :html "<div _=\"on click
                            set value to [1,2,3]
                            append 4 to value
                            set my.innerHTML to value as String\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"1,2,3,4\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click  set value to [1,2,3] then append 4 to value then set my.innerHTML to value as String\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"1,2,3,4\")
  ))")
(~hyperscript/hs-test-card
  :name "can append a value to 'it'"
  :html "<div _=\"on click
                            set result to [1,2,3]
                            append 4
                            put it as String into me\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"1,2,3,4\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click  set result to [1,2,3] then append 4 then put it as String into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"1,2,3,4\")
  ))")
(~hyperscript/hs-test-card
  :name "can append a value to a DOM node"
  :html "<div _=\"on click
                            append '<span>This is my inner HTML</span>' to me
                            append '<b>With Tags</b>' to me\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"<span>This is my inner HTML</span><b>With Tags</b>\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click  append '<span>This is my inner HTML</span>' to me then append '<b>With Tags</b>' to me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"<span>This is my inner HTML</span><b>With Tags</b>\")
  ))")
(~hyperscript/hs-test-card
  :name "can append a value to a DOM element"
  :html "<div id=\"content\" _=\"on click
                            append 'Content' to #content\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"Content\")"
  :run-src "(fn (sandbox)
  (let ((_el-content (dom-create-element \"div\")))
    (dom-set-attr _el-content \"id\" \"content\")
    (dom-set-attr _el-content \"_\" \"on click  append 'Content' to #content\")
    (dom-append sandbox _el-content)
    (hs-activate! _el-content)
    (dom-dispatch _el-content \"click\" nil)
    (assert= (dom-inner-html _el-content) \"Content\")
  ))")
(~hyperscript/hs-test-card
  :name "can append a value to I"
  :html "<div _=\"on click 
                            append 'Content' to I\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"Content\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click  append 'Content' to I\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"Content\")
  ))")
(~hyperscript/hs-test-card
  :name "can append a value to an object property"
  :html "<div id=\"id\" _=\"on click append '_new' to my id\"></div>"
  :action "div.click()"
  :check "div.id.should.equal(\"id_new\")"
  :run-src "(fn (sandbox)
  (let ((_el-id (dom-create-element \"div\")))
    (dom-set-attr _el-id \"id\" \"id\")
    (dom-set-attr _el-id \"_\" \"on click append '_new' to my id\")
    (dom-append sandbox _el-id)
    (hs-activate! _el-id)
    (dom-dispatch _el-id \"click\" nil)
    ;; SKIP check: skip div.id.should.equal(\"id_new\")
  ))")
(~hyperscript/hs-test-card
  :name "multiple appends work"
  :html "<div id=\"id\" _=\"on click get 'foo' then append 'bar' then append 'doh' then append it to me\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"foobardoh\")"
  :run-src "(fn (sandbox)
  (let ((_el-id (dom-create-element \"div\")))
    (dom-set-attr _el-id \"id\" \"id\")
    (dom-set-attr _el-id \"_\" \"on click get 'foo' then append 'bar' then append 'doh' then append it to me\")
    (dom-append sandbox _el-id)
    (hs-activate! _el-id)
    (dom-dispatch _el-id \"click\" nil)
    (assert= (dom-inner-html _el-id) \"foobardoh\")
  ))")
(~hyperscript/hs-test-card
  :name "append to undefined ignores the undefined"
  :html "<div id=\"id\" _=\"on click append 'bar' then append it to me\"></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-id (dom-create-element \"div\")))
    (dom-set-attr _el-id \"id\" \"id\")
    (dom-set-attr _el-id \"_\" \"on click append 'bar' then append it to me\")
    (dom-append sandbox _el-id)
    (hs-activate! _el-id)
    (dom-dispatch _el-id \"click\" nil)
    (assert= (dom-inner-html _el-id) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "append preserves existing content rather than overwriting it"
  :html "<div _=\"on click append '<a>New Content</a>' to me\"><button id=\"btn1\">Click Me</button></div>"
  :action "btn.click(); div.click(); btn.click()"
  :check "clicks.should.equal(1) && div.innerHTML.should.contain(\"New Content\") && btn.parentNode.should.equal(div)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-btn1 (dom-create-element \"button\")))
    (dom-set-attr _el-div \"_\" \"on click append '<a>New Content</a>' to me\")
    (dom-set-attr _el-btn1 \"id\" \"btn1\")
    (dom-set-inner-html _el-btn1 \"Click Me\")
    (dom-append sandbox _el-div)
    (dom-append _el-div _el-btn1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip clicks.should.equal(1)
    ;; SKIP check: skip div.innerHTML.should.contain(\"New Content\")
    ;; SKIP check: skip btn.parentNode.should.equal(div)
  ))")
(~hyperscript/hs-test-card
  :name "new content added by append will be live"
  :html "<div _=\"on click append \\`<button id='b1' _='on click increment window.temp'>Test</button>\\` to me\"></div>"
  :action "div.click(); btn.click()"
  :check "window.temp.should.equal(1)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click append `<button id='b1' _='on click increment window.temp'>Test</button>` to me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip window.temp.should.equal(1)
  ))")
(~hyperscript/hs-test-card
  :name "new DOM content added by append will be live"
  :html "<div _=\"on click make a <span.topping/> then append it to me\"></div>"
  :action "div.click()"
  :check "span.classList.contains(\"topping\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click make a <span.topping/> then append it to me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"topping\"))
  ))")
(~hyperscript/hs-test-card
  :name "can append a value to a set"
  :html "<div _=\"on click
		                      set :s to [1,2] as Set
		                      append 3 to :s
		                      append 1 to :s
		                      put :s.size into me\"></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"3\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))"))))
