From 1013f32ce646880d6d675b60b92c0981caa978d0 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 2 Aug 2017 14:14:08 +0100 Subject: [PATCH] A few tests --- assets/scripts/src/choices.js | 3 ++- tests/spec/choices_spec.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index cf780b6..834e0c6 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -2737,6 +2737,7 @@ class Choices { const dropdown = this._getTemplate('dropdown'); const placeholder = this.config.placeholder ? this.config.placeholderValue || + this.config.searchPlaceholderValue || this.passedElement.getAttribute('placeholder') : false; @@ -2782,7 +2783,7 @@ class Choices { // If select one element with a search placeholder value if (this.config.searchPlaceholderValue) { input.placeholder = this.config.searchPlaceholderValue; - } else { + } else if (this.placeholder) { const placeholderItem = this._getTemplate('placeholder', this.placeholder); this.itemList.appendChild(placeholderItem); } diff --git a/tests/spec/choices_spec.js b/tests/spec/choices_spec.js index 181ef06..2a04178 100644 --- a/tests/spec/choices_spec.js +++ b/tests/spec/choices_spec.js @@ -523,7 +523,7 @@ describe('Choices', () => { ctrlKey: false }); - const activeOptions = this.choices.currentState.choices.filter(function (choice) { + const activeOptions = this.choices.currentState.choices.filter(function(choice) { return choice.active; }); @@ -566,6 +566,15 @@ describe('Choices', () => { expect(this.choices.currentState.choices[0].value).toEqual('Value 1'); }); + + it('should set searchPlaceholderValue if set', function() { + const dummyPlaceholder = 'Test placeholder'; + this.choices = new Choices(this.input, { + searchPlaceholderValue: dummyPlaceholder + }); + + expect(this.choices.input.placeholder).toEqual(dummyPlaceholder); + }); }); describe('should accept multiple select inputs', function() {