142
St
startsInvasion / files
startsInvasion / libs / node_modules / bean / support / syn / test / qunit / syn_test.js
3.0 KB
1module("funcunit/syn") 2 3st = { 4 g: function( id ) { 5 return document.getElementById(id) 6 }, 7 log: function( c ) { 8 if(st.g("mlog")) 9 st.g("mlog").innerHTML = st.g("mlog").innerHTML+c+"<br/>" 10 }, 11 binder: function( id, ev, f ) { 12 st.bind(st.g(id), ev, f) 13 }, 14 unbinder: function( id, ev, f ) { 15 st.unbind(st.g(id), ev, f) 16 }, 17 bind : function(el, ev, f){ 18 return el.addEventListener ? 19 el.addEventListener(ev, f, false) : 20 el.attachEvent("on"+ev, f) 21 }, 22 unbind : function(el, ev, f){ 23 return el.addEventListener ? 24 el.removeEventListener(ev, f, false) : 25 el.detachEvent("on"+ev, f) 26 }, 27 rootJoin : (typeof steal == "undefined" ? function(path){ 28 return "../../"+path; 29 } : 30 function(path){ return steal.root.join(path) } ) 31}; 32 33 34setTimeout(function(){ 35 if(Syn.support.ready ==2){ 36 for(var name in Syn.support){ 37 st.log(name+": "+Syn.support[name]) 38 } 39 }else{ 40 setTimeout(arguments.callee, 1); 41 } 42 43},1); 44 45test("Selecting a select element", function(){ 46 st.g("qunit-test-area").innerHTML = 47 "<form id='outer'><select name='select'><option value='1' id='one'>one</option><option value='2' id='two'>two</option></select></form>"; 48 49 var change = 0, changef = function(){ 50 change++; 51 } 52 53 st.g("outer").select.selectedIndex = 0; 54 55 st.bind(st.g("outer").select,"change",changef ); 56 57 stop() 58 Syn.click( st.g("two"), function(){ 59 equals(change, 1 , "change called once") 60 equals(st.g("outer").select.selectedIndex, 1, "Change Selected Index"); 61 //st.g("qunit-test-area").innerHTML = "" 62 start(); 63 }) 64 65 66 67 68}) 69 70asyncTest("scrollTop triggers scroll events", function(){ 71 st.g("qunit-test-area").innerHTML = "<div id='scroller' style='height:100px;width: 100px;overflow:auto'>"+ 72 "<div style='height: 200px; width: 100%'>text"+ 73 "</div>"+ 74 "</div>"; 75 76 st.binder("scroller","scroll",function(ev){ 77 ok(true,"scrolling created just by changing ScrollTop"); 78 st.g("qunit-test-area").innerHTML =""; 79 start(); 80 } ); 81 stop(); 82 setTimeout(function(){ 83 var sc = st.g("scroller"); 84 sc && (sc.scrollTop = 10); 85 86 },13) 87 88}) 89 90test("focus triggers focus events", function(){ 91 st.g("qunit-test-area").innerHTML = "<input type='text' id='focusme'/>"; 92 93 st.binder("focusme","focus",function(ev){ 94 ok(true,"focus creates event"); 95 st.g("qunit-test-area").innerHTML =""; 96 start(); 97 } ); 98 stop(); 99 setTimeout(function(){ 100 st.g("focusme").focus(); 101 102 },10) 103 104}); 105 106 107test("focus on an element then another in another page", function(){ 108 stop(10000); 109 var rootJoin = st.rootJoin; 110 111 var page1 = rootJoin("funcunit/syn/test/qunit/page1.html"), 112 page2 = rootJoin("funcunit/syn/test/qunit/page2.html"), 113 iframe = document.createElement('iframe'), 114 calls = 0; 115 116 st.bind(iframe,"load",function(){ 117 if(calls == 0){ 118 119 Syn.click( iframe.contentWindow.document.getElementById("first") ,{}, function(){ 120 121 iframe.contentWindow.location = page2; 122 }) 123 calls++; 124 }else{ 125 126 Syn.click( iframe.contentWindow.document.documentElement ,{}, function(){ 127 start(); 128 129 }) 130 } 131 132 133 }); 134 iframe.src = page1 135 136 137 138 st.g("qunit-test-area").appendChild(iframe); 139})