|
| 1 | +import { hash } from "@ember/helper"; |
| 2 | +import { render } from "@ember/test-helpers"; |
| 3 | +import { hbs } from "ember-cli-htmlbars"; |
| 4 | +import { module, test } from "qunit"; |
| 5 | +import PluginOutlet from "discourse/components/plugin-outlet"; |
| 6 | +import { withPluginApi } from "discourse/lib/plugin-api"; |
| 7 | +import { setupRenderingTest } from "discourse/tests/helpers/component-test"; |
| 8 | +import { query } from "discourse/tests/helpers/qunit-helpers"; |
| 9 | +import { withSilencedDeprecations } from "discourse-common/lib/deprecated"; |
| 10 | +import { registerTemporaryModule } from "../../helpers/temporary-module-helper"; |
| 11 | + |
| 12 | +const PREFIX = "discourse/plugins/some-plugin/templates/connectors"; |
| 13 | + |
| 14 | +module("Plugin Outlet - Decorator", function (hooks) { |
| 15 | + setupRenderingTest(hooks); |
| 16 | + |
| 17 | + hooks.beforeEach(() => { |
| 18 | + registerTemporaryModule(`${PREFIX}/my-outlet-name/foo`, hbs`FOO`); |
| 19 | + registerTemporaryModule(`${PREFIX}/my-outlet-name/bar`, hbs`BAR`); |
| 20 | + |
| 21 | + withPluginApi("0.8.38", (api) => { |
| 22 | + withSilencedDeprecations("discourse.decorate-plugin-outlet", () => { |
| 23 | + api.decoratePluginOutlet( |
| 24 | + "my-outlet-name", |
| 25 | + (elem, args) => { |
| 26 | + if (elem.classList.contains("foo")) { |
| 27 | + elem.style.backgroundColor = "yellow"; |
| 28 | + elem.classList.toggle("has-value", !!args.value); |
| 29 | + } |
| 30 | + }, |
| 31 | + { id: "yellow-decorator" } |
| 32 | + ); |
| 33 | + }); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + test("Calls the plugin callback with the rendered outlet", async function (assert) { |
| 38 | + await render(<template> |
| 39 | + <PluginOutlet @connectorTagName="div" @name="my-outlet-name" /> |
| 40 | + </template>); |
| 41 | + |
| 42 | + const fooConnector = query(".my-outlet-name-outlet.foo"); |
| 43 | + const barConnector = query(".my-outlet-name-outlet.bar"); |
| 44 | + |
| 45 | + assert.dom(fooConnector).exists(); |
| 46 | + assert.strictEqual(fooConnector.style.backgroundColor, "yellow"); |
| 47 | + assert.strictEqual(barConnector.style.backgroundColor, ""); |
| 48 | + |
| 49 | + await render(<template> |
| 50 | + <PluginOutlet |
| 51 | + @connectorTagName="div" |
| 52 | + @name="my-outlet-name" |
| 53 | + @outletArgs={{hash value=true}} |
| 54 | + /> |
| 55 | + </template>); |
| 56 | + |
| 57 | + assert.dom(".my-outlet-name-outlet.foo").hasClass("has-value"); |
| 58 | + |
| 59 | + await render(<template> |
| 60 | + <PluginOutlet @connectorTagName="div" @name="my-outlet-name" /> |
| 61 | + </template>); |
| 62 | + |
| 63 | + assert.dom(".my-outlet-name-outlet.foo").doesNotHaveClass("has-value"); |
| 64 | + }); |
| 65 | +}); |
0 commit comments