2019-10-30 03:23:50 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2015-07-15 01:56:59 +08:00
|
|
|
import createStore from "helpers/create-store";
|
2016-03-19 04:31:59 +08:00
|
|
|
import { autoLoadModules } from "discourse/initializers/auto-load-modules";
|
2016-04-15 03:23:05 +08:00
|
|
|
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
2019-11-14 04:55:32 +08:00
|
|
|
import User from "discourse/models/user";
|
2019-11-14 05:00:58 +08:00
|
|
|
import Site from "discourse/models/site";
|
2020-08-18 03:44:39 +08:00
|
|
|
import Session from "discourse/models/session";
|
2020-07-15 01:07:54 +08:00
|
|
|
import { currentSettings } from "helpers/site-settings";
|
2015-07-15 01:56:59 +08:00
|
|
|
|
|
|
|
export default function (name, opts) {
|
|
|
|
opts = opts || {};
|
|
|
|
|
2019-05-17 02:33:27 +08:00
|
|
|
if (opts.skip) {
|
|
|
|
return;
|
2019-05-17 02:15:37 +08:00
|
|
|
}
|
|
|
|
|
2015-07-15 01:56:59 +08:00
|
|
|
test(name, function (assert) {
|
2019-11-14 05:00:58 +08:00
|
|
|
this.site = Site.current();
|
2020-08-18 03:44:39 +08:00
|
|
|
this.session = Session.current();
|
2016-03-22 02:16:05 +08:00
|
|
|
|
2020-07-15 01:07:54 +08:00
|
|
|
this.registry.register("site-settings:main", currentSettings(), {
|
2016-11-08 04:11:56 +08:00
|
|
|
instantiate: false,
|
|
|
|
});
|
2019-10-30 03:23:50 +08:00
|
|
|
this.registry.register("capabilities:main", EmberObject);
|
2016-11-08 04:11:56 +08:00
|
|
|
this.registry.register("site:main", this.site, { instantiate: false });
|
2020-08-18 03:44:39 +08:00
|
|
|
this.registry.register("session:main", this.session, {
|
|
|
|
instantiate: false,
|
|
|
|
});
|
2016-11-08 04:11:56 +08:00
|
|
|
this.registry.injection("component", "siteSettings", "site-settings:main");
|
2019-10-04 22:06:08 +08:00
|
|
|
this.registry.injection("component", "appEvents", "service:app-events");
|
2016-11-08 04:11:56 +08:00
|
|
|
this.registry.injection("component", "capabilities", "capabilities:main");
|
|
|
|
this.registry.injection("component", "site", "site:main");
|
2020-08-18 03:44:39 +08:00
|
|
|
this.registry.injection("component", "session", "session:main");
|
2015-07-15 01:56:59 +08:00
|
|
|
|
2020-07-15 01:07:54 +08:00
|
|
|
this.siteSettings = currentSettings();
|
2020-07-23 01:13:12 +08:00
|
|
|
autoLoadModules(this.container, this.registry);
|
2016-01-05 04:18:09 +08:00
|
|
|
|
2016-04-15 03:23:05 +08:00
|
|
|
const store = createStore();
|
|
|
|
if (!opts.anonymous) {
|
2019-11-14 04:55:32 +08:00
|
|
|
const currentUser = User.create({ username: "eviltrout" });
|
2016-04-15 03:23:05 +08:00
|
|
|
this.currentUser = currentUser;
|
2016-11-08 04:11:56 +08:00
|
|
|
this.registry.register("current-user:main", this.currentUser, {
|
|
|
|
instantiate: false,
|
|
|
|
});
|
2019-10-29 18:12:09 +08:00
|
|
|
this.registry.injection("component", "currentUser", "current-user:main");
|
2016-11-08 04:11:56 +08:00
|
|
|
this.registry.register(
|
|
|
|
"topic-tracking-state:main",
|
2016-04-15 03:23:05 +08:00
|
|
|
TopicTrackingState.create({ currentUser }),
|
|
|
|
{ instantiate: false }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-28 01:59:22 +08:00
|
|
|
this.registry.register("service:store", store, { instantiate: false });
|
2016-04-15 03:23:05 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
if (opts.beforeEach) {
|
|
|
|
opts.beforeEach.call(this, store);
|
2016-01-05 04:18:09 +08:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:40:35 +08:00
|
|
|
andThen(() => {
|
|
|
|
return this.render(opts.template);
|
|
|
|
});
|
2019-05-24 03:23:31 +08:00
|
|
|
|
2019-05-01 02:01:21 +08:00
|
|
|
andThen(() => {
|
2020-06-24 14:03:38 +08:00
|
|
|
return opts.test.call(this, assert);
|
|
|
|
}).finally(() => {
|
|
|
|
if (opts.afterEach) {
|
|
|
|
andThen(() => {
|
|
|
|
return opts.afterEach.call(opts);
|
|
|
|
});
|
2019-05-24 03:23:31 +08:00
|
|
|
}
|
2019-05-01 02:01:21 +08:00
|
|
|
});
|
2015-07-15 01:56:59 +08:00
|
|
|
});
|
|
|
|
}
|