From 561a61de0f1a31bca9d3cc45d7af4c15ee32badc 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/e2e/select-multiple.spec.ts | 35 ++++++++++++++++++++++++++ public/test/select-multiple/index.html | 19 ++++++++++++++ src/scripts/choices.ts | 12 ++++----- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/select-multiple.spec.ts b/cypress/e2e/select-multiple.spec.ts index a00e9ec..5570904 100644 --- a/cypress/e2e/select-multiple.spec.ts +++ b/cypress/e2e/select-multiple.spec.ts @@ -282,6 +282,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 756e771..cede1c8 100644 --- a/public/test/select-multiple/index.html +++ b/public/test/select-multiple/index.html @@ -88,6 +88,22 @@ +
+ + +
+