UNPKG

flex-query

Version:

The support of javascript to make query collection object

90 lines (76 loc) 2.01 kB
const assert = require('assert'); const chalk = require('chalk1'); const test = require('./'); const good = function(message){ console.log('\t',chalk.green.bold(message)); } const error = function(message){ console.log('\t',chalk.red(message)); } const info = function(message){ console.log('\t',chalk.blue(message)); } const describe = function(message,cb){ console.log(' ',chalk.bgBlue.bold(message),'\n'); cb(); } describe('Testing Flex Query Library...', () => { //create a collection to test var n = [ { support:{ ajax:true, browser:'firefox', apiToken:'axcds' }, server:{ name:'wwwroot', type:'http' } }, { support:{ ajax:true, browser:'IE', apiToken:'bvdss' }, server:{ name:'ISS', type:'https' } } ]; //create instance var instance = new test({indentifier:[],number:1}); //define some function to testing function eval1(target,store,api){ if( api.equal('support.ajax',true) && api.equal('support.browser','firefox') ){ return true; }else if(api.index === 0){ error('Some Bad!!, should support.ajax is true and support.browser is firefox'); return false; } } function action1(target,store,api){ good('Yes!!, is working'); } function eval2(target,store,api){ if( api.equal('support.apiToken','bvdss') && api.equal('support.browser','IE') && api.equal('server.type','https') ){ return true; }else if(api.index === 1){ error('Some Bad!!, should support.ajax is true and support.browser is firefox'); return false; } } function eval3(target,store,api){ if( api.like('server.name',/^www/) ){ return true; } } describe('simple evaluate collections', function(){ instance.create('test1').when( eval1 ).action( action1 ); instance.create('test2').when( eval2 ).action( action1 ); instance.create('test3').when( eval2 ).action( action1 ); instance.start(n); }); });