diff --git a/ui/app/components/variable-form.hbs b/ui/app/components/variable-form.hbs index 6bb2e1127..852696195 100644 --- a/ui/app/components/variable-form.hbs +++ b/ui/app/components/variable-form.hbs @@ -40,6 +40,7 @@ @value={{this.path}} placeholder="nomad/jobs/my-job/my-group/my-task" class="input path-input {{if this.duplicatePathWarning "error"}}" + {{on "input" this.setModelPath}} disabled={{not @model.isNew}} {{autofocus}} data-test-path-input diff --git a/ui/app/components/variable-form.js b/ui/app/components/variable-form.js index 51e92b240..fe47f2b03 100644 --- a/ui/app/components/variable-form.js +++ b/ui/app/components/variable-form.js @@ -168,6 +168,14 @@ export default class VariableFormComponent extends Component { this.save(e, true); } + /** + * + * @param {KeyboardEvent} e + */ + @action setModelPath(e) { + set(this.args.model, 'path', e.target.value); + } + @action async save(e, overwrite = false) { if (e.type === 'submit') { diff --git a/ui/tests/acceptance/variables-test.js b/ui/tests/acceptance/variables-test.js index d50966fc2..3c5e9b846 100644 --- a/ui/tests/acceptance/variables-test.js +++ b/ui/tests/acceptance/variables-test.js @@ -145,7 +145,7 @@ module('Acceptance | variables', function (hooks) { }); test('variables prefixed with nomad/jobs/ correctly link to entities', async function (assert) { - assert.expect(23); + assert.expect(29); allScenarios.variableTestCluster(server); const variablesToken = server.db.tokens.find(VARIABLE_TOKEN_ID); @@ -313,6 +313,45 @@ module('Acceptance | variables', function (hooks) { assert .dom('[data-test-task-stat="variables"]') .doesNotExist('Link from Variable-less Job to Variable does not exist'); + + // Related Entities during the Variable creation process + await Variables.visitNew(); + assert + .dom('.related-entities.notification') + .doesNotExist('Related Entities notification is not present by default'); + await typeIn('[data-test-path-input]', 'foo/bar'); + assert + .dom('.related-entities.notification') + .doesNotExist( + 'Related Entities notification is not present when path is generic' + ); + document.querySelector('[data-test-path-input]').value = ''; // clear path input + await typeIn('[data-test-path-input]', 'nomad/jobs/abc'); + assert + .dom('.related-entities.notification') + .exists( + 'Related Entities notification is present when path is job-oriented' + ); + assert + .dom('.related-entities.notification') + .containsText( + 'This variable will be accessible by job', + 'Related Entities notification is job-oriented' + ); + await typeIn('[data-test-path-input]', '/def'); + assert + .dom('.related-entities.notification') + .containsText( + 'This variable will be accessible by group', + 'Related Entities notification is group-oriented' + ); + await typeIn('[data-test-path-input]', '/ghi'); + assert + .dom('.related-entities.notification') + .containsText( + 'This variable will be accessible by task', + 'Related Entities notification is task-oriented' + ); }); test('it does not allow you to save if you lack Items', async function (assert) {