From 20851f7240f3a5870e7930c12f9e6f8d27b81007 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 8 Jul 2022 13:00:33 +0200 Subject: [PATCH] FIX: Inputs using focusout regressed in #17345 (#17389) --- .../addon/components/secret-value-list.js | 10 ++++- .../admin/addon/components/simple-list.js | 6 +-- .../admin/addon/components/value-list.js | 4 +- .../components/secret-value-list.hbs | 4 +- .../templates/components/simple-list.hbs | 2 +- .../addon/templates/components/value-list.hbs | 2 +- .../components/secret-value-list-test.js | 40 ++++++++++++++++++- .../components/simple-list-test.js | 29 +++++++++++++- .../integration/components/value-list-test.js | 21 +++++++++- 9 files changed, 104 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/admin/addon/components/secret-value-list.js b/app/assets/javascripts/admin/addon/components/secret-value-list.js index ab79dad3671..1f31dc40e2f 100644 --- a/app/assets/javascripts/admin/addon/components/secret-value-list.js +++ b/app/assets/javascripts/admin/addon/components/secret-value-list.js @@ -22,17 +22,23 @@ export default Component.extend({ }, actions: { - changeKey(index, newValue) { + changeKey(index, event) { + const newValue = event.target.value; + if (this._checkInvalidInput(newValue)) { return; } + this._replaceValue(index, newValue, "key"); }, - changeSecret(index, newValue) { + changeSecret(index, event) { + const newValue = event.target.value; + if (this._checkInvalidInput(newValue)) { return; } + this._replaceValue(index, newValue, "secret"); }, diff --git a/app/assets/javascripts/admin/addon/components/simple-list.js b/app/assets/javascripts/admin/addon/components/simple-list.js index 46b8691e39b..5ca219ee80f 100644 --- a/app/assets/javascripts/admin/addon/components/simple-list.js +++ b/app/assets/javascripts/admin/addon/components/simple-list.js @@ -24,8 +24,8 @@ export default Component.extend({ }, @action - changeValue(index, newValue) { - this.collection.replace(index, 1, [newValue]); + changeValue(index, event) { + this.collection.replace(index, 1, [event.target.value]); this.collection.arrayContentDidChange(index); this._onChange(); }, @@ -65,7 +65,7 @@ export default Component.extend({ }, _onChange() { - this.attrs.onChange && this.attrs.onChange(this.collection); + this.onChange?.(this.collection); }, @discourseComputed("collection") diff --git a/app/assets/javascripts/admin/addon/components/value-list.js b/app/assets/javascripts/admin/addon/components/value-list.js index 57197548cb6..f7b61ed905f 100644 --- a/app/assets/javascripts/admin/addon/components/value-list.js +++ b/app/assets/javascripts/admin/addon/components/value-list.js @@ -39,8 +39,8 @@ export default Component.extend({ }, actions: { - changeValue(index, newValue) { - this._replaceValue(index, newValue); + changeValue(index, event) { + this._replaceValue(index, event.target.value); }, addValue(newValue) { diff --git a/app/assets/javascripts/admin/addon/templates/components/secret-value-list.hbs b/app/assets/javascripts/admin/addon/templates/components/secret-value-list.hbs index 8924af30ba8..a0aa6f2057d 100644 --- a/app/assets/javascripts/admin/addon/templates/components/secret-value-list.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/secret-value-list.hbs @@ -3,8 +3,8 @@ {{#each this.collection as |value index|}}
- - + +
{{/each}} diff --git a/app/assets/javascripts/admin/addon/templates/components/simple-list.hbs b/app/assets/javascripts/admin/addon/templates/components/simple-list.hbs index d3433879f9f..e0c4e862836 100644 --- a/app/assets/javascripts/admin/addon/templates/components/simple-list.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/simple-list.hbs @@ -4,7 +4,7 @@
- + {{#if this.showUpDownButtons}} diff --git a/app/assets/javascripts/admin/addon/templates/components/value-list.hbs b/app/assets/javascripts/admin/addon/templates/components/value-list.hbs index 7a2f12b5c3b..ac484043a85 100644 --- a/app/assets/javascripts/admin/addon/templates/components/value-list.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/value-list.hbs @@ -4,7 +4,7 @@
- + {{#if this.showUpDownButtons}} diff --git a/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js index 6590e15cbec..32f3bd17ebe 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js @@ -1,4 +1,4 @@ -import { click, fillIn } from "@ember/test-helpers"; +import { blur, click, fillIn } from "@ember/test-helpers"; import componentTest, { setupRenderingTest, } from "discourse/tests/helpers/component-test"; @@ -6,6 +6,7 @@ import { count, discourseModule, exists, + query, queryAll, } from "discourse/tests/helpers/qunit-helpers"; import I18n from "I18n"; @@ -88,6 +89,43 @@ discourseModule( }, }); + componentTest("changing a value", { + template: hbs`{{secret-value-list values=values}}`, + + async test(assert) { + this.set("values", "firstKey|FirstValue\nsecondKey|secondValue"); + + await fillIn( + ".values .value[data-index='1'] .value-input:first-of-type", + "changedKey" + ); + await blur(".values .value[data-index='1'] .value-input:first-of-type"); + + assert.strictEqual( + query(".values .value[data-index='1'] .value-input:first-of-type") + .value, + "changedKey" + ); + + await fillIn( + ".values .value[data-index='1'] .value-input:last-of-type", + "changedValue" + ); + await blur(".values .value[data-index='1'] .value-input:last-of-type"); + + assert.strictEqual( + query(".values .value[data-index='1'] .value-input:last-of-type") + .value, + "changedValue" + ); + assert.deepEqual( + this.values, + "firstKey|FirstValue\nchangedKey|changedValue", + "updates the value list" + ); + }, + }); + componentTest("removing a value", { template: hbs`{{secret-value-list values=values}}`, diff --git a/app/assets/javascripts/discourse/tests/integration/components/simple-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/simple-list-test.js index 59011fc2a8b..3ba4ad2f7db 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/simple-list-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/simple-list-test.js @@ -1,4 +1,10 @@ -import { click, fillIn, triggerKeyEvent } from "@ember/test-helpers"; +import { + blur, + click, + fillIn, + render, + triggerKeyEvent, +} from "@ember/test-helpers"; import componentTest, { setupRenderingTest, } from "discourse/tests/helpers/component-test"; @@ -9,6 +15,7 @@ import { query, } from "discourse/tests/helpers/qunit-helpers"; import hbs from "htmlbars-inline-precompile"; +import { test } from "qunit"; discourseModule("Integration | Component | simple-list", function (hooks) { setupRenderingTest(hooks); @@ -51,6 +58,26 @@ discourseModule("Integration | Component | simple-list", function (hooks) { }, }); + test("changing a value", async function (assert) { + const done = assert.async(); + + this.set("values", "vinkas\nosama"); + this.set("onChange", function (collection) { + assert.deepEqual(collection, ["vinkas", "jarek"]); + done(); + }); + + await render(hbs`{{simple-list values=values onChange=onChange}}`); + + await fillIn(".values .value[data-index='1'] .value-input", "jarek"); + await blur(".values .value[data-index='1'] .value-input"); + + assert.strictEqual( + query(".values .value[data-index='1'] .value-input").value, + "jarek" + ); + }); + componentTest("removing a value", { template: hbs`{{simple-list values=values}}`, diff --git a/app/assets/javascripts/discourse/tests/integration/components/value-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/value-list-test.js index 6ad51806b6f..80b9a39bda2 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/value-list-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/value-list-test.js @@ -6,7 +6,7 @@ import { discourseModule, query, } from "discourse/tests/helpers/qunit-helpers"; -import { click } from "@ember/test-helpers"; +import { blur, click, fillIn } from "@ember/test-helpers"; import hbs from "htmlbars-inline-precompile"; import selectKit from "discourse/tests/helpers/select-kit-helper"; @@ -39,6 +39,25 @@ discourseModule("Integration | Component | value-list", function (hooks) { }, }); + componentTest("changing a value", { + template: hbs`{{value-list values=values}}`, + + beforeEach() { + this.set("values", "vinkas\nosama"); + }, + + async test(assert) { + await fillIn(".values .value[data-index='1'] .value-input", "jarek"); + await blur(".values .value[data-index='1'] .value-input"); + + assert.strictEqual( + query(".values .value[data-index='1'] .value-input").value, + "jarek" + ); + assert.deepEqual(this.values, "vinkas\njarek", "updates the value list"); + }, + }); + componentTest("removing a value", { template: hbs`{{value-list values=values}}`,