Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inline views when template uses unescaped variables #672

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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);
});
});
});