From 89d9704194c837f027f428fc370247c52e361266 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Fri, 14 Feb 2020 11:21:06 -0500 Subject: [PATCH] FIX: value-list choices when removing a value Fixes an issue where choices were broken when removing an item from the value-list component. Adds test case for this scenario. --- app/assets/javascripts/admin/components/value-list.js.es6 | 5 ++--- test/javascripts/components/value-list-test.js.es6 | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/components/value-list.js.es6 b/app/assets/javascripts/admin/components/value-list.js.es6 index 99f1cc00d4..fe79b686ce 100644 --- a/app/assets/javascripts/admin/components/value-list.js.es6 +++ b/app/assets/javascripts/admin/components/value-list.js.es6 @@ -73,11 +73,10 @@ export default Component.extend({ _removeValue(value) { this.collection.removeObject(value); - const item = { id: value, name: value }; if (this.choices) { - this.choices.addObject(item); + this.set("choices", this.choices.push(value).uniq()); } else { - this.set("choices", makeArray(item)); + this.set("choices", makeArray(value)); } this._saveValues(); diff --git a/test/javascripts/components/value-list-test.js.es6 b/test/javascripts/components/value-list-test.js.es6 index 0c605ef076..15365e2225 100644 --- a/test/javascripts/components/value-list-test.js.es6 +++ b/test/javascripts/components/value-list-test.js.es6 @@ -45,6 +45,14 @@ componentTest("removing a value", { ); assert.equal(this.values, "osama", "it removes the expected value"); + + await selectKit().expand(); + + assert.ok( + find(".select-kit-collection li.select-kit-row span.name")[0] + .innerText === "vinkas", + "it adds the removed value to choices" + ); } });