Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions test/view-strategy.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Container } from 'aurelia-dependency-injection';
import { BindingLanguage } from '../src/binding-language';
import { inlineView } from '../src/decorators';
import { ResourceLoadContext, ViewCompileInstruction } from '../src/instructions';
import { ViewCompiler } from '../src/view-compiler';
import { ViewEngine } from '../src/view-engine';
import { ViewLocator } from '../src/view-locator';
import { ViewResources } from '../src/view-resources';
import { StaticViewStrategy } from '../src/view-strategy';
import { InlineViewStrategy, StaticViewStrategy } from '../src/view-strategy';
import './setup';
import { ViewEngineHooksResource } from '../src/view-engine-hooks-resource';
import { metadata } from 'aurelia-metadata';
Expand All @@ -14,11 +16,13 @@ import { _hyphenate } from '../src/util';
describe('ViewLocator', () => {
/**@type {ViewEngine} */
let viewEngine;
let container = new Container();
let appResources = new ViewResources();
/**@type {Container} */
let container;
/**@type {ViewResources} */
let appResources;

beforeEach(() => {
let bindingLanguage = new class extends BindingLanguage {
const bindingLanguage = new class extends BindingLanguage {
createAttributeInstruction () {}
inspectAttribute (resources, tagName, attrName, attrValue) {
return { attrName, attrValue};
Expand All @@ -27,11 +31,13 @@ describe('ViewLocator', () => {
};
container = new Container();
appResources = new ViewResources();
viewEngine = {
container: container,
appResources: appResources,
viewCompiler: new ViewCompiler(bindingLanguage, appResources)
};
viewEngine = new ViewEngine(
null, // no loader
container,
new ViewCompiler(bindingLanguage, appResources),
null, // no moduleAnalyzer
appResources
);
});

describe('StaticViewStrategy', () => {
Expand Down Expand Up @@ -344,4 +350,36 @@ describe('ViewLocator', () => {
.catch(done.fail);
});
});

describe('InlineViewStrategy', () => {
it('loads', (done) => {
class El {}
inlineView('<template><input value.bind="value"></template>')(El);
const viewLocator = new ViewLocator();
const strategy = viewLocator.getViewStrategy(El);
expect(strategy instanceof InlineViewStrategy).toBe(true);
strategy
.loadViewFactory(viewEngine, ViewCompileInstruction.normal, new ResourceLoadContext(), El)
.then((factory) => {
// TODO: Remove Console
// eslint-disable-next-line no-console
// TODO: Remove Console
// eslint-disable-next-line no-console
console.log(`factory`, factory);
// TODO: Remove Console
// eslint-disable-next-line no-console
console.log(`factory.resources`, factory.resources);

console.log(`factory.resources.elements=${JSON.stringify(factory.resources.elements, null, 2)}`);

expect(factory.resources.getElement('el').target).toBe(El);
}).catch(ex => {
// TODO: Remove Console
// eslint-disable-next-line no-console
console.log('ex', ex.message);

expect(ex.message).not.toContain('Cannot determine default view strategy for object.');
}).then(done);
});
});
});