Skip to content

Commit

Permalink
[CLEANUP beta] Assert on view and controller keywords
Browse files Browse the repository at this point in the history
(cherry picked from commit 8f72bf2)
  • Loading branch information
mixonic authored and rwjblue committed Aug 13, 2015
1 parent 75b2a74 commit abdc442
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 258 deletions.
60 changes: 44 additions & 16 deletions packages/ember-htmlbars/tests/compat/controller_keyword_test.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,100 @@
import Ember from 'ember-metal/core';
import EmberComponent from 'ember-views/views/component';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import compile from 'ember-template-compiler/system/compile';

import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';
import AssertNoViewAndControllerPaths from 'ember-template-compiler/plugins/assert-no-view-and-controller-paths';

let component;

QUnit.module('ember-htmlbars: compat - controller keyword (use as a path)', {
setup() {
Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false;
registerAstPlugin(AssertNoViewAndControllerPaths);

component = null;
},
teardown() {
runDestroy(component);

removeAstPlugin(AssertNoViewAndControllerPaths);
Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = true;
}
});

QUnit.test('reading the controller keyword fails assertion', function() {
var text = 'a-prop';
expectAssertion(function() {
component = EmberComponent.extend({
prop: text,
layout: compile('{{controller.prop}}')
}).create();

runAppend(component);
}, /Using `{{controller}}` or any path based on it .*/);
});

QUnit.module('ember-htmlbars: compat - controller keyword (use as a path) [LEGACY]', {
setup() {
registerAstPlugin(TransformEachIntoCollection);
registerAstPlugin(DeprecateViewAndControllerPaths);

component = null;
},
teardown() {
runDestroy(component);

removeAstPlugin(TransformEachIntoCollection);
removeAstPlugin(DeprecateViewAndControllerPaths);
}
});

