Skip to content

Commit

Permalink
Scope LayoutView regions to the view's elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jmca authored and samccone committed Jan 14, 2015
1 parent ab7e123 commit be8df33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/layout-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Marionette.LayoutView = Marionette.ItemView.extend({
_buildRegions: function(regions) {
var defaults = {
regionClass: this.getOption('regionClass'),
parentEl: _.partial(_.result, this, '$el')
parentEl: _.partial(_.result, this, 'el')
};

return this.regionManager.addRegions(regions, defaults);
Expand Down
32 changes: 31 additions & 1 deletion test/unit/layout-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,44 @@ describe('layoutView', function() {
beforeEach(function () {
this.layout = new this.LayoutView();
this.layout.render();

this.regions = this.layout.getRegions();
});

it("should be able to retrieve all regions", function () {
expect(this.regions.regionOne).to.equal(this.layout.getRegion("regionOne"));
expect(this.regions.regionTwo).to.equal(this.layout.getRegion("regionTwo"));
});

describe('when the regions are specified via regions hash and the view has no template', function () {
beforeEach(function () {
var fixture =
'<div class="region-hash-no-template-spec">' +
'<div class="region-one">Out-of-scope region</div>' +
'<div class="some-layout-view">' +
'<div class="region-one">In-scope region</div>' +
'</div>' +
'</div>';
this.setFixtures(fixture);
this.LayoutView = Backbone.Marionette.LayoutView.extend({
el: '.region-hash-no-template-spec .some-layout-view',
template: false,
regions: {
regionOne: '.region-one'
}
});
this.layoutViewInstance = new this.LayoutView();
this.layoutViewInstance.render();
var $specNode = $('.region-hash-no-template-spec');
this.$inScopeRegion = $specNode.find('.some-layout-view .region-one');
this.$outOfScopeRegion = $specNode.children('.region-one');
});

it('after initialization, the view\'s regions should be scoped to its parent view', function () {
expect(this.layoutViewInstance.regionOne.$el).to.have.length(1);
expect(this.layoutViewInstance.regionOne.$el.is(this.$inScopeRegion)).to.equal(true);
expect(this.layoutViewInstance.regionOne.$el.is(this.$outOfScopeRegion)).to.equal(false);
});
});
});

describe('manipulating regions', function () {
Expand Down

0 comments on commit be8df33

Please sign in to comment.