mirror of
https://github.com/discourse/discourse.git
synced 2025-01-16 04:02:40 +08:00
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:
parent
9618075b9c
commit
4d32635c69
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user