Skip to content

Commit

Permalink
Trim RouterNonApplicationTestCase to minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
xg-wang committed Oct 11, 2020
1 parent 517927b commit cba48c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ moduleFor(
super(...arguments);

this.resolver.add('router:main', Router.extend(this.routerOptions));
this.router.map(function() {
this.route('parent', { path: '/' }, function() {
this.router.map(function () {
this.route('parent', { path: '/' }, function () {
this.route('child');
this.route('sister');
this.route('brother');
});
this.route('dynamic', { path: '/dynamic/:dynamic_id' });
this.route('dynamicWithChild', { path: '/dynamic-with-child/:dynamic_id' }, function() {
this.route('dynamicWithChild', { path: '/dynamic-with-child/:dynamic_id' }, function () {
this.route('child', { path: '/:child_id' });
});
});
Expand Down Expand Up @@ -81,7 +81,7 @@ moduleFor(

this.render('{{foo-bar}}');

run(function() {
run(function () {
componentInstance.send('transitionToSister');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { assign } from '@ember/polyfills';
import { compile } from 'ember-template-compiler';
import { EventDispatcher } from '@ember/-internals/views';
import { helper, Helper, Component, _resetRenderers } from '@ember/-internals/glimmer';
import { Component, _resetRenderers } from '@ember/-internals/glimmer';
import { ModuleBasedResolver } from '../test-resolver';

import AbstractTestCase from './abstract';
import buildOwner from '../build-owner';
import { runAppend, runDestroy } from '../run';

const TextNode = window.Text;

export default class RouterNonApplicationTestCase extends AbstractTestCase {
constructor() {
super(...arguments);
Expand All @@ -30,20 +28,12 @@ export default class RouterNonApplicationTestCase extends AbstractTestCase {
this.renderer = this.owner.lookup('renderer:-dom');
this.element = document.querySelector('#qunit-fixture');
this.component = null;

if (!bootOptions || bootOptions.isInteractive !== false) {
owner.lookup('event_dispatcher:main').setup(this.getCustomDispatcherEvents(), this.element);
}
}

compile() {
return compile(...arguments);
}

getCustomDispatcherEvents() {
return {};
}

getOwnerOptions() {}
getBootOptions() {}

Expand Down Expand Up @@ -105,10 +95,6 @@ export default class RouterNonApplicationTestCase extends AbstractTestCase {
}
}

get context() {
return this.component;
}

render(templateStr, context = {}) {
let { owner } = this;

Expand All @@ -130,84 +116,4 @@ export default class RouterNonApplicationTestCase extends AbstractTestCase {

runAppend(this.component);
}

rerender() {
this.component.rerender();
}

registerHelper(name, funcOrClassBody) {
let type = typeof funcOrClassBody;

if (type === 'function') {
this.owner.register(`helper:${name}`, helper(funcOrClassBody));
} else if (type === 'object' && type !== null) {
this.owner.register(`helper:${name}`, Helper.extend(funcOrClassBody));
} else {
throw new Error(`Cannot register ${funcOrClassBody} as a helper`);
}
}

registerPartial(name, template) {
let owner = this.owner;
if (typeof template === 'string') {
owner.register(
`template:${name}`,
this.compile(template, { moduleName: `my-app/templates/-${name}.hbs` })
);
}
}

registerComponent(name, { ComponentClass = Component, template = null }) {
let { owner } = this;

if (ComponentClass) {
owner.register(`component:${name}`, ComponentClass);
}

if (typeof template === 'string') {
owner.register(
`template:components/${name}`,
this.compile(template, {
moduleName: `my-app/templates/components/${name}.hbs`,
})
);
}
}

registerModifier(name, ModifierClass) {
let { owner } = this;

owner.register(`modifier:${name}`, ModifierClass);
}

registerComponentManager(name, manager) {
let owner = this.owner;
owner.register(`component-manager:${name}`, manager);
}

registerTemplate(name, template) {
let { owner } = this;
if (typeof template === 'string') {
owner.register(
`template:${name}`,
this.compile(template, {
moduleName: `my-app/templates/${name}.hbs`,
})
);
} else {
throw new Error(`Registered template "${name}" must be a string`);
}
}

registerService(name, klass) {
this.owner.register(`service:${name}`, klass);
}

assertTextNode(node, text) {
if (!(node instanceof TextNode)) {
throw new Error(`Expecting a text node, but got ${node}`);
}

this.assert.strictEqual(node.textContent, text, 'node.textContent');
}
}

0 comments on commit cba48c5

Please sign in to comment.