Skip to content

Commit

Permalink
Cleanup ember-template-compiler's tests
Browse files Browse the repository at this point in the history
Fix travis
  • Loading branch information
karthiicksiva committed Dec 19, 2017
1 parent 4c5344c commit 1e0128e
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { compile } from '../../index';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

QUnit.module('ember-template-compiler: assert-input-helper-without-block');
moduleFor('ember-template-compiler: assert-input-helper-without-block', class extends AbstractTestCase {
['@test Using {{#input}}{{/input}} is not valid'](assert) {
assert.expect(1);

QUnit.test('Using {{#input}}{{/input}} is not valid', function() {
expect(1);
let expectedMessage =
`The {{input}} helper cannot be used in block form. ('baz/foo-bar' @ L1:C0) `;

let expectedMessage =
`The {{input}} helper cannot be used in block form. ('baz/foo-bar' @ L1:C0) `;

expectAssertion(() => {
compile('{{#input value="123"}}Completely invalid{{/input}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
expectAssertion(() => {
compile('{{#input value="123"}}Completely invalid{{/input}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
}
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { compile } from '../../index';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

QUnit.module('ember-template-compiler: deprecate-model-render');
moduleFor('ember-template-compiler: deprecate-model-render', class extends AbstractTestCase {
['@test Using `{{render` with model provides a deprecation'](assert) {
assert.expect(1);

QUnit.test('Using `{{render` with model provides a deprecation', function() {
expect(1);
let expectedMessage =
`Please refactor \`{{render "foo-bar" coolModel}}\` to a component and` +
` invoke via \`{{foo-bar model=coolModel}}\`. ('baz/foo-bar' @ L1:C0) `;

let expectedMessage =
`Please refactor \`{{render "foo-bar" coolModel}}\` to a component and` +
` invoke via \`{{foo-bar model=coolModel}}\`. ('baz/foo-bar' @ L1:C0) `;

expectDeprecation(() => {
compile('{{render "foo-bar" coolModel}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
expectDeprecation(() => {
compile('{{render "foo-bar" coolModel}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
}
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { compile } from '../../index';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

QUnit.module('ember-template-compiler: deprecate-render');
moduleFor('ember-template-compiler: deprecate-render', class extends AbstractTestCase {
['@test Using `{{render` without a model provides a deprecation'](assert) {
assert.expect(1);

QUnit.test('Using `{{render` without a model provides a deprecation', function() {
expect(1);
let expectedMessage =
`Please refactor \`{{render "foo-bar"}}\` to a component and` +
` invoke via \`{{foo-bar}}\`. ('baz/foo-bar' @ L1:C0) `;

let expectedMessage =
`Please refactor \`{{render "foo-bar"}}\` to a component and` +
` invoke via \`{{foo-bar}}\`. ('baz/foo-bar' @ L1:C0) `;

expectDeprecation(() => {
compile('{{render "foo-bar"}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
expectDeprecation(() => {
compile('{{render "foo-bar"}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
}
});
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { compile } from '../../index';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

QUnit.module('ember-template-compiler: transforms dot component invocation');
moduleFor('ember-template-compiler: transforms dot component invocation', class extends AbstractTestCase {
['@test Does not throw a compiler error for path components'](assert) {
assert.expect(1);

QUnit.test('Does not throw a compiler error for path components', function(assert) {
assert.expect(1);
[
'{{this.modal open}}',
'{{this.modal isOpen=true}}',
'{{#this.modal}}Woot{{/this.modal}}',
'{{c.modal open}}',
'{{c.modal isOpen=true}}',
'{{#c.modal}}Woot{{/c.modal}}',
'{{#my-component as |c|}}{{c.a name="Chad"}}{{/my-component}}',
'{{#my-component as |c|}}{{c.a "Chad"}}{{/my-component}}',
'{{#my-component as |c|}}{{#c.a}}{{/c.a}}{{/my-component}}',
'<input disabled={{true}}>', // GH#15740
'<td colspan={{3}}></td>' // GH#15217
].forEach((layout, i) => {
compile(layout, { moduleName: `example-${i}` });
});

[
'{{this.modal open}}',
'{{this.modal isOpen=true}}',
'{{#this.modal}}Woot{{/this.modal}}',
'{{c.modal open}}',
'{{c.modal isOpen=true}}',
'{{#c.modal}}Woot{{/c.modal}}',
'{{#my-component as |c|}}{{c.a name="Chad"}}{{/my-component}}',
'{{#my-component as |c|}}{{c.a "Chad"}}{{/my-component}}',
'{{#my-component as |c|}}{{#c.a}}{{/c.a}}{{/my-component}}',
'<input disabled={{true}}>', // GH#15740
'<td colspan={{3}}></td>' // GH#15217
].forEach((layout, i) => {
compile(layout, { moduleName: `example-${i}` });
});

assert.ok(true);
assert.ok(true);
}
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { compile } from '../../index';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

QUnit.module('ember-template-compiler: assert-no-view-and-controller-paths without legacy view support');
moduleFor('ember-template-compiler: inline-link-to', class extends AbstractTestCase {
['@test Can transform an inline {{link-to}} without error'](assert) {
assert.expect(0);

QUnit.test('Can transform an inline {{link-to}} without error', function() {
expect(0);

compile(`{{link-to 'foo' 'index'}}`, {
moduleName: 'foo/bar/baz'
});
compile(`{{link-to 'foo' 'index'}}`, {
moduleName: 'foo/bar/baz'
});
}
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { compile } from '../../index';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

QUnit.module('ember-template-compiler: input type syntax');
moduleFor('ember-template-compiler: input type syntax', class extends AbstractTestCase {
['@test Can compile an {{input}} helper that has a sub-expression value as its type'](assert) {
assert.expect(0);

QUnit.test('Can compile an {{input}} helper that has a sub-expression value as its type', function() {
expect(0);
compile(`{{input type=(if true 'password' 'text')}}`);
}

compile(`{{input type=(if true 'password' 'text')}}`);
});

QUnit.test('Can compile an {{input}} helper with a string literal type', function() {
expect(0);
['@test Can compile an {{input}} helper with a string literal type'](assert) {
assert.expect(0);

compile(`{{input type='text'}}`);
});
compile(`{{input type='text'}}`);
}

QUnit.test('Can compile an {{input}} helper with a type stored in a var', function() {
expect(0);
['@test Can compile an {{input}} helper with a type stored in a var'](assert) {
assert.expect(0);

compile(`{{input type=_type}}`);
compile(`{{input type=_type}}`);
}
});
116 changes: 60 additions & 56 deletions packages/ember-template-compiler/tests/system/bootstrap-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ import bootstrap from '../../system/bootstrap';
import {
runAppend,
runDestroy,
buildOwner
buildOwner,
moduleFor,
AbstractTestCase
} from 'internal-test-helpers';

const { trim } = jQuery;

let component, fixture;

function checkTemplate(templateName) {
function checkTemplate(templateName, assert) {
run(() => bootstrap({ context: fixture, hasTemplate, setTemplate }));

let template = getTemplate(templateName);

ok(template, 'template is available on Ember.TEMPLATES');
equal(jQuery('#qunit-fixture script').length, 0, 'script removed');
assert.ok(template, 'template is available on Ember.TEMPLATES');
assert.equal(jQuery('#qunit-fixture script').length, 0, 'script removed');

let owner = buildOwner();
owner.register('template:-top-level', template);
Expand All @@ -37,89 +39,91 @@ function checkTemplate(templateName) {
component = owner.lookup('component:-top-level');
runAppend(component);

equal(jQuery('#qunit-fixture').text().trim(), 'Tobias takes teamocil', 'template works');
assert.equal(jQuery('#qunit-fixture').text().trim(), 'Tobias takes teamocil', 'template works');
runDestroy(component);
}

QUnit.module('ember-templates: bootstrap', {
setup() {
moduleFor('ember-templates: bootstrap', class extends AbstractTestCase {
constructor() {
super();

fixture = document.getElementById('qunit-fixture');
},
}

teardown() {
setTemplates({});
runDestroy(component);
}
});

QUnit.test('template with data-template-name should add a new template to Ember.TEMPLATES', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" data-template-name="funkyTemplate">{{firstName}} takes {{drug}}</script>');
['@test template with data-template-name should add a new template to Ember.TEMPLATES'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" data-template-name="funkyTemplate">{{firstName}} takes {{drug}}</script>');

checkTemplate('funkyTemplate');
});
checkTemplate('funkyTemplate', assert);
}

QUnit.test('template with id instead of data-template-name should add a new template to Ember.TEMPLATES', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" id="funkyTemplate" >{{firstName}} takes {{drug}}</script>');
['@test template with id instead of data-template-name should add a new template to Ember.TEMPLATES'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" id="funkyTemplate" >{{firstName}} takes {{drug}}</script>');

checkTemplate('funkyTemplate');
});
checkTemplate('funkyTemplate', assert);
}

QUnit.test('template without data-template-name or id should default to application', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">{{firstName}} takes {{drug}}</script>');
['@test template without data-template-name or id should default to application'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">{{firstName}} takes {{drug}}</script>');

checkTemplate('application');
});
checkTemplate('application', assert);
}

if (typeof Handlebars === 'object') {
QUnit.test('template with type text/x-raw-handlebars should be parsed', function() {
// Add this test case, only for typeof Handlebars === 'object';
[`${typeof Handlebars === 'object' ? '@test' : '@skip'} template with type text/x-raw-handlebars should be parsed`](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-raw-handlebars" data-template-name="funkyTemplate">{{name}}</script>');

run(() => bootstrap({ context: fixture, hasTemplate, setTemplate }));

let template = getTemplate('funkyTemplate');

ok(template, 'template with name funkyTemplate available');
assert.ok(template, 'template with name funkyTemplate available');

// This won't even work with Ember templates
equal(trim(template({ name: 'Tobias' })), 'Tobias');
});
}
assert.equal(trim(template({ name: 'Tobias' })), 'Tobias');
}

QUnit.test('duplicated default application templates should throw exception', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">first</script><script type="text/x-handlebars">second</script>');
['@test duplicated default application templates should throw exception'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">first</script><script type="text/x-handlebars">second</script>');

throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
});
assert.throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
}

QUnit.test('default application template and id application template present should throw exception', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">first</script><script type="text/x-handlebars" id="application">second</script>');
['@test default default application template and id application template present should throw exception'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">first</script><script type="text/x-handlebars" id="application">second</script>');

throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
});
assert.throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
}

QUnit.test('default application template and data-template-name application template present should throw exception', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">first</script><script type="text/x-handlebars" data-template-name="application">second</script>');
['@test default application template and data-template-name application template present should throw exception'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars">first</script><script type="text/x-handlebars" data-template-name="application">second</script>');

throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
});
assert.throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
}

QUnit.test('duplicated template id should throw exception', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" id="funkyTemplate">first</script><script type="text/x-handlebars" id="funkyTemplate">second</script>');
['@test duplicated template id should throw exception'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" id="funkyTemplate">first</script><script type="text/x-handlebars" id="funkyTemplate">second</script>');

throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
});
assert.throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
}

QUnit.test('duplicated template data-template-name should throw exception', function() {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" data-template-name="funkyTemplate">first</script><script type="text/x-handlebars" data-template-name="funkyTemplate">second</script>');
['@test duplicated template data-template-name should throw exception'](assert) {
jQuery('#qunit-fixture').html('<script type="text/x-handlebars" data-template-name="funkyTemplate">first</script><script type="text/x-handlebars" data-template-name="funkyTemplate">second</script>');

throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
assert.throws(() => bootstrap({ context: fixture, hasTemplate, setTemplate }),
/Template named "[^"]+" already exists\./,
'duplicate templates should not be allowed');
}
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { compileOptions } from '../../index';
import { defaultPlugins } from '../../index';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

QUnit.module('ember-template-compiler: default compile options');

QUnit.test('default options are a new copy', function() {
notEqual(compileOptions(), compileOptions());
});
moduleFor('ember-template-compiler: default compile options', class extends AbstractTestCase {
['@test default options are a new copy'](assert) {
assert.notEqual(compileOptions(), compileOptions());
}

QUnit.test('has default AST plugins', function(assert) {
assert.expect(defaultPlugins.length);
['@test has default AST plugins'](assert) {
assert.expect(defaultPlugins.length);

let plugins = compileOptions().plugins.ast;
let plugins = compileOptions().plugins.ast;

for (let i = 0; i < defaultPlugins.length; i++) {
let plugin = defaultPlugins[i];
assert.ok(plugins.indexOf(plugin) > -1, `includes ${plugin}`);
for (let i = 0; i < defaultPlugins.length; i++) {
let plugin = defaultPlugins[i];
assert.ok(plugins.indexOf(plugin) > -1, `includes ${plugin}`);
}
}
});

0 comments on commit 1e0128e

Please sign in to comment.