diff --git a/cypress/integration/select-multiple.spec.js b/cypress/integration/select-multiple.spec.js index 3a35bf2..731721b 100644 --- a/cypress/integration/select-multiple.spec.js +++ b/cypress/integration/select-multiple.spec.js @@ -818,5 +818,40 @@ describe('Choices - select multiple', () => { }); }); }); + + describe('dynamically setting choice by value', () => { + const dynamicallySelectedChoiceValue = 'Choice 2'; + + it('selects choice', () => { + cy.get('[data-test-hook=set-choice-by-value]') + .find('.choices__list--multiple .choices__item') + .last() + .should($choice => { + expect($choice.text().trim()).to.equal( + dynamicallySelectedChoiceValue, + ); + }); + }); + + it('removes choice from dropdown list', () => { + cy.get('[data-test-hook=set-choice-by-value]') + .find('.choices__list--dropdown .choices__list') + .children() + .each($choice => { + expect($choice.text().trim()).to.not.equal( + dynamicallySelectedChoiceValue, + ); + }); + }); + + it('updates the value of the original input', () => { + cy.get('[data-test-hook=set-choice-by-value]') + .find('.choices__input.is-hidden') + .should($select => { + const val = $select.val() || []; + expect(val).to.contain(dynamicallySelectedChoiceValue); + }); + }); + }); }); }); diff --git a/cypress/integration/select-one.spec.js b/cypress/integration/select-one.spec.js index 7fc6513..f2d331e 100644 --- a/cypress/integration/select-one.spec.js +++ b/cypress/integration/select-one.spec.js @@ -835,5 +835,37 @@ describe('Choices - select one', () => { }); }); }); + + describe('dynamically setting choice by value', () => { + const dynamicallySelectedChoiceValue = 'Choice 2'; + + it('selects choice', () => { + cy.get('[data-test-hook=set-choice-by-value]') + .find('.choices__list--single .choices__item') + .last() + .should($choice => { + expect($choice.text().trim()).to.equal( + dynamicallySelectedChoiceValue, + ); + }); + }); + + it('does not remove choice from dropdown list', () => { + cy.get('[data-test-hook=set-choice-by-value]') + .find('.choices__list--dropdown .choices__list') + .then($choicesList => { + expect($choicesList).to.contain(dynamicallySelectedChoiceValue); + }); + }); + + it('updates the value of the original input', () => { + cy.get('[data-test-hook=set-choice-by-value]') + .find('.choices__input.is-hidden') + .should($select => { + const val = $select.val() || []; + expect(val).to.contain(dynamicallySelectedChoiceValue); + }); + }); + }); }); }); diff --git a/public/test/select-multiple.html b/public/test/select-multiple.html index 54e0561..5b1d1dc 100644 --- a/public/test/select-multiple.html +++ b/public/test/select-multiple.html @@ -185,6 +185,15 @@ + +