DEV: Use Category's async method in param-input (#310)

This commit refactors the category id normalization of param-input to
use `Category.asyncFindBySlugPath`.

Now, the category id input will use an async query when the
default/initial value is category slug.

Co-authored-by: Natalie <[email protected]>
This commit is contained in:
锦心
2024-08-21 15:41:02 +08:00
committed by GitHub
co-authored by Natalie
parent 1d991c6192
commit b47ba7ea60
5 changed files with 121 additions and 67 deletions
@@ -60,7 +60,7 @@ const InputTestCases = [
tests: [
{
input: null,
data_null: undefined,
data_null: "",
error: ERRORS.REQUIRED,
},
{
@@ -111,8 +111,9 @@ module("Data Explorer Plugin | Component | param-input", function (hooks) {
initialValues: config.initial
? { [testcase.type]: config.initial }
: {},
onRegisterApi: ({ submit }) => {
onRegisterApi: ({ submit, allNormalized }) => {
this.submit = submit;
this.allNormalized = allNormalized;
},
});
@@ -124,6 +125,8 @@ module("Data Explorer Plugin | Component | param-input", function (hooks) {
@onRegisterApi={{this.onRegisterApi}}
/>`);
await this.allNormalized;
if (config.initial || config.default) {
const data = await this.submit();
const val = config.initial || config.default;
@@ -201,4 +204,34 @@ module("Data Explorer Plugin | Component | param-input", function (hooks) {
await fillIn(`[name="string"]`, "");
assert.rejects(this.submit());
});
test("async normalizion", async function (assert) {
this.setProperties({
param_info: [
{
identifier: "category_id",
type: "category_id",
default: "support",
nullable: false,
},
],
initialValues: {},
onRegisterApi: (paramInputApi) => {
this.paramInputApi = paramInputApi;
},
});
await render(hbs`
<ParamInputForm
@initialValues={{this.initialValues}}
@paramInfo={{this.param_info}}
@onRegisterApi={{this.onRegisterApi}}
/>`);
await this.paramInputApi.allNormalized;
this.paramInputApi.submit().then((res) => {
assert.strictEqual(res.category_id, "1003");
});
});
});