FEATURE: default value to fields in automation

This PR adds the property `extra.default_value` to the fields in automation. This property is used to set the default value of the field.

Reducing the nil checks we have to do in automation fields.

I've added only testing in the `da-choices-field-test.js` file, but we could add tests to all the fields.
This commit is contained in:
Gabriel Grubba 2024-12-19 18:17:38 -03:00
parent 9618075b9c
commit 4d32635c69
No known key found for this signature in database
GPG Key ID: 5FE41764F62D556C
2 changed files with 31 additions and 0 deletions

View File

@ -2,6 +2,14 @@ import Component from "@glimmer/component";
import { action } from "@ember/object";
export default class BaseField extends Component {
constructor() {
super(...arguments);
if (this.args.field.extra?.default_value) {
this.args.field.metadata.value = this.args.field.extra.default_value;
}
}
get displayPlaceholders() {
return (
this.args.placeholders?.length && this.args.field?.acceptsPlaceholders

View File

@ -28,4 +28,27 @@ module("Integration | Component | da-choices-field", function (hooks) {
assert.strictEqual(this.field.metadata.value, 1);
});
test("can have a default value", async function (assert) {
this.field = new AutomationFabricators(getOwner(this)).field({
component: "choices",
extra: {
content: [
{ name: "Zero", id: 0 },
{ name: "One", id: 1 },
],
default_value: 0,
},
});
await render(
hbs` <AutomationField @automation={{this.automation}} @field={{this.field}} />`
);
assert.strictEqual(this.field.metadata.value, 0);
await selectKit().expand();
await selectKit().selectRowByValue(1);
assert.strictEqual(this.field.metadata.value, 1);
});
});