Login   Register  
Icontem

File: parmstest.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Randal Allen Anderson III  >  Javascript Params Array  >  parmstest.js  >  Download  
File: parmstest.js
Role: Unit test script
Content type: text/plain
Description: unit test for parms.js
Class: Javascript Params Array
Manipulate arrays of named parameters
Author: By
Last change:
Date: 2013-05-11 18:18
Size: 9,754 bytes
 

Contents

Class file image Download
/*
  Parms - Open Source JavaScript Custom Parameters

  parmstest.js
    Unit testing - shows how to create and manipulate parms

  Author: Randal Allen Anderson III
          rational_ape@hotmail.com
  Web: http://raa3enterprises.com/parms
  Copyright (c) 2013 RAA3 Enterprises, Inc.
  GNU General Public License - http://www.gnu.org/licenses/gpl.html
*/

//if this does not run, might need javascript turned on or a major failure occurred
//a red message will stay on the page explaining this
document.getElementById('scriptsuccessindicator').innerHTML = 'Javascript Failure!';

Parms = new jraJS.parms.Parms();

//test of Parms objects and functions
log.severe(Parms.getVersion());
log.debug('expected: 1 warning: Illegal parm type: x');
var newparm1 = new jraJS.parms.Parm(null,'test1','test1 description', 'x');
log.info(newparm1.toString());
var newparm2 = new jraJS.parms.Parm(null,'test2','test2 description', 's');
log.info(newparm2.toString());

//test of DParm objects and functions
log.debug('expected: 2 warnings: min > max; default > max');
var newDparm = new jraJS.parms.DParm(null,'Dtest','Ddescription',66,55,44,2);
log.debug('expected: default = 55');
log.debug(newDparm.toString());
log.debug('expected: 4 warnings: initial < min; default < min; max < min; value < min');
newDparm.reset();
newDparm.restoreDefault();
newDparm.setInitial(5);
newDparm.setDefault(6);
newDparm.setMin(3);
newDparm.setMax(2);
newDparm.setValue(1);
log.debug('expected: value = 44;');
log.debug(newDparm.toString());
log.debug('expected: no warnings; negatives but null minimum');
newDparm.setMin(null);
newDparm.setMax(200);
newDparm.setInitial(-56.2);
newDparm.setDefault(-67.3);
newDparm.setValue(-100.4);
log.debug(newDparm.toString());
log.debug('expected: no warnings; large values but no maximum; decimals truncated at 2');
newDparm.setMin(30);
newDparm.setMax(null);
newDparm.setInitial(122333444455555.666666);
newDparm.setDefault(777777788888888.7777);
newDparm.setValue(999999999.8888);
log.debug(newDparm.toString());
log.debug('expected: no warnings;');
newDparm.setMin(30);
newDparm.setMax(200);
newDparm.setInitial(56);
newDparm.setDefault(67);
newDparm.setValue(100);
log.debug(newDparm.toString());

log.debug('expected: no warnings;');
var newDparm2 = new jraJS.parms.DParm(null,'Dtest2','Ddescription2',0,null,null);
log.debug(newDparm2.toString());
log.debug('expected: no warnings;');
var newDparm3 = new jraJS.parms.DParm(null,'Dtest3','Ddescription3',0,0,0);
log.debug(newDparm3.toString());
log.debug('expected: no warnings; null defaults; null min and max');
var newDparm4 = new jraJS.parms.DParm(null,'Dtest4','Ddescription4');
log.debug(newDparm4.toString());
log.debug('expected: no warnings; null defaults; null min and max');
var newDparm5 = new jraJS.parms.DParm(null,'Dtest5','Ddescription5',undefined,undefined,undefined,undefined);
log.debug(newDparm5.toString());
log.debug('expected: no warnings;');
var newDparm6 = new jraJS.parms.DParm(null,'Dtest6','Ddescription6',0,null,5,null,1);
log.debug(newDparm6.toString());
log.debug('expected: 1 warning; default < minimum');
var newDparm7 = new jraJS.parms.DParm(null,'Dtest8','Ddescription8',0,5,null,null,3);
log.debug(newDparm7.toString());
log.debug('expected: no warnings; long decimals');
var newDparm8 = new jraJS.parms.DParm(null,'Dtest7','Ddescription7',1234.56789,-987.6543215,838383.919213929343,null,1);
log.debug(newDparm8.toString());

//test of Parms functions
log.debug('expected: parm Dtest3 found;');
var xx = Parms.findParm('Dtest3', 'd');
if(xx){
  log.debug(xx.toString());
} else {
  log.debug("'Dtest3', 'd' not found");
}
log.debug('expected: Dtest3 not found');
var yy = Parms.findParm('Dtest3', 'i');
if(yy){
  log.debug(yy.toString());
} else {
  log.debug("'Dtest3', 'i' not found");
}
log.debug('expected: Dtestz not found');
var zz = Parms.findParm('Dtestz', 'd');
if(zz){
  log.debug(zz.toString());
} else {
  log.debug("'Dtestz', 'd' not found");
}

log.severe('marker');

//test of IParm objects and functions
log.debug('expected: 1 warning; default < minimum; no decimal places');
var newIparm = new jraJS.parms.IParm(null,'Itest','Idescription',5,6,7);
log.debug(newIparm.toString());
log.debug("iparm.type = " + newIparm.parm.type);
log.debug('expected: Dparm unchanged');
log.debug(newDparm.toString());
//log.debug('expected: Dparm unchanged');
//log.debug(newDparm8.toString());

log.severe('marker');

