Skip to content

Commit

Permalink
Ensure that TemplateViews created with an ID by the Handlebars view h…
Browse files Browse the repository at this point in the history
…elper are added to view cache, unit test included
  • Loading branch information
Colin Campbell committed Apr 5, 2011
1 parent 5eb5248 commit 7d4f778
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions frameworks/core_foundation/tests/views/template/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,27 @@ test("Child views created using the view helper should have their parent view se
equals(childView, childView.childViews[0].parentView, 'parent view is correct');
});

test("Child views created using the view helper should have their IDs registered for events", function() {
TemplateTests = {};

var template = '{{view "SC.TemplateView"}}{{view "SC.TemplateView" id="templateViewTest"}}';

var view = SC.TemplateView.create({
template: SC.Handlebars.compile(template)
});

view.createLayer();

var childView = view.childViews[0];
var id = childView.$()[0].id;
equals(SC.View.views[id], childView, 'childView without passed ID is registered with SC.View.views so that it can properly receive events from RootResponder');

childView = view.childViews[1];
id = childView.$()[0].id;
equals(id, 'templateViewTest', 'precond -- id of childView should be set correctly');
equals(SC.View.views[id], childView, 'childView with passed ID is registered with SC.View.views so that it can properly receive events from RootResponder');
});

test("Collection views that specify an example view class have their children be of that class", function() {
TemplateTests.ExampleViewCollection = SC.TemplateCollectionView.create({
itemView: SC.TemplateView.extend({
Expand Down
2 changes: 2 additions & 0 deletions frameworks/handlebars/extensions/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SC.Handlebars.ViewHelper = SC.Object.create({
if (!newView) { throw "Unable to find view at path '" + path + "'"; }
}

if (hash.id) hash.layerId = hash.id;

var contextOptions = {
'id': hash.id,
'class': hash['class'],
Expand Down

0 comments on commit 7d4f778

Please sign in to comment.