discourse/test/javascripts/acceptance/plugin-outlet-connector-cla...

Failed to ignore revisions in .git-blame-ignore-revs.

88 lines
2.3 KiB
JavaScript
Raw Normal View History

import { acceptance } from "helpers/qunit-helpers";
2018-06-15 11:03:24 -04:00
import { extraConnectorClass } from "discourse/lib/plugin-connectors";
import { action } from "@ember/object";
const PREFIX = "javascripts/single-test/connectors";
acceptance("Plugin Outlet - Connector Class", {
2017-06-14 13:57:58 -04:00
beforeEach() {
2018-06-15 11:03:24 -04:00
extraConnectorClass("user-profile-primary/hello", {
actions: {
sayHello() {
2018-06-15 11:03:24 -04:00
this.set("hello", "hello!");
}
}
});
extraConnectorClass("user-profile-primary/hi", {
setupComponent() {
this.appEvents.on("hi:sayHi", this, this.say);
},
teardownComponent() {
this.appEvents.off("hi:sayHi", this, this.say);
},
@action
say() {
this.set("hi", "hi!");
},
@action
sayHi() {
this.appEvents.trigger("hi:sayHi");
}
});
2018-06-15 11:03:24 -04:00
extraConnectorClass("user-profile-primary/dont-render", {
shouldRender(args) {
2018-06-15 11:03:24 -04:00
return args.model.get("username") !== "eviltrout";
}
});
2018-06-15 11:03:24 -04:00
Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/hello`
] = Ember.HTMLBars.compile(
`<span class='hello-username'>{{model.username}}</span>
<button class='say-hello' {{action "sayHello"}}></button>
<span class='hello-result'>{{hello}}</span>`
);
Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/hi`
] = Ember.HTMLBars.compile(
`<button class='say-hi' {{action "sayHi"}}></button>
<span class='hi-result'>{{hi}}</span>`
);
2018-06-15 11:03:24 -04:00
Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/dont-render`
] = Ember.HTMLBars.compile(`I'm not rendered!`);
},
2017-06-14 13:57:58 -04:00
afterEach() {
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`];
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`];
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
}
});
QUnit.test("Renders a template into the outlet", async assert => {
await visit("/u/eviltrout");
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
"it has class names"
);
assert.ok(
!find(".user-profile-primary-outlet.dont-render").length,
"doesn't render"
);
await click(".say-hello");
assert.equal(
find(".hello-result").text(),
"hello!",
"actions delegate properly"
);
await click(".say-hi");
assert.equal(find(".hi-result").text(), "hi!", "actions delegate properly");
2018-06-15 11:03:24 -04:00
});