mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:42:45 +08:00
DEV: Add simple test for json-schema-editor and remove extra await
(#27827)
Followup to ce3d91f422
This commit is contained in:
parent
55e5cd3b96
commit
a4aebc83ac
|
@ -6,6 +6,7 @@
|
|||
"admin.site_settings.json_schema.modal_title"
|
||||
name=@model.settingName
|
||||
}}
|
||||
@inline={{@inline}}
|
||||
class="json-schema-editor-modal"
|
||||
>
|
||||
<:body>
|
||||
|
|
|
@ -37,7 +37,7 @@ export default class JsonSchemaEditorModal extends Component {
|
|||
|
||||
@action
|
||||
async buildJsonEditor(element) {
|
||||
const promise = await import("@json-editor/json-editor");
|
||||
const promise = import("@json-editor/json-editor");
|
||||
if (isTesting()) {
|
||||
waitForPromise(promise);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import { click, fillIn, render } from "@ember/test-helpers";
|
||||
import { module, test } from "qunit";
|
||||
import JsonSchemaEditor from "discourse/components/modal/json-schema-editor";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
|
||||
const TEST_SCHEMA = {
|
||||
type: "array",
|
||||
uniqueItems: true,
|
||||
items: {
|
||||
type: "object",
|
||||
properties: { color: { type: "string" }, icon: { type: "string" } },
|
||||
additionalProperties: false,
|
||||
},
|
||||
};
|
||||
|
||||
module("Unit | Component | <JsonSchemaEditor />", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("modal functions correctly", async function (assert) {
|
||||
let result;
|
||||
const model = {
|
||||
value: "[]",
|
||||
settingName: "My setting name",
|
||||
jsonSchema: TEST_SCHEMA,
|
||||
updateValue: (val) => (result = val),
|
||||
};
|
||||
|
||||
const closeModal = () => {};
|
||||
|
||||
await render(<template>
|
||||
<JsonSchemaEditor
|
||||
@inline={{true}}
|
||||
@model={{model}}
|
||||
@closeModal={{closeModal}}
|
||||
/>
|
||||
</template>);
|
||||
|
||||
await click(".json-editor-btn-add");
|
||||
await fillIn("[name='root[0][color]']", "red");
|
||||
await click(".d-modal__footer .btn-primary");
|
||||
|
||||
assert.deepEqual(JSON.parse(result), [{ color: "red", icon: "" }]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user