Skip to content

Commit

Permalink
Adding tests to demonstrate bigskysoftware#2676
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Henighan committed Aug 19, 2024
1 parent 7dd6cd7 commit c3b3c44
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/core/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,35 @@ describe("Core htmx AJAX Tests", function(){

});

it('properly handles radio inputs', function()
{
var values;
this.server.respondWith('Post', '/test', function(xhr) {
values = getParameters(xhr)
xhr.respond(204, {}, '')
});

var form = make('<form hx-post="/test" hx-trigger="click">' +
'<div role="radiogroup">' +
'<input id="rb1" name="r1" value="rb1" type="radio">' +
'<input id="rb2" name="r1" value="rb2" type="radio">' +
'<input id="rb3" name="r1" value="rb3" type="radio">' +
'<input id="rb4" name="r2" value="rb4" type="radio">' +
'<input id="rb5" name="r2" value="rb5" type="radio">' +
'<input id="rb6" name="r3" value="rb6" type="radio">' +
'</div>' +
'</form>');

form.click();
this.server.respond();
values.should.deep.equal({});

byId('rb1').checked = true;
form.click();
this.server.respond();
values.should.deep.equal({ r1: 'rb1' });
});

it('text nodes dont screw up settling via variable capture', function()
{
this.server.respondWith("GET", "/test", "<div id='d1' hx-trigger='click consume' hx-get='/test2'></div>fooo");
Expand Down
36 changes: 36 additions & 0 deletions test/core/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,42 @@ describe("Core htmx client side validation tests", function(){
form.textContent.should.equal("Clicked!");
});

it('Custom validation error prevents request for unticked checkboxes', function() {
this.server.respondWith('POST', '/test', 'Clicked!');

var form = make('<form hx-post="/test" hx-trigger="click">' +
'No Request' +
'<input id="i1" name="i1" type="checkbox">' +
'</form>');
byId('i1').setCustomValidity('Nope');
form.textContent.should.equal('No Request');
form.click();
this.server.respond();
form.textContent.should.equal('No Request');
byId('i1').setCustomValidity('');
form.click();
this.server.respond();
form.textContent.should.equal('Clicked!');
});

it('Custom validation error prevents request for unselected radiogroups', function() {
this.server.respondWith('POST', '/test', 'Clicked!');

var form = make('<form hx-post="/test" hx-trigger="click">' +
'No Request' +
'<input id="i1" name="i1" type="radio">' +
'</form>');
byId('i1').setCustomValidity('Nope');
form.textContent.should.equal('No Request');
form.click();
this.server.respond();
form.textContent.should.equal('No Request');
byId('i1').setCustomValidity('');
form.click();
this.server.respond();
form.textContent.should.equal('Clicked!');
});

it('hyperscript validation error prevents request', function()
{
if (IsIE11()) {
Expand Down

0 comments on commit c3b3c44

Please sign in to comment.