htmx/test/index.html
fhp-mec 11cef8ee83
Fix: Make the SSE extension work properly and adhere to tests (#2025)
* Process sse-swap properly when swapped in

Previously `sse-swap` were only processed when `sse-connect` was on the
root of what was being swapped in.
This is now fixed so that the closest sseEventSource is found and used as the
event source

* Pass for code readabiltiy

remove the nested if statements as there is no difference in handling
between sseURL and LegacySSEUrl.

* Fix indenting

* Initial attempt at sse extension tests

* Make existing tests pass

* Add test case for #916

* backport test for #916 to hx-sse for completeness

* add a distinct test for sse-swap

* more tests, fix tests

+ more tests differentiating the implementation of sse-swap and
hx-trigger
* fix for "is closed after removal with no close and activity"

* Cleanup listener if element is gone

* Revert "Cleanup listener if element is gone"

This reverts commit bbe3715276302656d1a422fbc4778842776e35f6.

* Clean up listeners if element gone, fix indenting

* Incorportate feedback from first review

+ seperate eventSource creation logic and event registering logic
+ manually create event handling, still confused by how hx-trigger works
* `createEventSourceOnElement` now looks for event sources in children
* explicitly handle legacy sse handling instead of having extra
  selectors in `querySelectorOnThisOrChildren`
+ a few readability changes
+ add regression check to make sure that sseEventSource is only created
  on elements with sse-connect or equivalent
+ add test to make sure that sse-connect in the child of a swapped
  element is handled

* Allow multiple listeners in eventsource mock

* Backport eventsource mocks to legacy tests

---------

Co-authored-by: 1cg <469183+1cg@users.noreply.github.com>
2023-12-14 14:33:38 -07:00

187 lines
6.3 KiB
HTML

<html lang="en">
<head>
<meta charset="utf-8" />
<title>Mocha Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="htmx-config" content='{"historyEnabled":false,"defaultSettleDelay":0}'>
</head>
<body style="padding:20px;font-family: sans-serif">
<h1 style="margin-top: 40px">htmx.js test suite</h1>
<p id="version-number">Version:&nbsp;</p>
<h2>Scratch Page</h2>
<ul>
<li>
<a href="scratch/scratch.html">Scratch Page</a>
</li>
</ul>
<h2>Manual Tests</h2>
<a href="manual">Here</a>
<h2>Mocha Test Suite</h2>
<a href="index.html">[ALL]</a>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/chai-dom/chai-dom.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/mocha-webdriver-runner/dist/mocha-webdriver-client.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
<script src="../node_modules/mock-socket/dist/mock-socket.js"></script>
<script src="../src/htmx.js"></script>
<script>
// Do not log all the events in headless mode (the log output is enormous)
if (navigator.webdriver) {
htmx.logAll = function () { }
}
// Add the version number to the top
document.getElementById('version-number').innerText += htmx.version
</script>
<script class="mocha-init">
mocha.setup('bdd');
mocha.checkLeaks();
should = chai.should();
</script>
<script src="util/util.js"></script>
<!-- core tests -->
<script src="core/internals.js"></script>
<script src="core/api.js"></script>
<script src="core/ajax.js"></script>
<script src="core/extensions.js"></script>
<script src="core/verbs.js"></script>
<script src="core/parameters.js"></script>
<script src="core/headers.js"></script>
<script src="core/regressions.js"></script>
<script src="core/security.js"></script>
<script src="core/perf.js"></script>
<script src="core/validation.js"></script>
<script src="core/tokenizer.js"></script>
<!-- attribute tests -->
<script src="attributes/hx-boost.js"></script>
<script src="attributes/hx-confirm.js"></script>
<script src="attributes/hx-delete.js"></script>
<script src="attributes/hx-ext.js"></script>
<script src="attributes/hx-get.js"></script>
<script src="attributes/hx-headers.js"></script>
<script src="attributes/hx-history.js"></script>
<script src="attributes/hx-include.js"></script>
<script src="attributes/hx-indicator.js"></script>
<script src="attributes/hx-disabled-elt.js"></script>
<script src="attributes/hx-disinherit.js"></script>
<script src="attributes/hx-on.js"></script>
<script src="attributes/hx-on-wildcard.js"></script>
<script src="attributes/hx-params.js"></script>
<script src="attributes/hx-patch.js"></script>
<script src="attributes/hx-post.js"></script>
<script src="attributes/hx-preserve.js"></script>
<script src="attributes/hx-push-url.js"></script>
<script src="attributes/hx-put.js"></script>
<script src="attributes/hx-request.js"></script>
<script src="attributes/hx-select.js"></script>
<script src="attributes/hx-select-oob.js"></script>
<script src="attributes/hx-sse.js"></script>
<script src="attributes/hx-swap-oob.js"></script>
<script src="attributes/hx-swap.js"></script>
<script src="attributes/hx-sync.js"></script>
<script src="attributes/hx-target.js"></script>
<script src="attributes/hx-trigger.js"></script>
<script src="attributes/hx-vals.js"></script>
<script src="attributes/hx-vars.js"></script>
<script src="attributes/hx-ws.js"></script>
<!-- hyperscript integration -->
<script src="lib/_hyperscript.js"></script>
<script src="ext/hyperscript.js"></script>
<!-- extension tests -->
<script src="ext/extension-swap.js"></script>
<script src="../src/ext/method-override.js"></script>
<script src="ext/method-override.js"></script>
<script src="../src/ext/debug.js"></script>
<script src="ext/debug.js"></script>
<script src="lib/morphdom-umd.js"></script>
<script src="../src/ext/morphdom-swap.js"></script>
<script src="ext/morphdom-swap.js"></script>
<script src="../src/ext/json-enc.js"></script>
<script src="ext/json-enc.js"></script>
<script src="lib/handlebars-v4.7.6.js"></script>
<script src="lib/mustache.js"></script>
<script src="../src/ext/client-side-templates.js"></script>
<script src="ext/client-side-templates.js"></script>
<script src="../src/ext/path-deps.js"></script>
<script src="ext/path-deps.js"></script>
<script src="../src/ext/class-tools.js"></script>
<script src="ext/class-tools.js"></script>
<script src="../src/ext/loading-states.js"></script>
<script src="ext/loading-states.js"></script>
<script src="ext/bad-extension.js"></script>
<script src="../src/ext/remove-me.js"></script>
<script src="ext/remove-me.js"></script>
<script src="../src/ext/include-vals.js"></script>
<script src="ext/include-vals.js"></script>
<script src="../src/ext/ajax-header.js"></script>
<script src="ext/ajax-header.js"></script>
<script src="../src/ext/event-header.js"></script>
<script src="ext/event-header.js"></script>
<script src="../src/ext/disable-element.js"></script>
<script src="ext/disable-element.js"></script>
<script src="../src/ext/multi-swap.js"></script>
<script src="ext/multi-swap.js"></script>
<script src="../src/ext/ws.js"></script>
<script src="ext/ws.js"></script>
<script src="../src/ext/sse.js"></script>
<script src="ext/sse.js"></script>
<script src="../src/ext/response-targets.js"></script>
<script src="ext/response-targets.js"></script>
<script src="../src/ext/path-params.js"></script>
<script src="ext/path-params.js"></script>
<!-- events last so they don't screw up other tests -->
<script src="core/events.js"></script>
<div id="mocha"></div>
<script class="mocha-exec">
document.addEventListener("DOMContentLoaded", function () {
mocha.setup({globals: ['$0', '$1', '$2', '$3', '$4', 'performance', 'requestAnimationFrame', 'cancelAnimationFrame', 'confirm']}); <!-- IE11 -->
mocha.run();
})
</script>
<em>Work Area</em>
<hr/>
<div id="work-area" hx-history-elt>
</div>
</body>
</html>