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

46 lines
1.8 KiB
Plaintext
Raw Normal View History

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 || {};
test(name, function(assert) {
const appEvents = AppEvents.create();
2016-03-21 14:16:05 -04:00
this.site = Discourse.Site.current();
this.container.register('site-settings:main', Discourse.SiteSettings, { instantiate: false });
this.container.register('app-events:main', appEvents, { instantiate: false });
this.container.register('capabilities:main', Ember.Object);
2016-03-21 14:16:05 -04:00
this.container.register('site:main', this.site, { instantiate: false });
this.container.injection('component', 'siteSettings', 'site-settings:main');
this.container.injection('component', 'appEvents', 'app-events:main');
this.container.injection('component', 'capabilities', 'capabilities:main');
2016-02-18 12:18:43 -05:00
this.container.injection('component', 'site', 'site:main');
this.siteSettings = Discourse.SiteSettings;
autoLoadModules(this.container, this.registry);
const store = createStore();
if (!opts.anonymous) {
const currentUser = Discourse.User.create({ username: 'eviltrout' });
this.currentUser = currentUser;
this.container.register('current-user:main', this.currentUser, { instantiate: false });
this.container.register('topic-tracking-state:main',
TopicTrackingState.create({ currentUser }),
{ instantiate: false });
}
this.container.register('store:main', store, { instantiate: false });
if (opts.setup) {
opts.setup.call(this, store);
}
andThen(() => this.render(opts.template));
andThen(() => opts.test.call(this, assert));
});
}