Consistency tests

Edit me

Using Epicraft

Consistency tests doesn’t exists yet in Epicraft.

Using a specific component

You can define and attach a function to a variable.

Each variables of a dataset has a list of functions to validate its validity (mandatory, min/max, length, …) but there is a special space at the end of the list which is empty and wait for you to add something.

Caution, you can only add one function on each variable. If you set it again, it will overwrite the previous one.

To be sure the validator is active right when opening the project, add a specific component (bulk) to your welcome page then add the function in the constructor.

oDataset.setValidation(sVariableName, fValidator)

This function attach your validation function to a variable. It can be an array of function if needed.

The output of your validator can be:

  • boolean
  • number (-1 error, 0 init, 1 warning, 2 info, 3 success)
  • object
    return {
      iStatus: 2,
      sMessage: "These aren't the Droids you're looking for."
    };
    

Example

// Library
import React from 'react';
import PropTypes from 'prop-types';

// Check if a variable is superior to another
export default class ConsistencySuperior extends React.Component {
	constructor(oProps) {
		super(oProps);

		// get options of the bulk (and datasets of the project)
		const {option, datasets: aDatasets} = oProps;
		const {
			datasetName: sDatasetName,
			variableNameA: sVariableNameA,
			variableNameB: sVariableNameB
		} = option;

		// search for the right dataset
		const oDataset = aDatasets.find(oDataset => oDataset.getName() === sDatasetName);
		if (oDataset === undefined) {
			return console.error(`Couldn't find the dataset "${sDatasetName}".`);
		}

		oDataset.setValidation(
			sVariableNameA,
			(sVariableName, oVariableDef, oRowData) => {
				const mValueA = oRowData.getValue(sVariableName);
				const mValueB = oRowData.getValue(sVariableNameB);

				return mValueA > mValueB;
			}
		);
	}

	render() {
		return null;
	}
}

ConsistencySuperior.propTypes = {
	option: PropTypes.object,
	datasets: PropTypes.array
};

ConsistencySuperior.defaultProps = {
	option: {}
};