discourse/test/javascripts/helpers/component-test.js.es6

69 lines
2.0 KiB
Plaintext
Raw Normal View History

2018-06-15 11:03:24 -04:00
import AppEvents from "discourse/lib/app-events";
import createStore from "helpers/create-store";
import { autoLoadModules } from "discourse/initializers/auto-load-modules";
import TopicTrackingState from "discourse/models/topic-tracking-state";
export default function(name, opts) {
opts = opts || {};
2019-05-16 14:33:27 -04:00
if (opts.skip) {
return;
}
test(name, function(assert) {
const appEvents = AppEvents.create();
2016-03-21 14:16:05 -04:00
this.site = Discourse.Site.current();
2018-06-15 11:03:24 -04:00
this.registry.register("site-settings:main", Discourse.SiteSettings, {
instantiate: false
});
this.registry.register("app-events:main", appEvents, {
instantiate: false
});
this.registry.register("capabilities:main", Ember.Object);
this.registry.register("site:main", this.site, { instantiate: false });
this.registry.injection("component", "siteSettings", "site-settings:main");
this.registry.injection("component", "appEvents", "app-events:main");
this.registry.injection("component", "capabilities", "capabilities:main");
this.registry.injection("component", "site", "site:main");
this.siteSettings = Discourse.SiteSettings;
autoLoadModules(this.registry, this.registry);
const store = createStore();
if (!opts.anonymous) {
2018-06-15 11:03:24 -04:00
const currentUser = Discourse.User.create({ username: "eviltrout" });
this.currentUser = currentUser;
2018-06-15 11:03:24 -04:00
this.registry.register("current-user:main", this.currentUser, {
instantiate: false
});
this.registry.register(
"topic-tracking-state:main",
TopicTrackingState.create({ currentUser }),
{ instantiate: false }
);
}
2018-06-15 11:03:24 -04:00
this.registry.register("service:store", store, { instantiate: false });
2017-06-14 13:57:58 -04:00
if (opts.beforeEach) {
opts.beforeEach.call(this, store);
}
andThen(() => {
return this.render(opts.template);
});
2019-04-30 14:01:21 -04:00
andThen(() => {
try {
opts.test.call(this, assert);
} finally {
if (opts.afterEach) {
opts.afterEach.call(opts);
}
}
2019-04-30 14:01:21 -04:00
});
});
}