Skip to content

Commit

Permalink
Merge pull request #677 from buschtoens/fix/template-factory
Browse files Browse the repository at this point in the history
fix(setupRenderingContext): compatibility with template factory
  • Loading branch information
rwjblue authored Aug 30, 2019
2 parents 4ca1ad8 + 7227929 commit 11b4b93
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
18 changes: 15 additions & 3 deletions addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,28 @@ export function isRenderingTestContext(context: BaseContext): context is Renderi
);
}

/**
@private
@param {Ember.ApplicationInstance} owner the current owner instance
@param {string} templateFullName the fill template name
@returns {Template} the template representing `templateFullName`
*/
function lookupTemplate(owner: Owner, templateFullName: string) {
let template = owner.lookup(templateFullName);
if (typeof template === 'function') return template(owner);
return template;
}

/**
@private
@param {Ember.ApplicationInstance} owner the current owner instance
@returns {Template} a template representing {{outlet}}
*/
function lookupOutletTemplate(owner: Owner): any {
let OutletTemplate = owner.lookup('template:-outlet');
let OutletTemplate = lookupTemplate(owner, 'template:-outlet');
if (!OutletTemplate) {
owner.register('template:-outlet', OUTLET_TEMPLATE);
OutletTemplate = owner.lookup('template:-outlet');
OutletTemplate = lookupTemplate(owner, 'template:-outlet');
}

return OutletTemplate;
Expand Down Expand Up @@ -120,7 +132,7 @@ export function render(template: TemplateFactory): Promise<void> {
name: 'index',
controller: context,
ViewClass: undefined,
template: owner.lookup(templateFullName),
template: lookupTemplate(owner, templateFullName),
outlets: {},
},
outlets: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ export default class extends TestModule {
}
}

function getOwnerFromModule(module) {
return (getOwner && getOwner(module.container)) || module.container.owner;
}

function lookupTemplateFromModule(module, templateFullName) {
var template = module.container.lookup(templateFullName);
if (typeof template === 'function') template = template(getOwnerFromModule(module));
return template;
}

export function setupComponentIntegrationTest() {
var module = this;
var context = this.context;
Expand All @@ -211,12 +221,12 @@ export function setupComponentIntegrationTest() {
var OutletView = module.container.factoryFor
? module.container.factoryFor('view:-outlet')
: module.container.lookupFactory('view:-outlet');
var OutletTemplate = module.container.lookup('template:-outlet');
var OutletTemplate = lookupTemplateFromModule(module, 'template:-outlet');
var toplevelView = (module.component = OutletView.create());
var hasOutletTemplate = !!OutletTemplate;
var outletState = {
render: {
owner: getOwner ? getOwner(module.container) : undefined,
owner: getOwnerFromModule(module),
into: undefined,
outlet: 'main',
name: 'application',
Expand Down Expand Up @@ -251,13 +261,13 @@ export function setupComponentIntegrationTest() {
var templateFullName = 'template:-undertest-' + ++templateId;
this.registry.register(templateFullName, template);
var stateToRender = {
owner: getOwner ? getOwner(module.container) : undefined,
owner: getOwnerFromModule(module),
into: undefined,
outlet: 'main',
name: 'index',
controller: module.context,
ViewClass: undefined,
template: module.container.lookup(templateFullName),
template: lookupTemplateFromModule(module, templateFullName),
outlets: {},
};

Expand Down

0 comments on commit 11b4b93

Please sign in to comment.