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