mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-20 14:10:57 -06:00
fix(bug): indeterminate checkbox state doesn't get changed (#21665)
This commit is contained in:
@@ -71,6 +71,21 @@ describe('src/cy/commands/actions/check', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/19098
|
||||
it('removes indeterminate prop when checkbox is checked', () => {
|
||||
const intermediateCheckbox = $(`<input type='checkbox' name="indeterminate">`)
|
||||
|
||||
intermediateCheckbox.prop('indeterminate', true)
|
||||
|
||||
$('body').append(intermediateCheckbox)
|
||||
|
||||
cy.get(':checkbox[name=\'indeterminate\']').check().then(($checkbox) => {
|
||||
const hasIndeterminate = $checkbox.prop('indeterminate')
|
||||
|
||||
expect(hasIndeterminate).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
it('is a noop if already checked', () => {
|
||||
const checkbox = ':checkbox[name=\'colors\'][value=\'blue\']'
|
||||
|
||||
@@ -839,6 +854,21 @@ describe('src/cy/commands/actions/check', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/19098
|
||||
it('removes indeterminate prop when checkbox is unchecked', () => {
|
||||
const indeterminateCheckbox = $(`<input type='checkbox' name="indeterminate">`)
|
||||
|
||||
indeterminateCheckbox.prop('indeterminate', true)
|
||||
|
||||
$('body').append(indeterminateCheckbox)
|
||||
|
||||
cy.get(':checkbox[name=\'indeterminate\']').uncheck().then(($checkbox) => {
|
||||
const hasIndeterminate = $checkbox.prop('indeterminate')
|
||||
|
||||
expect(hasIndeterminate).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
it('unchecks a checkbox', () => {
|
||||
cy.get('[name=birds][value=cockatoo]').uncheck().then(($checkbox) => {
|
||||
expect($checkbox).not.to.be.checked
|
||||
|
||||
@@ -113,6 +113,13 @@ const checkOrUncheck = (Cypress, cy, type, subject, values: any[] = [], userOpti
|
||||
cy.ensureVisibility($el, options._log)
|
||||
}
|
||||
|
||||
// if the checkbox is in an indeterminate state, checking or unchecking should set the
|
||||
// prop to false to move it into a "determinate" state
|
||||
// https://github.com/cypress-io/cypress/issues/19098
|
||||
if ($el.prop('indeterminate')) {
|
||||
$el.prop('indeterminate', false)
|
||||
}
|
||||
|
||||
if (options._log) {
|
||||
const inputType = $el.is(':radio') ? 'radio' : 'checkbox'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user