Skip to content

Commit

Permalink
Merge branch 'nested-collection-scope'
Browse files Browse the repository at this point in the history
  • Loading branch information
san650 committed Oct 17, 2015
2 parents d867bd3 + 890f24b commit e2be4e3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Chris Santero (https://github.com/csantero)
Spencer P <spencer@ravellaw.com> (https://github.com/spencer516)
Cory Forsyth <cory.forsyth@gmail.com> (https://github.com/bantic)
Matthew Beale <matt.beale@madhatted.com> (https://github.com/mixonic)
Buck Doyle <b@chromatin.ca> (https://github.com/backspace)
8 changes: 6 additions & 2 deletions test-support/page-object/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function preProcess(target, key, options) {
definition.count = count(options.itemScope);
}

options.collectionComponent = build(definition);
options.collectionComponent = definition;
}

function getCollection(target, key, options, index) {
Expand All @@ -59,7 +59,11 @@ function getCollection(target, key, options, index) {
component.__forceScopeToChildren = true;
component = build(component);
} else {
component = options.collectionComponent;
if (target.__forceScopeToChildren) {
options.collectionComponent.scope = target.scope;
}

component = build(options.collectionComponent);
}

return component;
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/components/collection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,43 @@ test('assigns the correct scope to item sub components when component doesn\'t d
assert.equal(attribute(1).anotherComponent().text(), 'Lorem');
});

test('assigns the correct scope to sub collection component', function(assert) {
fixture('<div><span></span><span></span></div><div><span></span></div>');

let attribute = buildProperty(
collection({
itemScope: 'div',
item: {
spans: collection({
itemScope: 'span'
})
}
})
).toFunction();

assert.equal(attribute(1).spans().count(), 2);
});

test('assigns the correct scope to sub collection items', function(assert) {
fixture('<div><span>Lorem</span><span>Ipsum</span></div><div><span>Dolor</span></div>');

let attribute = buildProperty(
collection({
itemScope: 'div',
item: {
spans: collection({
itemScope: 'span',
item: {
text: text()
}
})
}
})
).toFunction();

assert.equal(attribute(1).spans(2).text(), 'Ipsum');
});

import { build } from '../../page-object/build';

test('doesn\'t mutate collection definition', function(assert) {
Expand Down

0 comments on commit e2be4e3

Please sign in to comment.