1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2<html> 3 <head> 4 <title>Tests for the Selectbox widget</title> 5<!-- 6 $Id: ArrayTests.html 130 2006-11-30 20:44:53Z wingedfox $ 7 $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/trunk/tests/ArrayTests.html $ 8 9 Automated tests for the Selectbox widget 10 @author Ilya Lebedev <ilya@lebedev.net> 11--> 12 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 13 <title>BrowserExtensions/Array extensions tests</title> 14 <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css"> 15 <script language="JavaScript" type="text/javascript" src="jsUnitCore.js"></script> 16 <script language="JavaScript" type="text/javascript" src="../helpers.js"></script> 17 <script language="JavaScript" type="text/javascript" src="../arrayextensions.js"></script> 18 <script language="JavaScript" type="text/javascript" src="../objectextensions.js"></script> 19 <script language="JavaScript" type="text/javascript" src="../regexpextensions.js"></script> 20 <script language="JavaScript" type="text/javascript" src="../dom/selectbox.js"></script> 21 <script language="JavaScript" type="text/javascript"> 22 var sbx1, sbx2, 23 sel1, sel2; 24 function setUp() { 25 inform('setUp()'); 26 document.body.innerHTML = '<select id="testselect1" multiple="true">' 27 +' <option value="1-1">test1-1</option>' 28 +' <option value="1-2" selected="selected">test1-2</option>' 29 +' <option value="1-3">test1-3</option>' 30 +' <option value="1-4">test1-4</option>' 31 +' <option value="1-5" selected="selected">test1-5</option>' 32 +'</select>' 33 +'<select id="testselect2" multiple="true">' 34 +' <option value="2-1">test2-1</option>' 35 +' <option value="2-2">test2-2</option>' 36 +' <option value="2-3">test2-3</option>' 37 +' <option value="2-4">test2-4</option>' 38 +' <option value="2-5" selected="selected">test2-5</option>' 39 +'</select>'; 40 sbx1 = new Selectbox('testselect1'); 41 sel1 = document.getElementById('testselect1'); 42 sbx2 = new Selectbox('testselect2'); 43 sel2 = document.getElementById('testselect2'); 44 setUpPageStatus = 'complete'; 45 } 46 47 function testSelectboxCreation() { 48 try { 49 assertNull("Selectbox should produce an exception, when called with non-existent ID", new Selectbox('notexists')); 50 } catch(err) {} 51 assertNotNull("Selectbox should be initialized", sbx1); 52 assertNotNull("Selectbox should be initialized", sbx2); 53 54 assertNotNull("Selectbox should not produce an exception, when called with empty ID", new Selectbox()); 55 var so = new Selectbox(); 56 assertNotNull("Selectbox should create empty selectbox, when no id is specified.",so.getEl()); 57 assertEvaluatesToTrue("Selectbox should set not empty id on the created box",so.getEl()); 58 } 59 function testGetters() { 60 assertEquals(".getId() method should return the correct ID", 'testselect1', sbx1.getId()); 61 assertEquals(".getEl() method should return a reference to the correct selectbox", 62 sel1, sbx1.getEl()); 63 assertEquals(".getSelectedIndex check", 1, sbx1.getSelectedIndex()); 64 assertEquals(".getSelectedIndex check", sel1.selectedIndex, sbx1.getSelectedIndex()); 65 assertEquals(".getSelectedIndex check", 4, sbx2.getSelectedIndex()); 66 var so = [['test2-5','2-5']]; 67 assertEquals(".getSelectedIndex check", sel2.selectedIndex, sbx2.getSelectedIndex()); 68 var so = [['test1-2','1-2'],['test1-5','1-5']]; 69 assertObjectEquals(".getSelectedOptions check", so, sbx1.getSelectedOptions()); 70 var so = ['test1-1','test1-2','test1-3','test1-4','test1-5']; 71 assertObjectEquals(".getOptionsNames check 1", so, sbx1.getOptionsNames()); 72 var so = []; 73 assertObjectEquals(".getOptionsNames check 2: partial value mask is not allowed", so, sbx1.getOptionsNames(['-2','-5'])); 74 assertObjectEquals(".getOptionsNames check 3: partial value mask is not allowed", so, sbx1.getOptionsNames('-5')); 75 assertObjectEquals(".getOptionsNames check 4: regexps are not supported", so, sbx1.getOptionsNames(/(-2|-5)/)); 76 var so = ['test1-2','test1-5']; 77 assertObjectEquals(".getOptionsNames check 5: matches only the whole option value", so, sbx1.getOptionsNames(['1-2','1-5'])); 78 } 79 function testSelectboxOptionAddition() { 80 sbx1.addOption('t1','t2'); 81 assertEquals("Option will be added immediately",6,sel1.options.length); 82 var so = ['test1-1','test1-2','test1-3','test1-4','test1-5','t1']; 83 assertObjectEquals("Options will not be sorted, if 'sort' options was not set to 'true' or .sort() called explicitly",so,sbx1.getOptionsNames()); 84 assertEquals("Added value == 't1' on the 5th position",'t2',sel1.options[5].value); 85 assertEquals("Added text == 't2' on the 5th position",'t1',sel1.options[5].text); 86 87 sbx1.addOption('t5','t6'); 88 sbx1.addOption('t3','t4',false,false,true); 89 var so = ['t1','t3','t5','test1-1','test1-2','test1-3','test1-4','test1-5']; 90 assertObjectEquals("All options will be added immediately and in the sorted order",8,sel1.options.length); 91 assertObjectEquals("All options will be added immediately and in the sorted order",so,sbx1.getOptionsNames()); 92 } 93 function testAddOption() { 94 assertTrue("Adding scalar values is fine, even if it is evaluates to false", sbx1.addOption(0,0)); 95 assertTrue("Adding scalar values is fine, even if it is evaluates to false", sbx1.addOption("","")); 96 assertTrue("Adding scalar values is fine, even if it is evaluates to false", sbx1.addOption("test",0)); 97 assertFalse("Adding non-scalar value is prohibited", sbx1.addOption([],{})); 98 assertFalse("Adding non-scalar value is prohibited", sbx1.addOption({},new RegExp())); 99 } 100 function testSelection () { 101 assertEquals("selectMatchingOptions should add new options to the selection and return the number of added options", 1, sbx1.selectMatchingOptions('test1-1','exact')); 102 assertEquals("selectMatchingOptions should not change selection on the matching option", 0, sbx1.selectMatchingOptions('test1-1','exact')); 103 } 104 </script> 105 </head> 106 <body> 107 <h1>Tests for the Array extensions</h1> 108 <p>This page contains tests for the Helpers functions. To see them, take a look at the source.</p> 109 </body> 110</html> 111