mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 15:25:26 +00:00

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.
164 lines
5.9 KiB
JavaScript
164 lines
5.9 KiB
JavaScript
describe("hx-headers attribute", function() {
|
|
beforeEach(function () {
|
|
this.server = makeServer();
|
|
clearWorkArea();
|
|
});
|
|
afterEach(function () {
|
|
this.server.restore();
|
|
clearWorkArea();
|
|
});
|
|
|
|
it('basic hx-headers works', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("test");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make("<div hx-post='/vars' hx-headers='\"i1\":\"test\"'></div>")
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('basic hx-headers works with braces', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("test");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make("<div hx-post='/vars' hx-headers='{\"i1\":\"test\"}'></div>")
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('multiple hx-headers works', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['v1'].should.equal("test");
|
|
xhr.requestHeaders['v2'].should.equal("42");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make("<div hx-post='/vars' hx-headers='\"v1\":\"test\", \"v2\":42'></div>")
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('hx-headers can be on parents', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("test");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
make("<div hx-headers='\"i1\":\"test\"'><div id='d1' hx-post='/vars'></div></div>");
|
|
var div = byId("d1");
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('hx-headers can override parents', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("best");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
make("<div hx-headers='\"i1\":\"test\"'><div id='d1' hx-headers='\"i1\":\"best\"' hx-post='/vars'></div></div>");
|
|
var div = byId("d1");
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('hx-headers overrides inputs', function () {
|
|
this.server.respondWith("POST", "/include", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("best");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make("<div hx-target='this'><input hx-post='/include' hx-headers='\"i1\":\"best\"' hx-trigger='click' id='i1' name='i1' value='test'/></div>")
|
|
var input = byId("i1")
|
|
input.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('basic hx-headers javascript: works', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("test");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make('<div hx-post="/vars" hx-headers="javascript:i1:\'test\'"></div>')
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('hx-headers works with braces', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("test");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make('<div hx-post="/vars" hx-headers="javascript:{i1:\'test\'}"></div>')
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('multiple hx-headers works', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['v1'].should.equal("test");
|
|
xhr.requestHeaders['v2'].should.equal("42");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make('<div hx-post="/vars" hx-headers="javascript:v1:\'test\', v2:42"></div>')
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('hx-headers can be on parents', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("test");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
make('<div hx-headers="javascript:i1:\'test\'"><div id="d1" hx-post="/vars"></div></div>')
|
|
var div = byId("d1");
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('hx-headers can override parents', function () {
|
|
this.server.respondWith("POST", "/vars", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("best");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
make('<div hx-headers="javascript:i1:\'test\'"><div id="d1" hx-headers="javascript:i1:\'best\'" hx-post="/vars"></div></div>')
|
|
var div = byId("d1");
|
|
div.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
it('hx-headers overrides inputs', function () {
|
|
this.server.respondWith("POST", "/include", function (xhr) {
|
|
|
|
xhr.requestHeaders['i1'].should.equal("best");
|
|
xhr.respond(200, {}, "Clicked!")
|
|
});
|
|
var div = make('<div hx-target="this"><input hx-post="/include" hx-headers="javascript:i1:\'best\'" hx-trigger="click" id="i1" name="i1" value="test"/></div>')
|
|
var input = byId("i1")
|
|
input.click();
|
|
this.server.respond();
|
|
div.innerHTML.should.equal("Clicked!");
|
|
});
|
|
|
|
|
|
}); |