From 013058dd7f6a04c1bfebf4a45b91d9b64117a25f Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Sat, 27 Oct 2018 20:03:53 +0100 Subject: [PATCH] Update readme to document multiple instances --- README.md | 5 +++- cypress/integration/text.spec.js | 40 ++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c4f549..0c95d54 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,12 @@ Or include Choices directly: ``` ## Setup +If you pass a selector which targets multiple elements, an array of Choices instances +will be returned. If you target one element, that instance will be returned. + ```js // Pass multiple elements: - const choices = new Choices(elements); + const [firstInstance, secondInstance] = new Choices(elements); // Pass single element: const choices = new Choices(element); diff --git a/cypress/integration/text.spec.js b/cypress/integration/text.spec.js index 961eb4a..4cb5279 100644 --- a/cypress/integration/text.spec.js +++ b/cypress/integration/text.spec.js @@ -55,10 +55,12 @@ describe('Choices - text element', () => { describe('editing items', () => { beforeEach(() => { - cy.get('[data-test-hook=edit-items]') - .find('.choices__input--cloned') - .type(textInput) - .type('{enter}'); + for (let index = 0; index < 3; index++) { + cy.get('[data-test-hook=edit-items]') + .find('.choices__input--cloned') + .type(textInput) + .type('{enter}'); + } }); describe('on back space', () => { @@ -77,6 +79,36 @@ describe('Choices - text element', () => { }); }); }); + + describe('on cmd+a', () => { + beforeEach(() => { + cy.get('[data-test-hook=edit-items]') + .find('.choices__input--cloned') + .type('{cmd}a'); + }); + + it('highlights all items', () => { + cy.get('[data-test-hook=edit-items]') + .find('.choices__list--multiple .choices__item') + .each($choice => { + expect($choice.hasClass('is-highlighted')).to.equal(true); + }); + }); + + describe('on backspace', () => { + it('clears all inputted values', () => { + // two backspaces are needed as Cypress has an issue where + // it will also insert an 'a' character into the text input + cy.get('[data-test-hook=edit-items]') + .find('.choices__input--cloned') + .type('{backspace}{backspace}'); + + cy.get('[data-test-hook=edit-items]') + .find('.choices__list--multiple .choices__item') + .should('have.length', 0); + }); + }); + }); }); describe('remove button', () => {