QUnit.test('reading the controller keyword is deprecated [DEPRECATED]', function() {
QUnit.test('reading the controller keyword works [LEGACY]', function() {
var text = 'a-prop';
expectDeprecation(function() {
ignoreAssertion(function() {
component = EmberComponent.extend({
prop: text,
layout: compile('{{controller.prop}}')
}).create();
}, /Using `{{controller}}` or any path based on it .*/);

runAppend(component);
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
runAppend(component);
equal(component.$().text(), text, 'controller keyword is read');
});

QUnit.test('reading the controller keyword for hash is deprecated [DEPRECATED]', function() {
expectDeprecation(function() {
QUnit.test('reading the controller keyword for hash [LEGACY]', function() {
ignoreAssertion(function() {
component = EmberComponent.extend({
prop: true,
layout: compile('{{if true \'hiho\' option=controller.prop}}')
}).create();

runAppend(component);
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
}, /Using `{{controller}}` or any path based on it .*/);
ok(true, 'access keyword');
});

QUnit.test('reading the controller keyword for param is deprecated [DEPRECATED]', function() {
QUnit.test('reading the controller keyword for param [LEGACY]', function() {
var text = 'a-prop';
expectDeprecation(function() {
ignoreAssertion(function() {
component = EmberComponent.extend({
prop: true,
layout: compile(`{{if controller.prop '${text}'}}`)
}).create();

runAppend(component);
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
}, /Using `{{controller}}` or any path based on it .*/);
equal(component.$().text(), text, 'controller keyword is read');
});

QUnit.test('reading the controller keyword for param with block is deprecated [DEPRECATED]', function() {
expectDeprecation(function() {
QUnit.test('reading the controller keyword for param with block fails assertion [LEGACY]', function() {
ignoreAssertion(function() {
component = EmberComponent.extend({
prop: true,
layout: compile(`{{#each controller as |things|}}{{/each}}`)
}).create();

runAppend(component);
}, /Using `{{controller}}` or any path based on it .* has been deprecated./);
}, /Using `{{controller}}` or any path based on it .*/);
ok(true, 'access keyword');
});
60 changes: 47 additions & 13 deletions packages/ember-htmlbars/tests/compat/view_helper_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Ember from 'ember-metal/core';
import EmberComponent from 'ember-views/views/component';
import EmberView from 'ember-views/views/view';
import EmberSelectView from 'ember-views/views/select';
Expand All @@ -6,7 +7,7 @@ import compile from 'ember-template-compiler/system/compile';
import Registry from 'container/registry';

import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import DeprecateViewHelper from 'ember-template-compiler/plugins/deprecate-view-helper';
import AssertNoViewHelper from 'ember-template-compiler/plugins/assert-no-view-helper';

import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils';
import viewKeyword from 'ember-htmlbars/keywords/view';
Expand All @@ -15,7 +16,8 @@ let component, registry, container, originalViewKeyword;

QUnit.module('ember-htmlbars: compat - view helper', {
setup() {
registerAstPlugin(DeprecateViewHelper);
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;
registerAstPlugin(AssertNoViewHelper);

originalViewKeyword = registerKeyword('view', viewKeyword);

Expand All @@ -25,61 +27,93 @@ QUnit.module('ember-htmlbars: compat - view helper', {
teardown() {
runDestroy(component);
runDestroy(container);
removeAstPlugin(DeprecateViewHelper);
removeAstPlugin(AssertNoViewHelper);
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = true;
registry = container = component = null;

resetKeyword('view', originalViewKeyword);
}
});

QUnit.test('using the view helper with a string (inline form) is deprecated [DEPRECATED]', function(assert) {
QUnit.test('using the view helper fails assertion', function(assert) {
const ViewClass = EmberView.extend({
template: compile('fooView')
});
registry.register('view:foo', ViewClass);

expectDeprecation(function() {
expectAssertion(function() {
component = EmberComponent.extend({
layout: compile('{{view \'foo\'}}'),
container
}).create();

runAppend(component);
}, /Using the `{{view "string"}}` helper is deprecated/);
}, /Using the `{{view "string"}}` helper/);
});

QUnit.module('ember-htmlbars: compat - view helper [LEGACY]', {
setup() {
originalViewKeyword = registerKeyword('view', viewKeyword);

registry = new Registry();
container = registry.container();
},
teardown() {
runDestroy(component);
runDestroy(container);
registry = container = component = null;

resetKeyword('view', originalViewKeyword);
}
});

QUnit.test('using the view helper with a string (inline form) fails assertion [LEGACY]', function(assert) {
const ViewClass = EmberView.extend({
template: compile('fooView')
});
registry.register('view:foo', ViewClass);

ignoreAssertion(function() {
component = EmberComponent.extend({
layout: compile('{{view \'foo\'}}'),
container
}).create();

runAppend(component);
});

assert.equal(component.$().text(), 'fooView', 'view helper is still rendered');
});

QUnit.test('using the view helper with a string (block form) is deprecated [DEPRECATED]', function(assert) {
QUnit.test('using the view helper with a string (block form) fails assertion [LEGACY]', function(assert) {
const ViewClass = EmberView.extend({
template: compile('Foo says: {{yield}}')
});
registry.register('view:foo', ViewClass);

expectDeprecation(function() {
ignoreAssertion(function() {
component = EmberComponent.extend({
layout: compile('{{#view \'foo\'}}I am foo{{/view}}'),
container
}).create();

runAppend(component);
}, /Using the `{{view "string"}}` helper is deprecated/);
});

assert.equal(component.$().text(), 'Foo says: I am foo', 'view helper is still rendered');
});

QUnit.test('using the view helper with string "select" has its own deprecation message [DEPRECATED]', function(assert) {
QUnit.test('using the view helper with string "select" fails assertion [LEGACY]', function(assert) {
registry.register('view:select', EmberSelectView);

expectDeprecation(function() {
ignoreAssertion(function() {
component = EmberComponent.extend({
layout: compile('{{view \'select\'}}'),
container
}).create();

runAppend(component);
}, /Using `{{view "select"}}` is deprecated/);
});

assert.ok(!!component.$('select').length, 'still renders select');
});

17 changes: 9 additions & 8 deletions packages/ember-htmlbars/tests/compat/view_keyword_test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import Ember from 'ember-metal/core';
import EmberComponent from 'ember-views/views/component';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import compile from 'ember-template-compiler/system/compile';

import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';
import AssertNoViewAndControllerPaths from 'ember-template-compiler/plugins/assert-no-view-and-controller-paths';

let component;

QUnit.module('ember-htmlbars: compat - view keyword (use as a path)', {
setup() {
registerAstPlugin(DeprecateViewAndControllerPaths);
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = false;
registerAstPlugin(AssertNoViewAndControllerPaths);
component = null;
},
teardown() {
runDestroy(component);
removeAstPlugin(DeprecateViewAndControllerPaths);
removeAstPlugin(AssertNoViewAndControllerPaths);
Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT = true;
}
});

QUnit.test('reading the view keyword is deprecated [DEPRECATED]', function() {
QUnit.test('reading the view keyword fails assertion', function() {
var text = 'a-prop';
expectDeprecation(function() {
expectAssertion(function() {
component = EmberComponent.extend({
prop: text,
layout: compile('{{view.prop}}')
}).create();

runAppend(component);
}, /Using `{{view}}` or any path based on it .* has been deprecated./);

equal(component.$().text(), text, 'view keyword is read');
}, /Using `{{view}}` or any path based on it .*/);
});

1 change: 1 addition & 0 deletions packages/ember-htmlbars/tests/helpers/collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ QUnit.test('empty views should be removed when content is added to the collectio
});

view = EmberView.create({
_viewRegistry: {},
listView: ListView,
listController: listController,
template: compile('{{#collection view.listView content=view.listController tagName="table"}} <td>{{view.content.title}}</td> {{/collection}}')
Expand Down
Loading

0 comments on commit abdc442

Please sign in to comment.