m2geval / html /fixi_block_bench.jsonl
Tswatery's picture
Add files using upload-large-folder tool
93236ab verified
{"repo_name": "fixi", "file_name": "/fixi/test.html", "inference_info": {"prefix_code": "<html lang=\"en\">\n<head>\n <title>fixi test suite</title>\n <script>\n let tests = [];\n let currentTest = null;\n let passed = 0;\n let failed = 0;\n let find = (selector) => currentTest.testElt.querySelector(selector);\n function fetchMock(action, init){\n if (init.signal && init.signal.aborted) {\n throw new DOMException(\"Aborted\", \"AbortError\");\n }\n for (let mock of currentTest.mocks) {\n if (mock.path === action || (mock.path.test && mock.path.test(action))) {\n if (typeof mock.response === 'string' || mock.response instanceof String) {\n return Promise.resolve({text : () => Promise.resolve(mock.response)});\n } else {\n return Promise.resolve({text: () => Promise.resolve(mock.response(action, init))})\n }\n }\n }\n throw `Unknown path: ${action}`;\n }\n document.addEventListener(\"fx:config\", (evt)=>{\n if (!evt.target.hasAttribute(\"use-real-fetch\")){\n evt.detail.cfg.fetch = fetchMock\n }\n })\n function test(code){\n let currentScript = document.currentScript;\n let testElt = currentScript.closest('div');\n tests.push(async ()=>{\n currentTest.testElt = testElt;\n try {\n await code();\n testElt.classList.add(\"passed\");\n testElt.insertAdjacentHTML('beforeend', `<p>Passed</p>`)\n passed++;\n document.querySelector(\".passed-info\").querySelector(\"output\").innerText = passed.toString();\n } catch (e) {\n testElt.classList.add(\"failed\");\n testElt.insertAdjacentHTML('beforeend', `<p>ERROR: ${e}</p>`)\n failed++;\n document.querySelector(\".failed-info\").querySelector(\"output\").innerText = failed.toString();\n } finally {\n currentTest = null;\n }\n })\n }\n function mock(path, response) {\n currentTest.mocks ||= []\n currentTest.mocks.push({path, response})\n }\n function sleep(ms) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n })\n }\n function assertEq(actual, expected, trim) {\n if (expected !== (trim ? actual?.trim() : actual)) {\n console.error(\"Expected\", expected, \"found\", actual);\n throw `Expected ${expected} found ${actual}`\n }\n }\n function logEvt(evt) {\n console.log(evt.type, evt.target, evt.detail?.cfg || \"\", evt.detail)\n }\n document.addEventListener(\"fx:init\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:process\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:config\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:before\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:after\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:error\", (evt) => console.error(evt.detail.error, evt.target, evt.detail?.cfg || \"\", evt.detail))\n document.addEventListener(\"fx:swapped\", (evt) => logEvt(evt))\n document.addEventListener('DOMContentLoaded', async () => {\n for (let i = 0; i < document.querySelectorAll(\".test\").length; i++){\n const testBlock = document.querySelectorAll(\".test\")[i];\n testBlock.querySelector(\"h3\").insertAdjacentHTML(\"beforeend\", ` - <a id='test${i}' href=\"test.html?test${i}\">run</a>`)\n let scriptElt = testBlock.querySelector(\"script\");\n scriptElt.insertAdjacentHTML(\"beforebegin\", `<b>Code:</b><pre></pre>`)\n scriptElt.previousElementSibling.innerText = scriptElt.innerText.replaceAll(/^ {8}/gm, '') + \"\\n\";\n if (location.search.indexOf(\"?test\") === 0) {\n let index = parseInt(location.search.substring(5));\n if (index !== i) {\n testBlock.setAttribute(\"fx-ignore\", 'true');\n } else {\n testBlock.scrollIntoView()\n }\n }\n }\n // let fixi initialize, then run tests in sequence\n setTimeout(async ()=>{\n for (let i = 0; i < tests.length; i++){\n if (location.search.indexOf(\"?test\") === 0) {\n let index = parseInt(location.search.substring(5));\n if (index !== i) {\n continue;\n }\n }\n currentTest = tests[i];\n await currentTest();\n }\n })\n });\n\n </script>\n <script src=\"fixi.js\"></script>\n <style>\n .test {\n padding: 8px;\n margin: 8px;\n }\n .passed {\n border: 3px solid green;\n }\n .failed {\n border: 3px solid red;\n }\n .passed-info {\n color: green;\n }\n .failed-info {\n color: red;\n }\n pre {\n padding: 4px;\n margin: 12px;\n border: 1px solid rgb(128, 128, 128);\n background-color: whitesmoke;\n }\n body.hide-passed .passed {\n display: none;\n }\n </style>\n</head>\n<body>\n\n<header>\n <h1>&#x1F6B2; fixi test suite</h1>\n <div>\n <div class=\"passed-info\">Passed: <output></output></div>\n <div class=\"failed-info\">Failed: <output></output></div>\n <a href=\"javascript:document.body.classList.toggle('hide-passed')\">Toggle Passed</a><br/>\n <a href=\"test.html\">Run All</a>\n </div>\n</header>\n\n<main>\n <section id=\"core\">\n <h2>Core</h2>\n <div class=\"test\">\n <h3>Test basic button works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button works when added dynamically</h3>\n <script>\n test(async ()=>{\n currentTest.testElt.insertAdjacentHTML('beforeEnd', `<button fx-action=\"/demo\">Button 1</button>`)\n await sleep(50);\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n </div>\n\n <div class=\"test\">\n <h3>Test basic target works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-target=\"#output1\">\n Button 1\n </button>\n <output id=\"output1\">\n Bar\n </output>\n </div>\n\n <div class=\"test\">\n <h3>Test basic target works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"afterend\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with inner swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with none swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"none\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with beforebegin swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.previousElementSibling?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"beforebegin\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test added content is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<button fx-action='/demo2'>Button 2</button>\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test added content with text around it is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"content <button fx-action='/demo2'>Button 2</button> content\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test nested added content is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<p><button fx-action='/demo2'>Button 2</button></p>\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n ", "suffix_code": "\n\n <div class=\"test\">\n <h3>Test double-click works when drop disabled</h3>\n <script>\n test(async ()=>{\n find('button').addEventListener(\"fx:config\", (evt)=> evt.detail.cfg.drop = false) // don't drop any reqs\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo2\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based throttling works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n if (evt.detail.requests.size > 0) {\n evt.preventDefault();\n }\n })\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based throttling w/delay works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n if (evt.detail.requests.length > 0) {\n evt.preventDefault();\n }\n })\n find('button').click();\n await sleep(50);\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo2\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based aborting works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.detail.cfg.abort();\n evt.detail.cfg.confirm = async() => {\n await sleep(1)\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based disabling works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.target.disabled = true;\n })\n find(\"button\").addEventListener(\"fx:finally\", (evt)=>{\n evt.target.disabled = true;\n })\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic form works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('form').requestSubmit();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <form id=\"f1\" fx-action=\"/demo\" fx-method=\"get\">\n Form1\n </form>\n </div>\n\n <div class=\"test\">\n <h3>Test confirm can disable</h3>\n <script>\n test(async ()=>{\n let allow = false;\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n evt.detail.cfg.confirm = ()=>allow\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n allow = true;\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test confirm-based debouncing works as expected</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n let latestPromise = null;\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n evt.detail.cfg.confirm = ()=>{\n let currentPromise = latestPromise = new Promise((resolve)=>{\n setTimeout(()=>resolve(currentPromise === latestPromise), 200)\n })\n return currentPromise\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n await sleep(200);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test can disable transitions</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.detail.cfg.transition = false\n })\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Moving a node does not reinitialize it</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n let requests = 0;\n find(\"button\").addEventListener(\"fx:before\", ()=>{\n requests++\n })\n let btn = find('button')\n // move button to the end of the div\n btn.parentElement.insertBefore(btn, null)\n await sleep(50);\n btn.click();\n await sleep(50);\n assertEq(requests, 1);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n <p>A Paragraph</p>\n </div>\n\n <div class=\"test\">\n <h3>Lazy loading works as expected using fx:inited</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div><p fx-action=\"/demo2\" fx-trigger=\"fx:inited\">Foo</p></div>`);\n mock(\"/demo2\", `Bar`);\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(btn.innerText, \"Bar\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>GET url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>GET url encodes parameters and appends when existing params</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?baz=bloop&foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo?baz=bloop\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>DELETE url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"delete\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>POST does not url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL, body = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n body = evt.detail.cfg.body;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo\");\n assertEq(body.has('foo'), true);\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"post\">\n Button 1\n </button>\n </form>\n </div>\n\n </section>\n\n <section id=\"web-components\">\n <script>\n class TestWebComponent extends HTMLElement {\n connectedCallback() {\n console.log(this.innerHTML)\n this.innerHTML = this.getAttribute('data-inner-html');\n console.log(this.innerHTML)\n }\n }\n customElements.define('test-web-component', TestWebComponent)\n </script>\n <h2>Web Components</h2>\n\n <div class=\"test\">\n <h3>Works inside web components</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div>Foo</div>`);\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(btn.innerText, \"Foo\", true);\n })\n </script>\n <test-web-component data-inner-html=\"<button fx-action='/demo' fx-swap='innerHTML'>Demo</button>\">\n </test-web-component>\n </div>\n\n <div class=\"test\">\n <h3>Works directly on web components</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div>Foo</div>`);\n let component = find('test-web-component')\n component.click();\n await sleep(50);\n assertEq(component.innerText, \"Foo\", true);\n })\n </script>\n <test-web-component fx-action='/demo' fx-swap='innerHTML' data-inner-html=\"Foo\">\n </test-web-component>\n </div>\n\n <div class=\"test\">\n <h3>Test button input works</h3>\n <script>\n\t\t\t\t\t\t\ttest(async ()=>{\n\t\t\t\t\t\t\t\tmock(\"/demo\", \"<div>Foo</div>\");\n\t\t\t\t\t\t\t\tfind('input').click();\n\t\t\t\t\t\t\t\tawait sleep(50);\n\t\t\t\t\t\t\t\tassertEq(find('div')?.innerText, \"Foo\");\n\t\t\t\t\t\t\t})\n </script>\n <input type=\"button\" fx-action=\"/demo\" value=\"Button 1\">\n </div>\n\n <div class=\"test\">\n <h3>Test can swap classes</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`foo`);\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.className, \"foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"className\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test can use real fetch()</h3>\n <script>\n test(async ()=>{\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.innerText, \"foo\", true);\n })\n </script>\n <button fx-action=\"data:text/plain,foo\" fx-swap=\"innerHTML\" use-real-fetch>\n Button 1\n </button>\n </div>\n\n\n </section>\n\n <section id=\"events\">\n <h2>Events</h2>\n\n <div class=\"test\">\n <h3>Test basic fx:before triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:config', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test trigger event is cancelled when config halts</h3>\n <script>\n test(async ()=>{\n let defaultPrevented = false;\n mock(\"/demo\", \"<div>Foo</div>\");\n currentTest.testElt.addEventListener(\"click\", (evt)=>{\n defaultPrevented = evt.defaultPrevented;\n })\n find('button').addEventListener('fx:config', (evt) => {\n evt.preventDefault()\n })\n find('button').click();\n await sleep(50);\n assertEq(defaultPrevented, true);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:before triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:before', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:after triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:after', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:finally triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:finally', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test fx:before can cancel request</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:before', (evt) => {\n triggered = true;\n console.log(evt);\n evt.preventDefault();\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div'), null);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test evt.detail.cfg.swap can be a function</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let swapped = false;\n find('button').addEventListener('fx:before', (evt) => {\n evt.detail.cfg.swap = ()=>{\n swapped = true;\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(swapped, true);\n assertEq(find('div'), null);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:inited triggered</h3>\n <script>\n test(async ()=>{\n assertEq(find('button').classList.contains(\"fx-inited\"), true);\n assertEq(find('button').parentElement.classList.contains(\"fx-inited\"), false);\n })\n </script>\n <button fx-action=\"/demo\" fx-trigger=\"fx:inited\">\n Button 1\n </button>\n <script>\n let button = document.currentScript.previousElementSibling\n button.addEventListener(\"fx:before\", (evt)=>{\n evt.preventDefault(); // don't make the request\n })\n button.addEventListener(\"fx:inited\", ()=>{\n button.classList.add(\"fx-inited\")\n })\n button.parentElement.addEventListener(\"fx:inited\", ()=>{\n button.classList.add(\"fx-inited\")\n })\n </script>\n </div>\n\n <div class=\"test\">\n <h3>Test fx:swapped is triggered on doc even if element replaces itself</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let swapped = false;\n let evtListener = (e)=>{\n\t\t\t\t\t\t\t\t\tconsole.log('here!', e)\n\t\t\t\t swapped = true;\n }\n\t\t\t\tdocument.addEventListener(\"fx:swapped\", evtListener)\n find('button').click();\n await sleep(10);\n document.removeEventListener(\"fx:swapped\", evtListener)\n assertEq(swapped, true);\n })\n </script>\n <div id=\"parent-div\">\n <button fx-action=\"/demo\" fx-target=\"#parent-div\">\n Button 1\n </button>\n </div>\n </div>\n\n </section>\n\n</main>\n\n</body>\n</html>\n", "middle_code": "<div class=\"test\">\n <h3>Test double-click works when drop disabled</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>", "code_description": null, "fill_type": "BLOCK_TYPE", "language_type": "html", "sub_task_type": "div"}, "context_code": [], "task_instance_info": {"created_time": "2025-08-21 06:17:36", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Simulate rapid user interactions and verify that only the initial request is processed while subsequent actions are ignored during ongoing operations."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```html\n[TASK_BEGIN]\n <div class=\"test\">\n <h3>Test PATCH includes parameters in body</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL, body = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n body = evt.detail.cfg.body;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo\");\n assertEq(body.has('foo'), true);\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"patch\">\n Button 1\n </button>\n </form>\n </div>\n[TASK_END]\n```", "inference_time": "2025-08-21 06-17-53"}, "editdistance_info": {"edit_distance": 34.4633, "calculate_time": "2025-08-21 06:17:53", "true_code_clean": "<div class=\"test\">\n <h3>Test double-click works when drop disabled</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>", "predict_code_clean": "<div class=\"test\">\n <h3>Test PATCH includes parameters in body</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL, body = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n body = evt.detail.cfg.body;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo\");\n assertEq(body.has('foo'), true);\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"patch\">\n Button 1\n </button>\n </form>\n </div>"}}
{"repo_name": "fixi", "file_name": "/fixi/test.html", "inference_info": {"prefix_code": "<html lang=\"en\">\n<head>\n <title>fixi test suite</title>\n <script>\n let tests = [];\n let currentTest = null;\n let passed = 0;\n let failed = 0;\n let find = (selector) => currentTest.testElt.querySelector(selector);\n function fetchMock(action, init){\n if (init.signal && init.signal.aborted) {\n throw new DOMException(\"Aborted\", \"AbortError\");\n }\n for (let mock of currentTest.mocks) {\n if (mock.path === action || (mock.path.test && mock.path.test(action))) {\n if (typeof mock.response === 'string' || mock.response instanceof String) {\n return Promise.resolve({text : () => Promise.resolve(mock.response)});\n } else {\n return Promise.resolve({text: () => Promise.resolve(mock.response(action, init))})\n }\n }\n }\n throw `Unknown path: ${action}`;\n }\n document.addEventListener(\"fx:config\", (evt)=>{\n if (!evt.target.hasAttribute(\"use-real-fetch\")){\n evt.detail.cfg.fetch = fetchMock\n }\n })\n function test(code){\n let currentScript = document.currentScript;\n let testElt = currentScript.closest('div');\n tests.push(async ()=>{\n currentTest.testElt = testElt;\n try {\n await code();\n testElt.classList.add(\"passed\");\n testElt.insertAdjacentHTML('beforeend', `<p>Passed</p>`)\n passed++;\n document.querySelector(\".passed-info\").querySelector(\"output\").innerText = passed.toString();\n } catch (e) {\n testElt.classList.add(\"failed\");\n testElt.insertAdjacentHTML('beforeend', `<p>ERROR: ${e}</p>`)\n failed++;\n document.querySelector(\".failed-info\").querySelector(\"output\").innerText = failed.toString();\n } finally {\n currentTest = null;\n }\n })\n }\n function mock(path, response) {\n currentTest.mocks ||= []\n currentTest.mocks.push({path, response})\n }\n function sleep(ms) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n })\n }\n function assertEq(actual, expected, trim) {\n if (expected !== (trim ? actual?.trim() : actual)) {\n console.error(\"Expected\", expected, \"found\", actual);\n throw `Expected ${expected} found ${actual}`\n }\n }\n function logEvt(evt) {\n console.log(evt.type, evt.target, evt.detail?.cfg || \"\", evt.detail)\n }\n document.addEventListener(\"fx:init\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:process\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:config\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:before\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:after\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:error\", (evt) => console.error(evt.detail.error, evt.target, evt.detail?.cfg || \"\", evt.detail))\n document.addEventListener(\"fx:swapped\", (evt) => logEvt(evt))\n document.addEventListener('DOMContentLoaded', async () => {\n for (let i = 0; i < document.querySelectorAll(\".test\").length; i++){\n const testBlock = document.querySelectorAll(\".test\")[i];\n testBlock.querySelector(\"h3\").insertAdjacentHTML(\"beforeend\", ` - <a id='test${i}' href=\"test.html?test${i}\">run</a>`)\n let scriptElt = testBlock.querySelector(\"script\");\n scriptElt.insertAdjacentHTML(\"beforebegin\", `<b>Code:</b><pre></pre>`)\n scriptElt.previousElementSibling.innerText = scriptElt.innerText.replaceAll(/^ {8}/gm, '') + \"\\n\";\n if (location.search.indexOf(\"?test\") === 0) {\n let index = parseInt(location.search.substring(5));\n if (index !== i) {\n testBlock.setAttribute(\"fx-ignore\", 'true');\n } else {\n testBlock.scrollIntoView()\n }\n }\n }\n // let fixi initialize, then run tests in sequence\n setTimeout(async ()=>{\n for (let i = 0; i < tests.length; i++){\n if (location.search.indexOf(\"?test\") === 0) {\n let index = parseInt(location.search.substring(5));\n if (index !== i) {\n continue;\n }\n }\n currentTest = tests[i];\n await currentTest();\n }\n })\n });\n\n </script>\n <script src=\"fixi.js\"></script>\n <style>\n .test {\n padding: 8px;\n margin: 8px;\n }\n .passed {\n border: 3px solid green;\n }\n .failed {\n border: 3px solid red;\n }\n .passed-info {\n color: green;\n }\n .failed-info {\n color: red;\n }\n pre {\n padding: 4px;\n margin: 12px;\n border: 1px solid rgb(128, 128, 128);\n background-color: whitesmoke;\n }\n body.hide-passed .passed {\n display: none;\n }\n </style>\n</head>\n<body>\n\n<header>\n <h1>&#x1F6B2; fixi test suite</h1>\n <div>\n <div class=\"passed-info\">Passed: <output></output></div>\n <div class=\"failed-info\">Failed: <output></output></div>\n <a href=\"javascript:document.body.classList.toggle('hide-passed')\">Toggle Passed</a><br/>\n <a href=\"test.html\">Run All</a>\n </div>\n</header>\n\n<main>\n <section id=\"core\">\n <h2>Core</h2>\n <div class=\"test\">\n <h3>Test basic button works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button works when added dynamically</h3>\n <script>\n test(async ()=>{\n currentTest.testElt.insertAdjacentHTML('beforeEnd', `<button fx-action=\"/demo\">Button 1</button>`)\n await sleep(50);\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n </div>\n\n <div class=\"test\">\n <h3>Test basic target works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-target=\"#output1\">\n Button 1\n </button>\n <output id=\"output1\">\n Bar\n </output>\n </div>\n\n <div class=\"test\">\n <h3>Test basic target works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"afterend\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with inner swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with none swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"none\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with beforebegin swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.previousElementSibling?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"beforebegin\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test added content is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<button fx-action='/demo2'>Button 2</button>\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test added content with text around it is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"content <button fx-action='/demo2'>Button 2</button> content\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test nested added content is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<p><button fx-action='/demo2'>Button 2</button></p>\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test double-click works when drop disabled</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test double-click works when drop disabled</h3>\n <script>\n test(async ()=>{\n find('button').addEventListener(\"fx:config\", (evt)=> evt.detail.cfg.drop = false) // don't drop any reqs\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo2\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based throttling works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n if (evt.detail.requests.size > 0) {\n evt.preventDefault();\n }\n })\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based throttling w/delay works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n if (evt.detail.requests.length > 0) {\n evt.preventDefault();\n }\n })\n find('button').click();\n await sleep(50);\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo2\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based aborting works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.detail.cfg.abort();\n evt.detail.cfg.confirm = async() => {\n await sleep(1)\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based disabling works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.target.disabled = true;\n })\n find(\"button\").addEventListener(\"fx:finally\", (evt)=>{\n evt.target.disabled = true;\n })\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic form works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('form').requestSubmit();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <form id=\"f1\" fx-action=\"/demo\" fx-method=\"get\">\n Form1\n </form>\n </div>\n\n <div class=\"test\">\n <h3>Test confirm can disable</h3>\n <script>\n test(async ()=>{\n let allow = false;\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n evt.detail.cfg.confirm = ()=>allow\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n allow = true;\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test confirm-based debouncing works as expected</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n let latestPromise = null;\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n evt.detail.cfg.confirm = ()=>{\n let currentPromise = latestPromise = new Promise((resolve)=>{\n setTimeout(()=>resolve(currentPromise === latestPromise), 200)\n })\n return currentPromise\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n await sleep(200);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test can disable transitions</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.detail.cfg.transition = false\n })\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Moving a node does not reinitialize it</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n let requests = 0;\n find(\"button\").addEventListener(\"fx:before\", ()=>{\n requests++\n })\n let btn = find('button')\n // move button to the end of the div\n btn.parentElement.insertBefore(btn, null)\n await sleep(50);\n btn.click();\n await sleep(50);\n assertEq(requests, 1);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n <p>A Paragraph</p>\n </div>\n\n ", "suffix_code": "\n\n <div class=\"test\">\n <h3>GET url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>GET url encodes parameters and appends when existing params</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?baz=bloop&foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo?baz=bloop\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>DELETE url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"delete\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>POST does not url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL, body = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n body = evt.detail.cfg.body;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo\");\n assertEq(body.has('foo'), true);\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"post\">\n Button 1\n </button>\n </form>\n </div>\n\n </section>\n\n <section id=\"web-components\">\n <script>\n class TestWebComponent extends HTMLElement {\n connectedCallback() {\n console.log(this.innerHTML)\n this.innerHTML = this.getAttribute('data-inner-html');\n console.log(this.innerHTML)\n }\n }\n customElements.define('test-web-component', TestWebComponent)\n </script>\n <h2>Web Components</h2>\n\n <div class=\"test\">\n <h3>Works inside web components</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div>Foo</div>`);\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(btn.innerText, \"Foo\", true);\n })\n </script>\n <test-web-component data-inner-html=\"<button fx-action='/demo' fx-swap='innerHTML'>Demo</button>\">\n </test-web-component>\n </div>\n\n <div class=\"test\">\n <h3>Works directly on web components</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div>Foo</div>`);\n let component = find('test-web-component')\n component.click();\n await sleep(50);\n assertEq(component.innerText, \"Foo\", true);\n })\n </script>\n <test-web-component fx-action='/demo' fx-swap='innerHTML' data-inner-html=\"Foo\">\n </test-web-component>\n </div>\n\n <div class=\"test\">\n <h3>Test button input works</h3>\n <script>\n\t\t\t\t\t\t\ttest(async ()=>{\n\t\t\t\t\t\t\t\tmock(\"/demo\", \"<div>Foo</div>\");\n\t\t\t\t\t\t\t\tfind('input').click();\n\t\t\t\t\t\t\t\tawait sleep(50);\n\t\t\t\t\t\t\t\tassertEq(find('div')?.innerText, \"Foo\");\n\t\t\t\t\t\t\t})\n </script>\n <input type=\"button\" fx-action=\"/demo\" value=\"Button 1\">\n </div>\n\n <div class=\"test\">\n <h3>Test can swap classes</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`foo`);\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.className, \"foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"className\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test can use real fetch()</h3>\n <script>\n test(async ()=>{\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.innerText, \"foo\", true);\n })\n </script>\n <button fx-action=\"data:text/plain,foo\" fx-swap=\"innerHTML\" use-real-fetch>\n Button 1\n </button>\n </div>\n\n\n </section>\n\n <section id=\"events\">\n <h2>Events</h2>\n\n <div class=\"test\">\n <h3>Test basic fx:before triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:config', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test trigger event is cancelled when config halts</h3>\n <script>\n test(async ()=>{\n let defaultPrevented = false;\n mock(\"/demo\", \"<div>Foo</div>\");\n currentTest.testElt.addEventListener(\"click\", (evt)=>{\n defaultPrevented = evt.defaultPrevented;\n })\n find('button').addEventListener('fx:config', (evt) => {\n evt.preventDefault()\n })\n find('button').click();\n await sleep(50);\n assertEq(defaultPrevented, true);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:before triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:before', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:after triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:after', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:finally triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:finally', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test fx:before can cancel request</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:before', (evt) => {\n triggered = true;\n console.log(evt);\n evt.preventDefault();\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div'), null);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test evt.detail.cfg.swap can be a function</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let swapped = false;\n find('button').addEventListener('fx:before', (evt) => {\n evt.detail.cfg.swap = ()=>{\n swapped = true;\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(swapped, true);\n assertEq(find('div'), null);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:inited triggered</h3>\n <script>\n test(async ()=>{\n assertEq(find('button').classList.contains(\"fx-inited\"), true);\n assertEq(find('button').parentElement.classList.contains(\"fx-inited\"), false);\n })\n </script>\n <button fx-action=\"/demo\" fx-trigger=\"fx:inited\">\n Button 1\n </button>\n <script>\n let button = document.currentScript.previousElementSibling\n button.addEventListener(\"fx:before\", (evt)=>{\n evt.preventDefault(); // don't make the request\n })\n button.addEventListener(\"fx:inited\", ()=>{\n button.classList.add(\"fx-inited\")\n })\n button.parentElement.addEventListener(\"fx:inited\", ()=>{\n button.classList.add(\"fx-inited\")\n })\n </script>\n </div>\n\n <div class=\"test\">\n <h3>Test fx:swapped is triggered on doc even if element replaces itself</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let swapped = false;\n let evtListener = (e)=>{\n\t\t\t\t\t\t\t\t\tconsole.log('here!', e)\n\t\t\t\t swapped = true;\n }\n\t\t\t\tdocument.addEventListener(\"fx:swapped\", evtListener)\n find('button').click();\n await sleep(10);\n document.removeEventListener(\"fx:swapped\", evtListener)\n assertEq(swapped, true);\n })\n </script>\n <div id=\"parent-div\">\n <button fx-action=\"/demo\" fx-target=\"#parent-div\">\n Button 1\n </button>\n </div>\n </div>\n\n </section>\n\n</main>\n\n</body>\n</html>\n", "middle_code": "<div class=\"test\">\n <h3>Lazy loading works as expected using fx:inited</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div><p fx-action=\"/demo2\" fx-trigger=\"fx:inited\">Foo</p></div>`);\n mock(\"/demo2\", `Bar`);\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(btn.innerText, \"Bar\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>", "code_description": null, "fill_type": "BLOCK_TYPE", "language_type": "html", "sub_task_type": "div"}, "context_code": [], "task_instance_info": {"created_time": "2025-08-21 06:17:36", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Verify that dynamically injected elements with deferred initialization triggers correctly execute associated actions and update their content based on asynchronous responses."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```html\n[TASK_BEGIN]\n <div class=\"test\">\n <h3>Test can swap attributes</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`bar`);\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.getAttribute('data-foo'), \"bar\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"attribute:data-foo\">\n Button 1\n </button>\n </div>\n[TASK_END]\n```", "inference_time": "2025-08-21 06-17-55"}, "editdistance_info": {"edit_distance": 40.2985, "calculate_time": "2025-08-21 06:17:55", "true_code_clean": "<div class=\"test\">\n <h3>Lazy loading works as expected using fx:inited</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div><p fx-action=\"/demo2\" fx-trigger=\"fx:inited\">Foo</p></div>`);\n mock(\"/demo2\", `Bar`);\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(btn.innerText, \"Bar\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>", "predict_code_clean": "<div class=\"test\">\n <h3>Test can swap attributes</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`bar`);\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.getAttribute('data-foo'), \"bar\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"attribute:data-foo\">\n Button 1\n </button>\n </div>"}}
{"repo_name": "fixi", "file_name": "/fixi/test.html", "inference_info": {"prefix_code": "<html lang=\"en\">\n<head>\n <title>fixi test suite</title>\n <script>\n let tests = [];\n let currentTest = null;\n let passed = 0;\n let failed = 0;\n let find = (selector) => currentTest.testElt.querySelector(selector);\n function fetchMock(action, init){\n if (init.signal && init.signal.aborted) {\n throw new DOMException(\"Aborted\", \"AbortError\");\n }\n for (let mock of currentTest.mocks) {\n if (mock.path === action || (mock.path.test && mock.path.test(action))) {\n if (typeof mock.response === 'string' || mock.response instanceof String) {\n return Promise.resolve({text : () => Promise.resolve(mock.response)});\n } else {\n return Promise.resolve({text: () => Promise.resolve(mock.response(action, init))})\n }\n }\n }\n throw `Unknown path: ${action}`;\n }\n document.addEventListener(\"fx:config\", (evt)=>{\n if (!evt.target.hasAttribute(\"use-real-fetch\")){\n evt.detail.cfg.fetch = fetchMock\n }\n })\n function test(code){\n let currentScript = document.currentScript;\n let testElt = currentScript.closest('div');\n tests.push(async ()=>{\n currentTest.testElt = testElt;\n try {\n await code();\n testElt.classList.add(\"passed\");\n testElt.insertAdjacentHTML('beforeend', `<p>Passed</p>`)\n passed++;\n document.querySelector(\".passed-info\").querySelector(\"output\").innerText = passed.toString();\n } catch (e) {\n testElt.classList.add(\"failed\");\n testElt.insertAdjacentHTML('beforeend', `<p>ERROR: ${e}</p>`)\n failed++;\n document.querySelector(\".failed-info\").querySelector(\"output\").innerText = failed.toString();\n } finally {\n currentTest = null;\n }\n })\n }\n function mock(path, response) {\n currentTest.mocks ||= []\n currentTest.mocks.push({path, response})\n }\n function sleep(ms) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n })\n }\n function assertEq(actual, expected, trim) {\n if (expected !== (trim ? actual?.trim() : actual)) {\n console.error(\"Expected\", expected, \"found\", actual);\n throw `Expected ${expected} found ${actual}`\n }\n }\n function logEvt(evt) {\n console.log(evt.type, evt.target, evt.detail?.cfg || \"\", evt.detail)\n }\n document.addEventListener(\"fx:init\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:process\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:config\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:before\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:after\", (evt) => logEvt(evt))\n document.addEventListener(\"fx:error\", (evt) => console.error(evt.detail.error, evt.target, evt.detail?.cfg || \"\", evt.detail))\n document.addEventListener(\"fx:swapped\", (evt) => logEvt(evt))\n document.addEventListener('DOMContentLoaded', async () => {\n for (let i = 0; i < document.querySelectorAll(\".test\").length; i++){\n const testBlock = document.querySelectorAll(\".test\")[i];\n testBlock.querySelector(\"h3\").insertAdjacentHTML(\"beforeend\", ` - <a id='test${i}' href=\"test.html?test${i}\">run</a>`)\n let scriptElt = testBlock.querySelector(\"script\");\n scriptElt.insertAdjacentHTML(\"beforebegin\", `<b>Code:</b><pre></pre>`)\n scriptElt.previousElementSibling.innerText = scriptElt.innerText.replaceAll(/^ {8}/gm, '') + \"\\n\";\n if (location.search.indexOf(\"?test\") === 0) {\n let index = parseInt(location.search.substring(5));\n if (index !== i) {\n testBlock.setAttribute(\"fx-ignore\", 'true');\n } else {\n testBlock.scrollIntoView()\n }\n }\n }\n // let fixi initialize, then run tests in sequence\n setTimeout(async ()=>{\n for (let i = 0; i < tests.length; i++){\n if (location.search.indexOf(\"?test\") === 0) {\n let index = parseInt(location.search.substring(5));\n if (index !== i) {\n continue;\n }\n }\n currentTest = tests[i];\n await currentTest();\n }\n })\n });\n\n </script>\n <script src=\"fixi.js\"></script>\n <style>\n .test {\n padding: 8px;\n margin: 8px;\n }\n .passed {\n border: 3px solid green;\n }\n .failed {\n border: 3px solid red;\n }\n .passed-info {\n color: green;\n }\n .failed-info {\n color: red;\n }\n pre {\n padding: 4px;\n margin: 12px;\n border: 1px solid rgb(128, 128, 128);\n background-color: whitesmoke;\n }\n body.hide-passed .passed {\n display: none;\n }\n </style>\n</head>\n<body>\n\n<header>\n <h1>&#x1F6B2; fixi test suite</h1>\n <div>\n <div class=\"passed-info\">Passed: <output></output></div>\n <div class=\"failed-info\">Failed: <output></output></div>\n <a href=\"javascript:document.body.classList.toggle('hide-passed')\">Toggle Passed</a><br/>\n <a href=\"test.html\">Run All</a>\n </div>\n</header>\n\n<main>\n <section id=\"core\">\n <h2>Core</h2>\n <div class=\"test\">\n <h3>Test basic button works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button works when added dynamically</h3>\n <script>\n test(async ()=>{\n currentTest.testElt.insertAdjacentHTML('beforeEnd', `<button fx-action=\"/demo\">Button 1</button>`)\n await sleep(50);\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n </div>\n\n <div class=\"test\">\n <h3>Test basic target works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-target=\"#output1\">\n Button 1\n </button>\n <output id=\"output1\">\n Bar\n </output>\n </div>\n\n <div class=\"test\">\n <h3>Test basic target works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"afterend\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with inner swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic button with none swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"none\">\n Button 1\n </button>\n </div>\n\n ", "suffix_code": "\n\n <div class=\"test\">\n <h3>Test added content is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<button fx-action='/demo2'>Button 2</button>\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test added content with text around it is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"content <button fx-action='/demo2'>Button 2</button> content\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test nested added content is live</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<p><button fx-action='/demo2'>Button 2</button></p>\");\n mock(\"/demo2\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 2\", true);\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test double-click works when drop disabled</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test double-click works when drop disabled</h3>\n <script>\n test(async ()=>{\n find('button').addEventListener(\"fx:config\", (evt)=> evt.detail.cfg.drop = false) // don't drop any reqs\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo2\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based throttling works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n if (evt.detail.requests.size > 0) {\n evt.preventDefault();\n }\n })\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based throttling w/delay works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n if (evt.detail.requests.length > 0) {\n evt.preventDefault();\n }\n })\n find('button').click();\n await sleep(50);\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo2\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based aborting works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.detail.cfg.abort();\n evt.detail.cfg.confirm = async() => {\n await sleep(1)\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test event-based disabling works</h3>\n <script>\n test(async ()=>{\n let i = 1;\n mock(\"/demo\", ()=>`<div>Foo${i++}</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.target.disabled = true;\n })\n find(\"button\").addEventListener(\"fx:finally\", (evt)=>{\n evt.target.disabled = true;\n })\n find('button').click();\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Foo1\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic form works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('form').requestSubmit();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <form id=\"f1\" fx-action=\"/demo\" fx-method=\"get\">\n Form1\n </form>\n </div>\n\n <div class=\"test\">\n <h3>Test confirm can disable</h3>\n <script>\n test(async ()=>{\n let allow = false;\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n evt.detail.cfg.confirm = ()=>allow\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n allow = true;\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test confirm-based debouncing works as expected</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n let latestPromise = null;\n find(\"button\").addEventListener(\"fx:config\", (evt)=>{\n evt.detail.cfg.confirm = ()=>{\n let currentPromise = latestPromise = new Promise((resolve)=>{\n setTimeout(()=>resolve(currentPromise === latestPromise), 200)\n })\n return currentPromise\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.innerText, \"Button 1\");\n await sleep(200);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test can disable transitions</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n evt.detail.cfg.transition = false\n })\n find('button').click();\n await sleep(50);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Moving a node does not reinitialize it</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`<div>Foo</div>`);\n let requests = 0;\n find(\"button\").addEventListener(\"fx:before\", ()=>{\n requests++\n })\n let btn = find('button')\n // move button to the end of the div\n btn.parentElement.insertBefore(btn, null)\n await sleep(50);\n btn.click();\n await sleep(50);\n assertEq(requests, 1);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n <p>A Paragraph</p>\n </div>\n\n <div class=\"test\">\n <h3>Lazy loading works as expected using fx:inited</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div><p fx-action=\"/demo2\" fx-trigger=\"fx:inited\">Foo</p></div>`);\n mock(\"/demo2\", `Bar`);\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(btn.innerText, \"Bar\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"innerHTML\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>GET url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>GET url encodes parameters and appends when existing params</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?baz=bloop&foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo?baz=bloop\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>DELETE url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo?foo=bar\");\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"delete\">\n Button 1\n </button>\n </form>\n </div>\n\n <div class=\"test\">\n <h3>POST does not url encodes parameters</h3>\n <script>\n test(async ()=>{\n mock(/.*/, ()=>`<div>Foo</div>`);\n let finalURL, body = null;\n find(\"button\").addEventListener(\"fx:before\", (evt)=>{\n finalURL = evt.detail.cfg.action;\n body = evt.detail.cfg.body;\n })\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(finalURL, \"/demo\");\n assertEq(body.has('foo'), true);\n })\n </script>\n <form>\n <input type=\"text\" name=\"foo\" value=\"bar\">\n <button fx-action=\"/demo\" fx-method=\"post\">\n Button 1\n </button>\n </form>\n </div>\n\n </section>\n\n <section id=\"web-components\">\n <script>\n class TestWebComponent extends HTMLElement {\n connectedCallback() {\n console.log(this.innerHTML)\n this.innerHTML = this.getAttribute('data-inner-html');\n console.log(this.innerHTML)\n }\n }\n customElements.define('test-web-component', TestWebComponent)\n </script>\n <h2>Web Components</h2>\n\n <div class=\"test\">\n <h3>Works inside web components</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div>Foo</div>`);\n let btn = find('button')\n btn.click();\n await sleep(50);\n assertEq(btn.innerText, \"Foo\", true);\n })\n </script>\n <test-web-component data-inner-html=\"<button fx-action='/demo' fx-swap='innerHTML'>Demo</button>\">\n </test-web-component>\n </div>\n\n <div class=\"test\">\n <h3>Works directly on web components</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", `<div>Foo</div>`);\n let component = find('test-web-component')\n component.click();\n await sleep(50);\n assertEq(component.innerText, \"Foo\", true);\n })\n </script>\n <test-web-component fx-action='/demo' fx-swap='innerHTML' data-inner-html=\"Foo\">\n </test-web-component>\n </div>\n\n <div class=\"test\">\n <h3>Test button input works</h3>\n <script>\n\t\t\t\t\t\t\ttest(async ()=>{\n\t\t\t\t\t\t\t\tmock(\"/demo\", \"<div>Foo</div>\");\n\t\t\t\t\t\t\t\tfind('input').click();\n\t\t\t\t\t\t\t\tawait sleep(50);\n\t\t\t\t\t\t\t\tassertEq(find('div')?.innerText, \"Foo\");\n\t\t\t\t\t\t\t})\n </script>\n <input type=\"button\" fx-action=\"/demo\" value=\"Button 1\">\n </div>\n\n <div class=\"test\">\n <h3>Test can swap classes</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", ()=>`foo`);\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.className, \"foo\");\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"className\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test can use real fetch()</h3>\n <script>\n test(async ()=>{\n find('button').click()\n await sleep(50);\n assertEq(find('button')?.innerText, \"foo\", true);\n })\n </script>\n <button fx-action=\"data:text/plain,foo\" fx-swap=\"innerHTML\" use-real-fetch>\n Button 1\n </button>\n </div>\n\n\n </section>\n\n <section id=\"events\">\n <h2>Events</h2>\n\n <div class=\"test\">\n <h3>Test basic fx:before triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:config', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test trigger event is cancelled when config halts</h3>\n <script>\n test(async ()=>{\n let defaultPrevented = false;\n mock(\"/demo\", \"<div>Foo</div>\");\n currentTest.testElt.addEventListener(\"click\", (evt)=>{\n defaultPrevented = evt.defaultPrevented;\n })\n find('button').addEventListener('fx:config', (evt) => {\n evt.preventDefault()\n })\n find('button').click();\n await sleep(50);\n assertEq(defaultPrevented, true);\n assertEq(find('button')?.innerText, \"Button 1\", true);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:before triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:before', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:after triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:after', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:finally triggered</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:finally', () => {\n triggered = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div')?.innerText, \"Foo\");\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test fx:before can cancel request</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let triggered = false;\n find('button').addEventListener('fx:before', (evt) => {\n triggered = true;\n console.log(evt);\n evt.preventDefault();\n })\n find('button').click();\n await sleep(50);\n assertEq(triggered, true);\n assertEq(find('div'), null);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test evt.detail.cfg.swap can be a function</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let swapped = false;\n find('button').addEventListener('fx:before', (evt) => {\n evt.detail.cfg.swap = ()=>{\n swapped = true;\n }\n })\n find('button').click();\n await sleep(50);\n assertEq(swapped, true);\n assertEq(find('div'), null);\n })\n </script>\n <button fx-action=\"/demo\">\n Button 1\n </button>\n </div>\n\n <div class=\"test\">\n <h3>Test basic fx:inited triggered</h3>\n <script>\n test(async ()=>{\n assertEq(find('button').classList.contains(\"fx-inited\"), true);\n assertEq(find('button').parentElement.classList.contains(\"fx-inited\"), false);\n })\n </script>\n <button fx-action=\"/demo\" fx-trigger=\"fx:inited\">\n Button 1\n </button>\n <script>\n let button = document.currentScript.previousElementSibling\n button.addEventListener(\"fx:before\", (evt)=>{\n evt.preventDefault(); // don't make the request\n })\n button.addEventListener(\"fx:inited\", ()=>{\n button.classList.add(\"fx-inited\")\n })\n button.parentElement.addEventListener(\"fx:inited\", ()=>{\n button.classList.add(\"fx-inited\")\n })\n </script>\n </div>\n\n <div class=\"test\">\n <h3>Test fx:swapped is triggered on doc even if element replaces itself</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n let swapped = false;\n let evtListener = (e)=>{\n\t\t\t\t\t\t\t\t\tconsole.log('here!', e)\n\t\t\t\t swapped = true;\n }\n\t\t\t\tdocument.addEventListener(\"fx:swapped\", evtListener)\n find('button').click();\n await sleep(10);\n document.removeEventListener(\"fx:swapped\", evtListener)\n assertEq(swapped, true);\n })\n </script>\n <div id=\"parent-div\">\n <button fx-action=\"/demo\" fx-target=\"#parent-div\">\n Button 1\n </button>\n </div>\n </div>\n\n </section>\n\n</main>\n\n</body>\n</html>\n", "middle_code": "<div class=\"test\">\n <h3>Test basic button with beforebegin swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.previousElementSibling?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"beforebegin\">\n Button 1\n </button>\n </div>", "code_description": null, "fill_type": "BLOCK_TYPE", "language_type": "html", "sub_task_type": "div"}, "context_code": [], "task_instance_info": {"created_time": "2025-08-21 06:17:36", "created_task_model": "DeepSeek-R1", "code_description": "This code segment functions to: Verify the correct insertion of dynamically loaded content immediately preceding a triggering element when a specific placement strategy is applied during user interaction."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```html\n[TASK_BEGIN]\n <div class=\"test\">\n <h3>Test self-replacement triggers fx:swapped on document</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<button fx-action='/demo'>New Button</button>\");\n let swapped = false;\n document.addEventListener(\"fx:swapped\", ()=>{\n swapped = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(swapped, true);\n assertEq(find('button')?.innerText, \"New Button\");\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"outerHTML\">\n Original Button\n </button>\n </div>\n[TASK_END]\n```", "inference_time": "2025-08-21 06-18-00"}, "editdistance_info": {"edit_distance": 47.8873, "calculate_time": "2025-08-21 06:18:00", "true_code_clean": "<div class=\"test\">\n <h3>Test basic button with beforebegin swap works</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<div>Foo</div>\");\n find('button').click();\n await sleep(50);\n assertEq(find('button')?.previousElementSibling?.innerText, \"Foo\", true);\n })\n </script>\n <button fx-action=\"/demo\" fx-method=\"get\" fx-swap=\"beforebegin\">\n Button 1\n </button>\n </div>", "predict_code_clean": "<div class=\"test\">\n <h3>Test self-replacement triggers fx:swapped on document</h3>\n <script>\n test(async ()=>{\n mock(\"/demo\", \"<button fx-action='/demo'>New Button</button>\");\n let swapped = false;\n document.addEventListener(\"fx:swapped\", ()=>{\n swapped = true;\n })\n find('button').click();\n await sleep(50);\n assertEq(swapped, true);\n assertEq(find('button')?.innerText, \"New Button\");\n })\n </script>\n <button fx-action=\"/demo\" fx-swap=\"outerHTML\">\n Original Button\n </button>\n </div>"}}