Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2676 - Tests for v2 to prevent regression of issue from v1 #2829

Conversation

ehenighan
Copy link
Contributor

Description

Added a basic test for radio input form submission, following the example for checkbox inputs.
Added tests for custom validation on radio and checkbox inputs when the inputs are empty, to support things like 'you must choose an option from at least one of these groups' etc.
These tests pass for v2 due to the refactoring of processInputValue in commit b9322450ff42a5bdf25b194fcdb6ecc744353819 : b932245#diff-f14ff7f8c91a6f76e7688c45ca01d600e8928769b268caa71cf09b8f12661f3dR2528-R2530

Corresponding issue: #2676

Testing

As above - manually tested the fix in v1 using the replication sample attached to the ticket, wrote the tests and saw they failed when without the fix. Carried the fixes over to v2, saw that the tests passed now, checked why, and thought it best to submit the tests anyway.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@@ -559,6 +559,34 @@ describe('Core htmx AJAX Tests', function() {
values.should.deep.equal({ c1: ['cb1', 'cb3'], c2: 'cb5', c3: 'cb6' })
})

it('properly handles radio inputs', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially just a cut-down clone of the function above which tests checkboxes in detail, to cover the shouldInclude logic which applies to both input types:

if (elt.type === 'checkbox' || elt.type === 'radio') { return elt.checked }

this.server.respond()
form.textContent.should.equal('Clicked!')
})

Copy link
Contributor Author

@ehenighan ehenighan Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two functions are essentially clones of the previous function but applied specifically to the input types with special handling in shouldInclude (if (elt.type === 'checkbox' || elt.type === 'radio') { return elt.checked }) to ensure that custom validation isn't broken for unchecked items again in the future

Copy link
Collaborator

@Telroshan Telroshan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the details & the new test cases!

@Telroshan Telroshan merged commit 27fc37c into bigskysoftware:dev Aug 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants