From 0ab2215cdf3bdc56b77b06cd96bc016eb790c089 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Fri, 11 May 2018 14:00:56 -0600 Subject: [PATCH] Prevent entering an existing option in the "Other" dialog Closes #75 --- _src/app/OtherOptionHandler.js | 6 ++++-- _src/app/tests/spec/SpecOtherOptionHandler.js | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/_src/app/OtherOptionHandler.js b/_src/app/OtherOptionHandler.js index 729a3845..2269e092 100644 --- a/_src/app/OtherOptionHandler.js +++ b/_src/app/OtherOptionHandler.js @@ -84,9 +84,11 @@ define([ // event: Event Object console.log('app/OtherOptionHandler:onTxtChange', arguments); - this.submitBtn.disabled = !(this.codeTxt.value.length > 0); + const value = this.codeTxt.value.toUpperCase(); + this.submitBtn.disabled = !value || !(value.length > 0) || + this.existingOptions.map(v => v.toUpperCase()).includes(value); - if (event.key === 'Enter') { + if (!this.submitBtn.disabled && event.key === 'Enter') { this.onSubmit(); } }, diff --git a/_src/app/tests/spec/SpecOtherOptionHandler.js b/_src/app/tests/spec/SpecOtherOptionHandler.js index e035987b..da341eaa 100644 --- a/_src/app/tests/spec/SpecOtherOptionHandler.js +++ b/_src/app/tests/spec/SpecOtherOptionHandler.js @@ -18,7 +18,8 @@ require([ widget = null; }; var select; - var options = ['code1', 'code2', 'code3']; + const code1 = 'code1'; + var options = [code1, 'code2', 'code3']; beforeEach(function () { select = domConstruct.create('select', {}, win.body()); @@ -57,5 +58,15 @@ require([ testWidget.onSubmit(); }); }); + + describe('onTxtChange', function () { + it('does not allow for an existing value to be submitted', function () { + testWidget.codeTxt.value = code1.toUpperCase(); + + testWidget.onTxtChange({}); + + expect(testWidget.submitBtn.disabled).toBe(true); + }); + }); }); });