htmx/www/static/test/attributes/hx-preserve.js
Alexander Petros d1288d202a
Remove old tests from the website (#1733)
The website used to host every past test suite, copied into the www
directory. We no longer need that on the website (and it makes the
codebase impossible to search) so I removed all the old tests and the
new tests are hosted simply at /test.

I also replaced the www.js script with a simpler www.sh one (since we no
longer need to do anything besides copying, really), which allowed me to
remove a node dependency that was only used in that script.
2023-09-19 11:07:24 -05:00

40 lines
1.7 KiB
JavaScript

describe("hx-preserve attribute", function () {
beforeEach(function () {
this.server = makeServer();
clearWorkArea();
});
afterEach(function () {
this.server.restore();
clearWorkArea();
});
it('handles basic response properly', function () {
this.server.respondWith("GET", "/test", "<div id='d1' hx-preserve>New Content</div><div id='d2'>New Content</div>");
var div = make("<div hx-get='/test'><div id='d1' hx-preserve>Old Content</div><div id='d2'>Old Content</div></div>");
div.click();
this.server.respond();
byId("d1").innerHTML.should.equal("Old Content");
byId("d2").innerHTML.should.equal("New Content");
})
it('handles preserved element that might not be existing', function () {
this.server.respondWith("GET", "/test", "<div id='d1' hx-preserve>New Content</div><div id='d2'>New Content</div>");
var div = make("<div hx-get='/test'><div id='d2'>Old Content</div></div>");
div.click();
this.server.respond();
byId("d1").innerHTML.should.equal("New Content");
byId("d2").innerHTML.should.equal("New Content");
})
it('preserved element should not be swapped if it lies outside of hx-select', function () {
this.server.respondWith("GET", "/test", "<div id='d1' hx-preserve>New Content</div><div id='d2'>New Content</div>");
var div = make("<div hx-get='/test' hx-target='#d2' hx-select='#d2' hx-swap='outerHTML'><div id='d1' hx-preserve>Old Content</div><div id='d2'>Old Content</div></div>");
div.click();
this.server.respond();
byId("d1").innerHTML.should.equal("Old Content");
byId("d2").innerHTML.should.equal("New Content");
})
});