//test of SParm objects and functions
log.debug('expected: no warnings;');
var newSparm = new jraJS.parms.SParm(null,'Stest','Sdescription','Sdefault',66);
log.debug(newSparm.toString());
log.debug('expected: 5 warnings; illegal 0; illegal 5300; value too long; initial too long; default too long');
newSparm.setMaxLength(0);
newSparm.setMaxLength(5300);
newSparm.setMaxLength(null);
newSparm.setMaxLength();
newSparm.setMaxLength(5);
newSparm.setValue('thisistoolong');
newSparm.setInitial('soisthis');
newSparm.setDefault('andthistoo');
log.debug(newSparm.toString());
log.debug('expected: no warnings;');
newSparm.setMaxLength(55);
newSparm.setValue('but this is just fine');
newSparm.setInitial('and this is fine also');
newSparm.setDefault('not to be left out');
log.debug(newSparm.toString());
log.debug('expected: no warnings; value = initial');
newSparm.reset();
log.debug(newSparm.toString());
log.debug('expected: no warnings; value = default');
newSparm.restoreDefault();
log.debug(newSparm.toString());

log.severe('marker');

//test of CParm objects and functions
log.debug('expected: no warnings;');
var newCparm = new jraJS.parms.CParm(null,'Ctest','Cdescription','Cdefault',66);
newCparm.setChoices([{'ord': 5, 'opt' : 'a'},{'ord': 25, 'opt' : 'b'},{'ord': 10, 'opt' : 'c'},{'opt' : 'd'}]);
log.debug(newCparm.toString());
log.debug('expected: 3 warnings; not set default; not set initial; not set value');
newCparm.setDefault('howdy');
newCparm.setInitial('doody');
newCparm.setValue('pardner');
log.debug('expected: no warnings;');
newCparm.setDefault('a');
newCparm.setInitial('b');
newCparm.setValue('c');
log.debug('expected: no warnings;');
var newCparm2 = new jraJS.parms.CParm(null,'Ctest2','Cdescription2','d',66,null,[{'ord': 5, 'opt' : 'a'},{'ord': 25, 'opt' : 'b'},{'ord': 10, 'opt' : 'c'},{'opt' : 'd'}]);
log.debug(newCparm2.toString());
log.debug('expected: no warnings; listing choices with space');
newCparm2.addChoice('e');
newCparm2.addChoice('f',1);
log.debug(newCparm2.listChoices());
log.debug('expected: no warnings; listing choices with comma');
log.debug(newCparm2.listChoices(','));

log.severe('marker');

//test of BParm objects and functions
log.debug('expected: 1 warning; not parse Bdefault; initial,value,default = false text');
var newBparm = new jraJS.parms.BParm(null,'Btest','Bdescription','Bdefault','si','non');
log.debug(newBparm.toString());
log.debug('expected: no warnings; now initial,value,default = true text');
newBparm.setValue(1);
newBparm.setInitial(true);
newBparm.setDefault('true');
log.debug(newBparm.toString());
log.debug('expected: no warnings; now initial,value,default = false text');
newBparm.setValue(0);
newBparm.setInitial(false);
newBparm.setDefault('false');
log.debug(newBparm.toString());
log.debug('expected: no warnings; now initial,value,default = true text');
newBparm.setValue('yes');
newBparm.setInitial('on');
newBparm.setDefault('T');
log.debug(newBparm.toString());
log.debug('expected: no warnings; now initial,value,default = false text');
newBparm.setValue('no');
newBparm.setInitial('off');
newBparm.setDefault('F');
log.debug(newBparm.toString());
log.debug('expected: no warnings; now initial,value,default = true text');
newBparm.setValue('Y');
newBparm.setInitial('SI');
newBparm.setDefault('si');
log.debug(newBparm.toString());
log.debug('expected: no warnings; now initial,value,default = false text');
newBparm.setValue('N');
newBparm.setInitial('NON');
newBparm.setDefault('non');
log.debug(newBparm.toString());

//test of Parms functions
log.debug('expected: no warnings; list of defined parms');
var parmslist = Parms.listParms();

//show some random info to the user
document.getElementById('parmslist').innerHTML = parmslist;
document.getElementById('newparm1').innerHTML = newparm1.toString();
document.getElementById('newparm2').innerHTML = newparm2.toString();

ParmsTable = new jraJS.parms.ParmsTable();

//show table with first set of columns
var table1 = { "tableID" : "showParmsTable", "showvalues" : "", "columns" : [
	{ "type" : "Parm Type" }, { "name" : "Parm Name" }, { "descrip" : "Parm Description" },
	{ "tablemin" : "Min Value" }, { "tablemax" : "Max Value" }
]};
ParmsTable.showTable(table1,parmslist);

//show table with different set of columns
var table2 = { "tableID" : "showParmsTable2", "showvalues" : "inputs", "columns" : [
	{ "name" : "Parm Name" }, { "value" : "Current Value" }
]};
ParmsTable.showTable(table2,parmslist);

//show examples of parms as input fields (just happen to be in a table)
ParmsTable.showParmInput ( "inputexample1", newDparm );
ParmsTable.showParmInput ( "inputexample2", newIparm );
ParmsTable.showParmInput ( "inputexample3", newSparm );
ParmsTable.showParmInput ( "inputexample4", newCparm );
ParmsTable.showParmInput ( "inputexample5", newBparm );

//show examples of parms as input fields not in a table
ParmsTable.showParmInput ( "inputexamplex", newDparm7 );

//if this does not run then a red failure message will stay displayed on the page
document.getElementById('scriptsuccessindicator').style.display = 'none';