@@ -59,25 +59,37 @@ module.exports = (function () {
5959 QUnit . ok ( input . checked , 'input checked boolean returns true because that\'s how it was initially' ) ;
6060 } ) ;
6161
62- QUnit . test ( 'checking/unchecking callbacks ' , function ( ) {
63- QUnit . expect ( 4 ) ;
62+ QUnit . test ( 'should trigger onChecked callback option with correct args when checked ' , function ( ) {
63+ QUnit . expect ( 2 ) ;
6464 var fixture = document . getElementById ( 'qunit-fixture' ) ;
6565 var container = TestUtils . createHtmlElement ( html ) ;
6666 fixture . appendChild ( container ) ;
6767 var input = container . getElementsByClassName ( 'ui-checkbox-input' ) [ 0 ] ;
6868 var onCheckedSpy = Sinon . spy ( ) ;
69- var onUncheckedSpy = Sinon . spy ( ) ;
70- var checkbox = new Checkbox ( { el : input , onChecked : onCheckedSpy , onUnchecked : onUncheckedSpy } ) ;
69+ var checkbox = new Checkbox ( { el : input , onChecked : onCheckedSpy } ) ;
7170 var UICheckbox = container . getElementsByClassName ( 'ui-checkbox' ) [ 0 ] ;
7271 checkbox . check ( ) ;
7372 QUnit . deepEqual ( onCheckedSpy . args [ 0 ] , [ 'NY' , input , UICheckbox ] , 'on check(), onChecked callback was fired with correct args' ) ;
74- QUnit . equal ( onUncheckedSpy . callCount , 0 , 'onUnchecked callback was NOT fired yet' ) ;
7573 checkbox . uncheck ( ) ;
76- QUnit . deepEqual ( onUncheckedSpy . args [ 0 ] , [ 'NY' , input , UICheckbox ] , 'on uncheck(), onUnchecked callback was fired with correct args' ) ;
7774 QUnit . equal ( onCheckedSpy . callCount , 1 , 'onChecked callback was NOT fired' ) ;
7875 checkbox . destroy ( ) ;
7976 } ) ;
8077
78+ QUnit . test ( 'should trigger onUnchecked callback option with empty string and correct args when unchecked' , function ( ) {
79+ QUnit . expect ( 1 ) ;
80+ var fixture = document . getElementById ( 'qunit-fixture' ) ;
81+ var container = TestUtils . createHtmlElement ( html ) ;
82+ fixture . appendChild ( container ) ;
83+ var input = container . getElementsByClassName ( 'ui-checkbox-input' ) [ 0 ] ;
84+ var onUncheckedSpy = Sinon . spy ( ) ;
85+ var checkbox = new Checkbox ( { el : input , onUnchecked : onUncheckedSpy } ) ;
86+ var UICheckbox = container . getElementsByClassName ( 'ui-checkbox' ) [ 0 ] ;
87+ checkbox . check ( ) ;
88+ checkbox . uncheck ( ) ;
89+ QUnit . deepEqual ( onUncheckedSpy . args [ 0 ] , [ '' , input , UICheckbox ] , 'on uncheck(), onUnchecked callback was fired with correct args' ) ;
90+ checkbox . destroy ( ) ;
91+ } ) ;
92+
8193 //QUnit.test('clicking on and off ui element', function () {
8294 // QUnit.expect(12);
8395 // var fixture = document.getElementById('qunit-fixture');
@@ -201,32 +213,39 @@ module.exports = (function () {
201213 setAttrSpy . restore ( ) ;
202214 } ) ;
203215
204- QUnit . test ( 'passing truthy value to setValue() should check the checkbox, and passing a falsy value should uncheck it ' , function ( ) {
205- QUnit . expect ( 3 ) ;
216+ QUnit . test ( 'should set the value passed to setValue() onto the checkbox form element ' , function ( ) {
217+ QUnit . expect ( 1 ) ;
206218 var fixture = document . getElementById ( 'qunit-fixture' ) ;
207219 var container = TestUtils . createHtmlElement ( html ) ;
208220 fixture . appendChild ( container ) ;
209221 var checkboxEl = container . getElementsByClassName ( 'ui-checkbox-input' ) [ 0 ] ;
210222 var checkbox = new Checkbox ( { el : checkboxEl } ) ;
211- QUnit . ok ( ! checkboxEl . checked , 'not checked by default' ) ;
212- checkbox . setValue ( 'true' ) ;
213- QUnit . equal ( checkboxEl . checked , true ) ;
214- checkbox . setValue ( null ) ;
215- QUnit . equal ( checkboxEl . checked , false ) ;
223+ var testVal = 'blah' ;
224+ checkbox . setValue ( testVal ) ;
225+ QUnit . equal ( checkboxEl . value , testVal ) ;
216226 checkbox . destroy ( ) ;
217227 } ) ;
218228
219- QUnit . test ( 'getValue() should return true when checkbox is checked and false when not' , function ( ) {
220- QUnit . expect ( 2 ) ;
229+ QUnit . test ( 'getValue() should return value of the checkbox when checked' , function ( ) {
230+ QUnit . expect ( 1 ) ;
231+ var fixture = document . getElementById ( 'qunit-fixture' ) ;
232+ var container = TestUtils . createHtmlElement ( html ) ;
233+ fixture . appendChild ( container ) ;
234+ var checkbox = new Checkbox ( { el : container . getElementsByClassName ( 'ui-checkbox-input' ) [ 0 ] } ) ;
235+ checkbox . check ( ) ;
236+ QUnit . equal ( checkbox . getValue ( ) , 'NY' ) ;
237+ checkbox . destroy ( ) ;
238+ } ) ;
239+
240+ QUnit . test ( 'getValue() should return empty string when unchecked' , function ( ) {
241+ QUnit . expect ( 1 ) ;
221242 var fixture = document . getElementById ( 'qunit-fixture' ) ;
222243 var container = TestUtils . createHtmlElement ( html ) ;
223244 fixture . appendChild ( container ) ;
224245 var checkbox = new Checkbox ( { el : container . getElementsByClassName ( 'ui-checkbox-input' ) [ 0 ] } ) ;
225- // check checkbox
226246 checkbox . check ( ) ;
227- QUnit . equal ( checkbox . getValue ( ) , true ) ;
228247 checkbox . uncheck ( ) ;
229- QUnit . equal ( checkbox . getValue ( ) , false ) ;
248+ QUnit . equal ( checkbox . getValue ( ) , '' ) ;
230249 checkbox . destroy ( ) ;
231250 } ) ;
232251
@@ -264,7 +283,7 @@ module.exports = (function () {
264283 } ) ;
265284
266285 QUnit . test ( 'clicking on ui element should trigger onChange callback option with correct args' , function ( ) {
267- QUnit . expect ( 2 ) ;
286+ QUnit . expect ( 3 ) ;
268287 var fixture = document . getElementById ( 'qunit-fixture' ) ;
269288 var container = TestUtils . createHtmlElement ( html ) ;
270289 fixture . appendChild ( container ) ;
@@ -274,7 +293,26 @@ module.exports = (function () {
274293 var UICheckbox = container . getElementsByClassName ( 'ui-checkbox' ) [ 0 ] ;
275294 QUnit . equal ( onChangeSpy . callCount , 0 ) ;
276295 UICheckbox . click ( ) ;
277- QUnit . deepEqual ( onChangeSpy . args [ 0 ] , [ 'NY' , input , UICheckbox ] ) ;
296+ QUnit . deepEqual ( onChangeSpy . args [ 0 ] , [ true , input , UICheckbox ] , 'onChange was called with truth value when clicked to check' ) ;
297+ UICheckbox . click ( ) ;
298+ QUnit . deepEqual ( onChangeSpy . args [ 1 ] , [ false , input , UICheckbox ] , 'onChange was called with false value when clicked to uncheck' ) ;
299+ checkbox . destroy ( ) ;
300+ } ) ;
301+
302+ QUnit . test ( 'clicking on input checkbox element should trigger onChange callback option with correct args' , function ( ) {
303+ QUnit . expect ( 3 ) ;
304+ var fixture = document . getElementById ( 'qunit-fixture' ) ;
305+ var container = TestUtils . createHtmlElement ( html ) ;
306+ fixture . appendChild ( container ) ;
307+ var input = container . getElementsByClassName ( 'ui-checkbox-input' ) [ 0 ] ;
308+ var onChangeSpy = Sinon . spy ( ) ;
309+ var checkbox = new Checkbox ( { el : input , onChange : onChangeSpy } ) ;
310+ var UICheckbox = container . getElementsByClassName ( 'ui-checkbox' ) [ 0 ] ;
311+ QUnit . equal ( onChangeSpy . callCount , 0 ) ;
312+ input . click ( ) ;
313+ QUnit . deepEqual ( onChangeSpy . args [ 0 ] , [ true , input , UICheckbox ] , 'onChange was called with truth value when clicked to check' ) ;
314+ input . click ( ) ;
315+ QUnit . deepEqual ( onChangeSpy . args [ 1 ] , [ false , input , UICheckbox ] , 'onChange was called with false value when clicked to uncheck' ) ;
278316 checkbox . destroy ( ) ;
279317 } ) ;
280318
0 commit comments