From cb4cfaf60d76866a01da0310463bb7e7a8e12ae0 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 21 Aug 2024 10:40:41 +0200 Subject: [PATCH] Fix magic env var value auto-splitting The `companionField` in handleEnvValue() is meant to be the *other* (key/value) field. It doesn't make sense to specify its own value, that just looked like a copy&paste error from the *-key input handler. With that you can type "FOO=bar" and get the automatic split. The test "cheated" with `set_val()` which sets all letters atomically. Test "RHUBARB=STRAWBERRY" separately with proper keyboard input. Splitting muliple variables can only work with an atomic value setting, i.e. the user doing copy&paste. Keep the `set_val()` bit and explain it, and also validate that the fields get created and split as expected. --- src/Env.jsx | 2 +- test/check-application | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Env.jsx b/src/Env.jsx index 6e70c9a43..b35ea2f09 100644 --- a/src/Env.jsx +++ b/src/Env.jsx @@ -81,7 +81,7 @@ export const EnvVar = ({ id, item, onChange, idx, removeitem, additem, itemCount onChange={(_event, value) => { utils.validationClear(validationFailed, "envValue", onValidationChange); utils.validationDebounce(() => onValidationChange({ ...validationFailed, envValue: validateEnvVar(value, "envValue") })); - handleEnvValue('envValue', value, idx, onChange, additem, itemCount, item.envValue); + handleEnvValue('envValue', value, idx, onChange, additem, itemCount, item.envKey); }} /> diff --git a/test/check-application b/test/check-application index 0c6bd26af..1c4f012b4 100755 --- a/test/check-application +++ b/test/check-application @@ -1928,11 +1928,22 @@ class TestApplication(testlib.MachineCase): b.set_input_text('#run-image-dialog-env-2-value', 'GRAPE') b.click('#run-image-dialog-env-2-btn-close') b.click('.env-form .btn-add') - # Test inputting an key=var entry - b.set_val('#run-image-dialog-env-3-value', - "RHUBARB=STRAWBERRY DURIAN=LEMON TEST_URL=wss://cockpit/?start=1&stop=0") + # Test inputting an key=var entry; that should auto-split on '=' + b.set_input_text('#run-image-dialog-env-3-value', "RHUBARB=STRAWBERRY", value_check=False) + b.wait_val("#run-image-dialog-env-3-key", "RHUBARB") + b.wait_val("#run-image-dialog-env-3-value", "STRAWBERRY") + + # with copy&paste you can also set multiple variables + b.click('.env-form .btn-add') + b.set_val('#run-image-dialog-env-4-value', + "DURIAN=LEMON TEST_URL=wss://cockpit/?start=1&stop=0") # set_val does not trigger onChange so append a space. - b.set_input_text('#run-image-dialog-env-3-value', ' ', append=True, value_check=False) + b.set_input_text('#run-image-dialog-env-4-value', ' ', append=True, value_check=False) + + b.wait_val("#run-image-dialog-env-4-key", "DURIAN") + b.wait_val("#run-image-dialog-env-4-value", "LEMON") + b.wait_val("#run-image-dialog-env-5-key", "TEST_URL") + b.wait_val("#run-image-dialog-env-5-value", "wss://cockpit/?start=1&stop=0") b.click('.env-form .btn-add') b.set_input_text('#run-image-dialog-env-6-key', 'HOSTNAME')