mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-19 02:49:18 -05:00
UI: Fix initial rendering of ToggleButton values for nested params (#30960)
* fix initial toggle of nested params * use get from @ember/object * add changelog * add test for optionalText
This commit is contained in:
parent
e80d0ac68c
commit
ad93d78ede
3 changed files with 33 additions and 2 deletions
3
changelog/30960.txt
Normal file
3
changelog/30960.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
ui: Fix initial setting of form toggle inputs for parameters nested within the `config` block
|
||||
```
|
||||
|
|
@ -14,6 +14,7 @@ import { addToArray } from 'vault/helpers/add-to-array';
|
|||
import { removeFromArray } from 'vault/helpers/remove-from-array';
|
||||
import { isEmpty } from '@ember/utils';
|
||||
import { presence } from 'vault/utils/forms/validators';
|
||||
import { get } from '@ember/object';
|
||||
|
||||
/**
|
||||
* @module FormField
|
||||
|
|
@ -82,7 +83,7 @@ export default class FormFieldComponent extends Component {
|
|||
);
|
||||
assert('@name is required', presence(attr.name));
|
||||
assert('@model (or resource object being updated) is required', presence(model));
|
||||
const modelValue = model[valuePath];
|
||||
const modelValue = get(model, valuePath);
|
||||
this.showToggleTextInput = !!modelValue;
|
||||
this.toggleInputEnabled = !!modelValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ module('Integration | Component | form field', function (hooks) {
|
|||
test('it renders: toggleButton', async function (assert) {
|
||||
const [model, spy] = await setup.call(
|
||||
this,
|
||||
createAttr('foobar', 'toggleButton', {
|
||||
createAttr('foobar', 'boolean', {
|
||||
defaultValue: false,
|
||||
editType: 'toggleButton',
|
||||
helperTextEnabled: 'Toggled on',
|
||||
|
|
@ -187,6 +187,33 @@ module('Integration | Component | form field', function (hooks) {
|
|||
assert.ok(spy.calledWith('foobar', true), 'onChange called with correct args');
|
||||
});
|
||||
|
||||
test('it sets nested attribute value for toggleButton', async function (assert) {
|
||||
this.setProperties({
|
||||
attr: createAttr('config.foo', 'boolean', {
|
||||
editType: 'toggleButton',
|
||||
defaultValue: false,
|
||||
}),
|
||||
model: { config: { foo: true } },
|
||||
onChange: () => {},
|
||||
});
|
||||
await render(hbs`<FormField @attr={{this.attr}} @model={{this.model}} @onChange={{this.onChange}} />`);
|
||||
assert.dom(GENERAL.toggleInput('toggle-config.foo')).isChecked();
|
||||
});
|
||||
|
||||
test('it sets nested attribute value for optionalText', async function (assert) {
|
||||
this.setProperties({
|
||||
attr: createAttr('foo.bar', 'string', {
|
||||
editType: 'optionalText',
|
||||
defaultValue: 'lemon',
|
||||
}),
|
||||
model: { foo: { bar: 'apple' } },
|
||||
onChange: () => {},
|
||||
});
|
||||
await render(hbs`<FormField @attr={{this.attr}} @model={{this.model}} @onChange={{this.onChange}} />`);
|
||||
assert.dom(GENERAL.toggleInput('show-foo.bar')).isChecked();
|
||||
assert.dom(GENERAL.inputByAttr('foo.bar')).hasValue('apple');
|
||||
});
|
||||
|
||||
test('it renders: editType file', async function (assert) {
|
||||
const subText = 'My subtext.';
|
||||
await setup.call(this, createAttr('foo', 'string', { editType: 'file', subText, docLink: '/docs' }));
|
||||
|
|
|
|||
Loading…
Reference in a new issue