diff --git a/cypress/integration/select-multiple.spec.js b/cypress/integration/select-multiple.spec.js index c6bdbff..67123f0 100644 --- a/cypress/integration/select-multiple.spec.js +++ b/cypress/integration/select-multiple.spec.js @@ -414,5 +414,48 @@ describe('Choices - select multiple', () => { }); }); }); + + describe('remote data', () => { + beforeEach(() => { + cy.reload(true); + }); + + describe('when loading data', () => { + it('shows a loading message as a placeholder', () => { + cy.get('[data-test-hook=remote-data]') + .find('.choices__input--cloned') + .should('have.attr', 'placeholder', 'Loading...'); + }); + + describe('opening the dropdown', () => { + it('displays "no choices to choose" prompt', () => { + cy.get('[data-test-hook=remote-data]').click(); + cy.get('[data-test-hook=remote-data]') + .find('.choices__list--dropdown') + .should('be.visible') + .should($dropdown => { + const dropdownText = $dropdown.text().trim(); + expect(dropdownText).to.equal('No choices to choose from'); + }); + }); + }); + }); + + describe('when data has loaded', () => { + describe('opening the dropdown', () => { + it('displays the loaded data', () => { + cy.wait(2000); + cy.get('[data-test-hook=remote-data]') + .find('.choices__list--dropdown .choices__list') + .children() + .should('have.length', 50) + .each(($choice, index) => { + expect($choice.text().trim()).to.equal(`Label ${index + 1}`); + expect($choice.data('value')).to.equal(`Value ${index + 1}`); + }); + }); + }); + }); + }); }); }); diff --git a/cypress/integration/select-one.spec.js b/cypress/integration/select-one.spec.js index 7dbb77f..edaed62 100644 --- a/cypress/integration/select-one.spec.js +++ b/cypress/integration/select-one.spec.js @@ -351,5 +351,53 @@ describe('Choices - select one', () => { }); }); }); + + describe('remote data', () => { + beforeEach(() => { + cy.reload(true); + }); + + describe('when loading data', () => { + it('shows a loading message as a placeholder', () => { + cy.get('[data-test-hook=remote-data]') + .find('.choices__list--single') + .children() + .first() + .should('have.class', 'choices__placeholder') + .and($placeholder => { + expect($placeholder).to.contain('Loading...'); + }); + }); + + describe('opening the dropdown', () => { + it('displays "no choices to choose" prompt', () => { + cy.get('[data-test-hook=remote-data]').click(); + cy.get('[data-test-hook=remote-data]') + .find('.choices__list--dropdown') + .should('be.visible') + .should($dropdown => { + const dropdownText = $dropdown.text().trim(); + expect(dropdownText).to.equal('No choices to choose from'); + }); + }); + }); + }); + + describe('when data has loaded', () => { + describe('opening the dropdown', () => { + it('displays the loaded data', () => { + cy.wait(2000); + cy.get('[data-test-hook=remote-data]') + .find('.choices__list--dropdown .choices__list') + .children() + .should('have.length', 50) + .each(($choice, index) => { + expect($choice.text().trim()).to.equal(`Label ${index + 1}`); + expect($choice.data('value')).to.equal(`Value ${index + 1}`); + }); + }); + }); + }); + }); }); }); diff --git a/public/test/select-multiple.html b/public/test/select-multiple.html index 73a5ebc..c9e50b5 100644 --- a/public/test/select-multiple.html +++ b/public/test/select-multiple.html @@ -106,6 +106,11 @@ + +