From 72ca731d25a967f9d6b58b356ff18ab9f0643881 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 20 Apr 2020 21:50:55 +0200 Subject: [PATCH] fix unique dropdown for multi-select select boxes --- cypress/integration/select-multiple.spec.ts | 35 +++++++++++++++++++++ public/test/select-multiple/index.html | 20 ++++++++++++ src/scripts/choices.ts | 7 ++--- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/cypress/integration/select-multiple.spec.ts b/cypress/integration/select-multiple.spec.ts index 90e096b7e..973b877cf 100644 --- a/cypress/integration/select-multiple.spec.ts +++ b/cypress/integration/select-multiple.spec.ts @@ -277,6 +277,41 @@ describe('Choices - select multiple', () => { }); }); + describe('unique values only', () => { + describe('unique values', () => { + beforeEach(() => { + cy.get('[data-test-hook=unique-values]') + .find('.choices__input--cloned') + .type('Choice 1') + .type('{enter}'); + }); + + it('only allows me to input unique values', () => { + cy.get('[data-test-hook=unique-values]') + .find('.choices__list--multiple') + .first() + .children() + .should($items => { + expect($items.length).to.equal(1); + }); + }); + + describe('inputting a non-unique value', () => { + it('displays dropdown prompt', () => { + cy.get('[data-test-hook=unique-values]') + .find('.choices__list--dropdown') + .should('be.visible') + .should($dropdown => { + const dropdownText = $dropdown.text().trim(); + expect(dropdownText).to.equal( + 'Only unique values can be added', + ); + }); + }); + }); + }); + }); + describe('disabled choice', () => { describe('selecting a disabled choice', () => { beforeEach(() => { diff --git a/public/test/select-multiple/index.html b/public/test/select-multiple/index.html index b1e0d0256..6139ffbac 100644 --- a/public/test/select-multiple/index.html +++ b/public/test/select-multiple/index.html @@ -88,6 +88,22 @@

Select multiple inputs

+
+ + +
+