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

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

68 lines
2.0 KiB
JavaScript
Raw Normal View History

import EmberObject from "@ember/object";
2018-06-15 23:03:24 +08:00
import createStore from "helpers/create-store";
import { autoLoadModules } from "discourse/initializers/auto-load-modules";
import TopicTrackingState from "discourse/models/topic-tracking-state";
2019-11-14 04:55:32 +08:00
import User from "discourse/models/user";
import Site from "discourse/models/site";
export default function(name, opts) {
opts = opts || {};
2019-05-17 02:33:27 +08:00
if (opts.skip) {
return;
}
test(name, function(assert) {
this.site = Site.current();
2016-03-22 02:16:05 +08:00
2018-06-15 23:03:24 +08:00
this.registry.register("site-settings:main", Discourse.SiteSettings, {
instantiate: false
});
this.registry.register("capabilities:main", EmberObject);
2018-06-15 23:03:24 +08:00
this.registry.register("site:main", this.site, { instantiate: false });
this.registry.injection("component", "siteSettings", "site-settings:main");
this.registry.injection("component", "appEvents", "service:app-events");
2018-06-15 23:03:24 +08:00
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) {
2019-11-14 04:55:32 +08:00
const currentUser = User.create({ username: "eviltrout" });
this.currentUser = currentUser;
2018-06-15 23:03:24 +08:00
this.registry.register("current-user:main", this.currentUser, {
instantiate: false
});
this.registry.injection("component", "currentUser", "current-user:main");
2018-06-15 23:03:24 +08:00
this.registry.register(
"topic-tracking-state:main",
TopicTrackingState.create({ currentUser }),
{ instantiate: false }
);
}
2018-06-15 23:03:24 +08:00
this.registry.register("service:store", store, { instantiate: false });
2017-06-15 01:57:58 +08:00
if (opts.beforeEach) {
opts.beforeEach.call(this, store);
}
andThen(() => {
return this.render(opts.template);
});
2019-05-01 02:01:21 +08:00
andThen(() => {
try {
opts.test.call(this, assert);
} finally {
if (opts.afterEach) {
opts.afterEach.call(opts);
}
}
2019-05-01 02:01:21 +08:00
});
});
}