Skip to content

Commit

Permalink
test for #312
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 16, 2017
1 parent 1bf03a9 commit 8b3f032
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
70 changes: 70 additions & 0 deletions test/generator/samples/binding-input-checkbox-group/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export default {
data: {
values: [ 'Alpha', 'Beta', 'Gamma' ],
selected: [ 'Beta' ]
},

html: `
<label>
<input type="checkbox"> Alpha
</label>
<label>
<input type="checkbox"> Beta
</label>
<label>
<input type="checkbox"> Gamma
</label>
<p>Beta</p>`,

test ( assert, component, target, window ) {
const inputs = target.querySelectorAll( 'input' );
assert.equal( inputs[0].checked, false );
assert.equal( inputs[1].checked, true );
assert.equal( inputs[2].checked, false );

const event = new window.Event( 'change' );

inputs[0].checked = true;
inputs[0].dispatchEvent( event );

assert.equal( target.innerHTML, `
<label>
<input type="checkbox"> Alpha
</label>
<label>
<input type="checkbox"> Beta
</label>
<label>
<input type="checkbox"> Gamma
</label>
<p>Alpha, Beta</p>
` );

component.set({ selected: [ 'Beta', 'Gamma' ] });
assert.equal( inputs[0].checked, false );
assert.equal( inputs[1].checked, true );
assert.equal( inputs[2].checked, true );

assert.equal( target.innerHTML, `
<label>
<input type="checkbox"> Alpha
</label>
<label>
<input type="checkbox"> Beta
</label>
<label>
<input type="checkbox"> Gamma
</label>
<p>Beta, Gamma</p>
` );
}
};
7 changes: 7 additions & 0 deletions test/generator/samples/binding-input-checkbox-group/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{#each values as value}}
<label>
<input type="checkbox" value="{{value}}" bind:group='selected' /> {{value}}
</label>
{{/each}}

<p>{{selected}}</p>
6 changes: 5 additions & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ function cleanChildren ( node ) {

child.data = child.data.replace( /\s{2,}/, '\n' );

if ( child.data === '\n' ) {
node.removeChild( child );
}

// text
if ( previous && previous.nodeType === 3 ) {
else if ( previous && previous.nodeType === 3 ) {
previous.data += child.data;
previous.data = previous.data.replace( /\s{2,}/, '\n' );

Expand Down

0 comments on commit 8b3f032

Please sign in to comment.