66} from 'ember-qunit' ;
77import hbs from 'htmlbars-inline-precompile' ;
88import { alice , alice2 , bob } from '../../helpers/person' ;
9- import hasEmberVersion from 'ember-test-helpers/has-ember-version' ;
109
1110moduleForComponent ( 'radio-button' , 'RadioButtonComponent' , {
1211 integration : true
@@ -39,7 +38,7 @@ test('it updates when clicked, and triggers the `changed` action', function(asse
3938 {{radio-button
4039 groupValue=groupValue
4140 value='component-value'
42- changed=' changed'
41+ changed=(action " changed")
4342 }}
4443 ` ) ;
4544
@@ -56,6 +55,28 @@ test('it updates when clicked, and triggers the `changed` action', function(asse
5655 assert . equal ( changedActionCallCount , 1 ) ;
5756} ) ;
5857
58+ test ( 'when no action is passed, updating does not error' , function ( assert ) {
59+ assert . expect ( 3 ) ;
60+
61+ this . set ( 'groupValue' , 'initial-group-value' ) ;
62+
63+ this . render ( hbs `
64+ {{radio-button
65+ groupValue=groupValue
66+ value='component-value'
67+ }}
68+ ` ) ;
69+
70+ assert . equal ( this . $ ( 'input' ) . prop ( 'checked' ) , false , 'starts unchecked' ) ;
71+
72+ run ( ( ) => {
73+ this . $ ( 'input' ) . trigger ( 'click' ) ;
74+ } ) ;
75+
76+ assert . equal ( this . $ ( 'input' ) . prop ( 'checked' ) , true , 'updates element property' ) ;
77+ assert . equal ( this . get ( 'groupValue' ) , 'component-value' , 'updates groupValue' ) ;
78+ } ) ;
79+
5980test ( 'it updates when the browser change event is fired' , function ( assert ) {
6081 let changedActionCallCount = 0 ;
6182 this . on ( 'changed' , ( ) => {
@@ -68,7 +89,7 @@ test('it updates when the browser change event is fired', function(assert) {
6889 {{radio-button
6990 groupValue=groupValue
7091 value='component-value'
71- changed=' changed'
92+ changed=(action " changed")
7293 }}
7394 ` ) ;
7495
@@ -94,7 +115,6 @@ test('it gives the label of a wrapped checkbox a `checked` className', function(
94115 {{#radio-button
95116 groupValue=groupValue
96117 value=value
97- changed='changed'
98118 classNames='blue-radio'
99119 ~}}
100120 Blue
@@ -121,7 +141,6 @@ test('providing `checkedClass` gives the label a custom classname when the radio
121141 groupValue=groupValue
122142 value=value
123143 checkedClass="my-custom-class"
124- changed='changed'
125144 classNames='blue-radio'
126145 ~}}
127146 Blue
@@ -364,35 +383,33 @@ test('it binds `aria-describedby` when specified', function(assert) {
364383 assert . equal ( this . $ ( 'input' ) . attr ( 'aria-describedby' ) , 'green-label' ) ;
365384} ) ;
366385
367- if ( hasEmberVersion ( 1 , 13 ) ) {
368- test ( 'it updates when clicked, and triggers the `changed` action when a closure action is passed in' , function ( assert ) {
369- assert . expect ( 5 ) ;
386+ test ( 'it updates when clicked, and supports legacy-style string `changed` actions' , function ( assert ) {
387+ assert . expect ( 5 ) ;
370388
371- let changedActionCallCount = 0 ;
372- this . on ( 'changed' , function ( ) {
373- changedActionCallCount ++ ;
374- } ) ;
389+ let changedActionCallCount = 0 ;
390+ this . on ( 'changed' , function ( ) {
391+ changedActionCallCount ++ ;
392+ } ) ;
375393
376- this . set ( 'groupValue' , 'initial-group-value' ) ;
394+ this . set ( 'groupValue' , 'initial-group-value' ) ;
377395
378- this . render ( hbs `
379- {{radio-button
380- groupValue=groupValue
381- value=' component-value'
382- changed=(action ' changed')
383- }}
384- ` ) ;
396+ this . render ( hbs `
397+ {{radio-button
398+ groupValue=groupValue
399+ value=" component-value"
400+ changed=" changed"
401+ }}
402+ ` ) ;
385403
386- assert . equal ( changedActionCallCount , 0 ) ;
387- assert . equal ( this . $ ( 'input' ) . prop ( 'checked' ) , false ) ;
404+ assert . equal ( changedActionCallCount , 0 ) ;
405+ assert . equal ( this . $ ( 'input' ) . prop ( 'checked' ) , false ) ;
388406
389- run ( ( ) => {
390- this . $ ( 'input' ) . trigger ( 'click' ) ;
391- } ) ;
407+ run ( ( ) => {
408+ this . $ ( 'input' ) . trigger ( 'click' ) ;
409+ } ) ;
392410
393- assert . equal ( this . $ ( 'input' ) . prop ( 'checked' ) , true , 'updates element property' ) ;
394- assert . equal ( this . get ( 'groupValue' ) , 'component-value' , 'updates groupValue' ) ;
411+ assert . equal ( this . $ ( 'input' ) . prop ( 'checked' ) , true , 'updates element property' ) ;
412+ assert . equal ( this . get ( 'groupValue' ) , 'component-value' , 'updates groupValue' ) ;
395413
396- assert . equal ( changedActionCallCount , 1 ) ;
397- } ) ;
398- }
414+ assert . equal ( changedActionCallCount , 1 ) ;
415+ } ) ;
0 commit comments