2016-12-20 00:19:10 +08:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
2018-06-15 23:03:24 +08:00
|
|
|
import { extraConnectorClass } from "discourse/lib/plugin-connectors";
|
2016-12-20 00:19:10 +08:00
|
|
|
|
|
|
|
const PREFIX = "javascripts/single-test/connectors";
|
|
|
|
acceptance("Plugin Outlet - Connector Class", {
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
extraConnectorClass("user-profile-primary/hello", {
|
2016-12-20 00:19:10 +08:00
|
|
|
actions: {
|
|
|
|
sayHello() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("hello", "hello!");
|
2016-12-20 00:19:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
extraConnectorClass("user-profile-primary/dont-render", {
|
2016-12-20 00:19:10 +08:00
|
|
|
shouldRender(args) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return args.model.get("username") !== "eviltrout";
|
2016-12-20 00:19:10 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
Ember.TEMPLATES[
|
|
|
|
`${PREFIX}/user-profile-primary/hello`
|
|
|
|
] = Ember.HTMLBars.compile(
|
2016-12-20 00:19:10 +08:00
|
|
|
`<span class='hello-username'>{{model.username}}</span>
|
|
|
|
<button class='say-hello' {{action "sayHello"}}></button>
|
|
|
|
<span class='hello-result'>{{hello}}</span>`
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
Ember.TEMPLATES[
|
|
|
|
`${PREFIX}/user-profile-primary/dont-render`
|
|
|
|
] = Ember.HTMLBars.compile(`I'm not rendered!`);
|
2016-12-20 00:19:10 +08:00
|
|
|
},
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
afterEach() {
|
2016-12-20 00:19:10 +08:00
|
|
|
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`];
|
|
|
|
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-19 22:40:12 +08:00
|
|
|
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"
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
});
|