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:
@@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user