/* global describe, it, before, beforeEach, require */
'use strict';

// MODULES //

var // Expectation library:
	chai = require( 'chai' ),

	// Module to be tested:
	validate = require( './../lib' );


// VARIABLES //

var expect = chai.expect,
	assert = chai.assert;


// FIXTURES //

var tmpl = require( './fixtures/template.json' );


// TESTS //

describe( 'marks', function tests() {

	var template;

	before( function before() {
		tmpl = JSON.stringify( tmpl );
	});

	beforeEach( function beforeEach() {
		template = JSON.parse( tmpl );
	});

	it( 'should invalidate a chart configuration without a marks field', function test() {
		template.marks = undefined;
		assert.notOk( validate( template ) );
		assert.strictEqual( validate.errors.length, 1 );
	});

	it( 'should invalidate a chart configuration with an invalid marks field (non-array)', function test() {
		var values = [
			5,
			true,
			null,
			NaN,
			function(){},
			{},
			'beep'
		];

		var marks = template.marks;
		for ( var i = 0; i < values.length; i++ ) {
			template.marks = marks;
			template.marks = values[ i ];
			assert.notOk( validate( template ) );
			assert.strictEqual( validate.errors.length, 1 );
		}
	});

	it( 'should invalidate a chart configuration without at least one mark', function test() {
		template.marks = [];
		assert.notOk( validate( template ) );
		assert.strictEqual( validate.errors.length, 1 );
	});

});
