Skip to content

A platform for community discussion. Free, open, simple.

DEV: Correctly test post-cooked "widget" (#23806)

Jarek Radosza27823fd3c7c
diff --git a/app/assets/javascripts/discourse/app/components/mount-widget.js b/app/assets/javascripts/discourse/app/components/mount-widget.js
index 4fd888112ac..5e366eecb4e 100644
--- a/app/assets/javascripts/discourse/app/components/mount-widget.js
+++ b/app/assets/javascripts/discourse/app/components/mount-widget.js
@@ -47,6 +47,21 @@ export default Component.extend({
this._super(...arguments);
const name = this.widget;
+ if (name === "post-cooked") {
+ throw [
+ "Cannot use <MountWidget /> with `post-cooked`.",
+ "It's a special-case that needs to be wrapped in another widget.",
+ "For example:",
+ " createWidget('test-widget', {",
+ " html(attrs) {",
+ " return [",
+ " new PostCooked(attrs, new DecoratorHelper(this), this.currentUser),",
+ " ];",
+ " },",
+ " });",
+ ].join("\n");
+ }
+
this.register = getRegister(this);
this._widgetClass =
diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-cooked-test.js b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-cooked-test.js
index a1413dcd869..f2adc7bc012 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-cooked-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-cooked-test.js
@@ -1,23 +1,31 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { render } from "@ember/test-helpers";
-import { query } from "discourse/tests/helpers/qunit-helpers";
import { hbs } from "ember-cli-htmlbars";
+import DecoratorHelper from "discourse/widgets/decorator-helper";
+import PostCooked from "discourse/widgets/post-cooked";
+import { createWidget } from "discourse/widgets/widget";
module("Integration | Component | Widget | post-cooked", function (hooks) {
setupRenderingTest(hooks);
test("quotes with no username and no valid topic", async function (assert) {
- this.siteSettings.show_copy_button_on_codeblocks = false;
-
this.set("args", {
cooked: `<aside class=\"quote no-group quote-post-not-found\" data-post=\"1\" data-topic=\"123456\">\n<blockquote>\n<p>abcd</p>\n</blockquote>\n</aside>\n<p>Testing the issue</p>`,
});
+ createWidget("test-widget", {
+ html(attrs) {
+ return [
+ new PostCooked(attrs, new DecoratorHelper(this), this.currentUser),
+ ];
+ },
+ });
+
await render(
- hbs`<MountWidget @widget="post-cooked" @args={{this.args}} />`
+ hbs`<MountWidget @widget="test-widget" @args={{this.args}} />`
);
- assert.strictEqual(query("blockquote").innerText, "abcd");
+ assert.dom("blockquote").hasText("abcd");
});
});