if(typeof require === 'function') var kff = require('../build/kff.js');

describe('kff.CheckBinder', function()
{
	it('should bind check binder', function()
	{
		var myModel = new kff.Cursor({
			checked: true
		});

		var dispatcher = new kff.Dispatcher({
			set: function(event)
			{
				event.cursor.set(event.value);
				return {
					type: 'refresh'
				};
			}
		});

		var $input = $('<input type="checkbox" data-kff-bind="myModel.checked:check"/>');
		var view = new kff.View(
		{
			element: $input[0],
			scope: {
				myModel: myModel
			},
			dispatcher: dispatcher
		});
		view.renderAll();
		view.runAll();

		expect($input.is(':checked')).to.equal(true);
		myModel.setIn('checked', false);
		view.refreshAll();

		expect($input.is(':checked')).to.equal(false);

		$input[0].dispatchEvent(new MouseEvent('click'));
		// emitEvent($input[0], 'click');

		expect(myModel.getIn('checked')).to.equal(true);
	});

});

@@ -159,23 +159,21 @@
 %7B%0A%09%09var 
-myModel
+state
  = new k
@@ -186,30 +186,12 @@
 sor(
-%7B%0A%09%09%09checked: true%0A%09%09%7D
+true
 );%0A%0A
@@ -357,17 +357,16 @@
 var 
-$
 input = 
 $('%3C
@@ -365,77 +365,138 @@
 t = 
-$('%3Cinput type=%22checkbox%22 data-kff-bind=%22myModel.checked
+document.createElement('input');%0A%09%09input.setAttribute('type', 'checkbox');%0A%09%09input.setAttribute('data-kff-bind', 'state
 :check
-%22/%3E
 ');%0A
+%0A
 %09%09va
@@ -534,25 +534,21 @@
 lement: 
-$
 input
-%5B0%5D
 ,%0A%09%09%09sco
@@ -561,24 +561,20 @@
 %09%09%09%09
-myModel: myModel
+state: state
 %0A%09%09%09
@@ -619,18 +619,77 @@
 iew.
-renderAll(
+initAll();%0A%0A%09%09expect(input.checked).to.equal(true);%0A%09%09state.set(false
 );%0A%09
@@ -695,18 +695,22 @@
 %09%09view.r
-un
+efresh
 All();%0A%0A
@@ -722,96 +722,759 @@
 ect(
-$
 input.
-is(':checked')).to.equal(true);%0A%09%09myModel.setIn('checked', fals
+checked).to.equal(false);%0A%0A%09%09input.dispatchEvent(new MouseEvent('click'));%0A%09%09// emitEvent(input, 'click');%0A%0A%09%09expect(state.get()).to.equal(true);%0A%09%7D);%0A%0A%0A%09it('should bind check binder to non-boolean state', function()%0A%09%7B%0A%09%09var checkedValue = 'checkedValue';%0A%09%09var state = new kff.Cursor(checkedValu
 e);%0A
+%0A
 %09%09v
-iew.refresh
+ar dispatcher = new kff.Dispatcher(%7B%0A%09%09%09set: function(event)%0A%09%09%09%7B%0A%09%09%09%09event.cursor.set(event.value);%0A%09%09%09%09return %7B%0A%09%09%09%09%09type: 'refresh'%0A%09%09%09%09%7D;%0A%09%09%09%7D%0A%09%09%7D);%0A%0A%09%09var input = document.createElement('input');%0A%09%09input.setAttribute('type', 'checkbox');%0A%09%09input.setAttribute('data-kff-bind', 'state:check(checkedValue)');%0A%0A%09%09var view = new kff.View(%0A%09%09%7B%0A%09%09%09element: input,%0A%09%09%09scope: %7B%0A%09%09%09%09state: state%0A%09%09%09%7D,%0A%09%09%09dispatcher: dispatcher%0A%09%09%7D);%0A%09%09view.init
 All(
@@ -1490,29 +1490,114 @@
 ect(
-$
 input.
-is(':checked')
+checked).to.equal(true);%0A%09%09state.set('uncheckedValue');%0A%09%09view.refreshAll();%0A%0A%09%09expect(input.checked
 ).to
@@ -1614,25 +1614,21 @@
 se);%0A%0A%09%09
-$
 input
-%5B0%5D
 .dispatc
@@ -1679,17 +1679,13 @@
 ent(
-$
 input
-%5B0%5D
 , 'c
@@ -1706,31 +1706,18 @@
 ect(
-myModel.getIn('checked'
+state.get(
 )).t
@@ -1716,33 +1716,41 @@
 get()).to.equal(
-tr
+checkedVal
 ue);%0A%09%7D);%0A%0A%7D);%0A

update tests, add test for non-boolean value