DEV: Add simple test for json-schema-editor and remove extra await (#27827)

Followup to ce3d91f422
This commit is contained in:
David Taylor 2024-07-10 12:22:31 +01:00 committed by GitHub
parent 55e5cd3b96
commit a4aebc83ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 1 deletions

View File

@ -6,6 +6,7 @@
"admin.site_settings.json_schema.modal_title"
name=@model.settingName
}}
@inline={{@inline}}
class="json-schema-editor-modal"
>
<:body>

View File

@ -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);
}

View File

@ -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: "" }]);
});
});