FEATURE: adds a new plugin api to decorate plugin outlets (#8937)
```
api.decoratePluginOutlet(
"discovery-list-container-top",
elem => {
if (elem.classList.contains("foo")) {
elem.style.backgroundColor = "yellow";
}
}
);
```
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { acceptance } from "helpers/qunit-helpers";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
const PREFIX = "javascripts/single-test/connectors";
|
||||
acceptance("Plugin Outlet - Decorator", {
|
||||
loggedIn: true,
|
||||
|
||||
beforeEach() {
|
||||
Ember.TEMPLATES[
|
||||
`${PREFIX}/discovery-list-container-top/foo`
|
||||
] = Ember.HTMLBars.compile("FOO");
|
||||
Ember.TEMPLATES[
|
||||
`${PREFIX}/discovery-list-container-top/bar`
|
||||
] = Ember.HTMLBars.compile("BAR");
|
||||
|
||||
withPluginApi("0.8.38", api => {
|
||||
api.decoratePluginOutlet(
|
||||
"discovery-list-container-top",
|
||||
(elem, args) => {
|
||||
if (elem.classList.contains("foo")) {
|
||||
elem.style.backgroundColor = "yellow";
|
||||
|
||||
if (args.category) {
|
||||
elem.classList.add("in-category");
|
||||
} else {
|
||||
elem.classList.remove("in-category");
|
||||
}
|
||||
}
|
||||
},
|
||||
{ id: "yellow-decorator" }
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
afterEach() {
|
||||
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`];
|
||||
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`];
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"Calls the plugin callback with the rendered outlet",
|
||||
async assert => {
|
||||
await visit("/");
|
||||
|
||||
const fooConnector = find(".discovery-list-container-top-outlet.foo ")[0];
|
||||
const barConnector = find(".discovery-list-container-top-outlet.bar ")[0];
|
||||
|
||||
assert.ok(exists(fooConnector));
|
||||
assert.equal(fooConnector.style.backgroundColor, "yellow");
|
||||
assert.equal(barConnector.style.backgroundColor, "");
|
||||
|
||||
await visit("/c/bug");
|
||||
|
||||
assert.ok(fooConnector.classList.contains("in-category"));
|
||||
|
||||
await visit("/");
|
||||
|
||||
assert.notOk(fooConnector.classList.contains("in-category"));
|
||||
}
|
||||
);
|
||||
@@ -18,6 +18,7 @@ import { initSearchData } from "discourse/widgets/search-menu";
|
||||
import { resetDecorators } from "discourse/widgets/widget";
|
||||
import { resetWidgetCleanCallbacks } from "discourse/components/mount-widget";
|
||||
import { resetDecorators as resetPostCookedDecorators } from "discourse/widgets/post-cooked";
|
||||
import { resetDecorators as resetPluginOutletDecorators } from "discourse/components/plugin-connector";
|
||||
import { resetCache as resetOneboxCache } from "pretty-text/oneboxer";
|
||||
import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";
|
||||
import User from "discourse/models/user";
|
||||
@@ -128,6 +129,7 @@ export function acceptance(name, options) {
|
||||
initSearchData();
|
||||
resetDecorators();
|
||||
resetPostCookedDecorators();
|
||||
resetPluginOutletDecorators();
|
||||
resetOneboxCache();
|
||||
resetCustomPostMessageCallbacks();
|
||||
Discourse._runInitializer("instanceInitializers", function(
|
||||
|
||||
Reference in New Issue
Block a user