A platform for community discussion. Free, open, simple.
DEV: Await for ace render in tests (#28586)
Jarek Radosz480f26a2c205
diff --git a/app/assets/javascripts/discourse/app/components/ace-editor.gjs b/app/assets/javascripts/discourse/app/components/ace-editor.gjsindex a3aad9981d3..213ffda552e 100644--- a/app/assets/javascripts/discourse/app/components/ace-editor.gjs+++ b/app/assets/javascripts/discourse/app/components/ace-editor.gjs@@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";import didInsert from "@ember/render-modifiers/modifiers/did-insert";import didUpdate from "@ember/render-modifiers/modifiers/did-update";import { service } from "@ember/service";+import { registerWaiter } from "@ember/test";import { modifier } from "ember-modifier";import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";import loadAce from "discourse/lib/load-ace-editor";@@ -70,6 +71,12 @@ export default class AceEditor extends Component {this.skipChangePropagation = true;this.editor.getSession().setValue(this.args.content || "");this.skipChangePropagation = false;++ if (isTesting()) {+ let finished = false;+ registerWaiter(() => finished);+ this.editor.renderer.once("afterRender", () => (finished = true));+ }});constructor() {@@ -165,7 +172,7 @@ export default class AceEditor extends Component {@bindeditorIdChanged() {if (this.autofocus) {- this.send("focus");+ this.focus();}}diff --git a/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.gjsindex 880f5ef09e5..d1ce7d1eb87 100644--- a/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.gjs+++ b/app/assets/javascripts/discourse/tests/integration/components/ace-editor-test.gjs@@ -7,34 +7,52 @@ module("Integration | Component | ace-editor", function (hooks) {setupRenderingTest(hooks);test("css editor", async function (assert) {- await render(<template><AceEditor @mode="css" /></template>);+ await render(<template>+ <AceEditor @mode="css" style="width: 300px; height: 200px" />+ </template>);assert.dom(".ace_editor").exists("it renders the ace editor");});test("html editor", async function (assert) {await render(<template>- <AceEditor @mode="html" @content="<b>wat</b>" />+ <AceEditor+ @mode="html"+ @content="<b>wat</b>"+ style="width: 300px; height: 200px"+ /></template>);assert.dom(".ace_editor").exists("it renders the ace editor");});test("sql editor", async function (assert) {await render(<template>- <AceEditor @mode="sql" @content="SELECT * FROM users" />+ <AceEditor+ @mode="sql"+ @content="SELECT * FROM users"+ style="width: 300px; height: 200px"+ /></template>);assert.dom(".ace_editor").exists("it renders the ace editor");});test("yaml editor", async function (assert) {await render(<template>- <AceEditor @mode="yaml" @content="test: true" />+ <AceEditor+ @mode="yaml"+ @content="test: true"+ style="width: 300px; height: 200px"+ /></template>);assert.dom(".ace_editor").exists("it renders the ace editor");});test("javascript editor", async function (assert) {await render(<template>- <AceEditor @mode="javascript" @content="test: true" />+ <AceEditor+ @mode="javascript"+ @content="test: true"+ style="width: 300px; height: 200px"+ /></template>);assert.dom(".ace_editor").exists("it renders the ace editor");});@@ -45,6 +63,7 @@ module("Integration | Component | ace-editor", function (hooks) {@mode="sql"@content="SELECT * FROM users"@disabled={{true}}+ style="width: 300px; height: 200px"/></template>);diff --git a/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/code-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/code-test.gjsindex 0032105c2e3..344aecfc72e 100644--- a/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/code-test.gjs+++ b/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/code-test.gjs@@ -14,7 +14,7 @@ module("Integration | Component | FormKit | Controls | Code", function (hooks) {await render(<template><Form @onSubmit={{mutateData}} @data={{data}} as |form|><form.Field @name="foo" @title="Foo" as |field|>- <field.Code />+ <field.Code @height={{100}} style="width: 200px" /></form.Field></Form></template>);