'use strict';

// MODULES //

var tape = require( 'tape' );
var Rug = require( './../lib' );


// FIXTURES //

var VTREE = require( './fixtures/vtree.js' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.strictEqual( typeof Rug, 'function', 'main export is a function' );
	t.end();
});

tape( 'if `autoRender` is `true`, when a returned instance receives a `change` event, it re-renders and emits a `render` event', function test( t ) {
	var node = new Rug({
		'data': [ 0.10, 0.50, 0.90 ],
		'autoRender': true
	});
	node.on( 'render', onRender );
	node.emit( 'change' );

	function onRender( obj ) {
		t.ok( true, 'emits a render event' );
		t.deepEqual( obj, VTREE, 'provides virtual tree' );
		t.end();
	}
});

tape( 'if `autoRender` is `false`, when a returned instance receives a `change` event, it does not re-render or emit a `render` event', function test( t ) {
	var node = new Rug({
		'data': [ 0.10, 0.50, 0.90 ],
		'autoRender': false
	});
	node.on( 'render', onRender );
	node.emit( 'change' );
	t.pass( 'is ok' );
	t.end();

	function onRender() {
		t.fail( 'should never be invoked' );
	}
});

'use strict';

// MODULES //

var tape = require( 'tape' );
var Rug = require( './../lib' );


// FIXTURES //

var VTREE = require( './fixtures/vtree.js' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.strictEqual( typeof Rug, 'function', 'main export is a function' );
	t.end();
});

tape( 'if `autoRender` is `true`, when a returned instance receives a `change` event, it re-renders and emits a `render` event', function test( t ) {
	var node = new Rug({
		'data': [ 0.10, 0.50, 0.90 ],
		'autoRender': true
	});
	node.on( 'render', onRender );
	node.emit( 'change' );

	function onRender( obj ) {
		t.ok( true, 'emits a render event' );
		t.deepEqual( obj, VTREE, 'provides virtual tree' );
		t.end();
	}
});

tape( 'if `autoRender` is `false`, when a returned instance receives a `change` event, it does not re-render or emit a `render` event', function test( t ) {
	var node = new Rug({
		'data': [ 0.10, 0.50, 0.90 ],
		'autoRender': false
	});
	node.on( 'render', onRender );
	node.emit( 'change' );
	t.pass( 'is ok' );
	t.end();

	function onRender() {
		t.fail( 'should never be invoked' );
	}
});

tape( 'setting the `autoRender` property triggers a `change` event', function test( t ) {
	var node = new Rug({
		'autoRender': true
	});
	node.on( 'change', onChange );
	node.autoRender = false;

	function onChange() {
		t.ok( true, 'triggers event' );
		t.end();
	}
});

tape( 'setting the `autoRender` property triggers a `change` event', function test( t ) {
	var node = new Rug({
		'autoRender': false
	});
	node.on( 'change', onChange );
	node.autoRender = true;

	function onChange() {
		t.ok( true, 'triggers event' );
		t.end();
	}
});

tape( 'setting the `autoRender` property triggers a `change` event', function test( t ) {
	var node = new Rug({
		'autoRender': true
	});
	node.on( 'change', onChange );
	node.autoRender = true;

	function onChange() {
		t.ok( true, 'triggers event' );
		t.end();
	}
});

tape( 'setting the `autoRender` property triggers a `change` event', function test( t ) {
	var node = new Rug({
		'autoRender': false
	});
	node.on( 'change', onChange );
	node.autoRender = false;

	function onChange() {
		t.ok( true, 'triggers event' );
		t.end();
	}
});

Add tests