mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-12 02:00:06 -06:00
fix: .select() by index works if <options> have same value (run ci) (#25016)
This commit is contained in:
@@ -51,6 +51,14 @@ describe('src/cy/commands/actions/select', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle index when all values are identical', () => {
|
||||
cy.$$('select[name=maps] option').attr('value', 'foo')
|
||||
|
||||
cy.get('select[name=maps]').select(2).then(($select) => {
|
||||
expect($select[0].selectedOptions[0].text).to.eq('nuke')
|
||||
})
|
||||
})
|
||||
|
||||
it('can select an array of values', () => {
|
||||
cy.get('select[name=movies]').select(['apoc', 'br', 'co']).then(($select) => {
|
||||
expect($select.val()).to.deep.eq(['apoc', 'br', 'co'])
|
||||
|
||||
@@ -127,6 +127,11 @@ export default (Commands, Cypress, cy) => {
|
||||
if (valueOrTextOrIndex.includes(value) || valueOrTextOrIndex.includes(index)) {
|
||||
optionEls.push(optEl)
|
||||
values.push(value)
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/24739
|
||||
if (options.$el.find(`option[value="${value}"]`).length > 1) {
|
||||
notAllUniqueValues = true
|
||||
}
|
||||
}
|
||||
|
||||
// replace new line chars, then trim spaces
|
||||
@@ -183,9 +188,7 @@ export default (Commands, Cypress, cy) => {
|
||||
args: { node },
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
_.each(optionEls, ($el) => {
|
||||
if ($el.closest('optgroup').prop('disabled')) {
|
||||
node = $dom.stringify($el)
|
||||
|
||||
@@ -271,7 +274,7 @@ export default (Commands, Cypress, cy) => {
|
||||
|
||||
if (notAllUniqueValues) {
|
||||
// if all the values are the same and the user is trying to
|
||||
// select based on the text, setting the val() will just
|
||||
// select based on the text or index, setting the val() will just
|
||||
// select the first one
|
||||
let selectedIndex = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user