Skip to content

Commit 221cc51

Browse files
committed
util test code 작성중
1 parent eccda4c commit 221cc51

File tree

1 file changed

+203
-32
lines changed

1 file changed

+203
-32
lines changed

api-test.html

+203-32
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,83 @@
2222
border-radius: 4px;
2323
background: #f06433;
2424
}
25+
hr.split{
26+
border-style: dashed;
27+
border-width: 1px;
28+
}
29+
2530
</style>
2631

2732
</head>
28-
<body>
29-
<div id="progress" class="progress"><div id="progress-bar" class="progress-bar"></div></div>
33+
<body custom-attr="ca">
34+
<div id="progress" class="progress"><div id="progress-bar" class="progress-bar" ondblclick="alert('dbClick')"></div></div>
3035
<h1>AX5 API Check</h1>
3136
<div id="test-result" class="test-result"></div>
32-
<p>[email protected] - 2014-12-11</p>
37+
<p id="author" ondblclick="alert('author_dbClick')">[email protected] - 2014-12-11</p>
3338

3439
<div id="id-test"></div>
3540
<a class="class-text"></a>
3641

37-
<span data-attr="A"></span>
42+
<span data-attr="A" id="test"></span>
3843
<div data-attr="B"></div>
3944

4045
<script type="text/javascript">
4146
/*
4247
http://ax5.io/jsdoc/document/index.html 에 좌측메뉴 순서대로 테스트 코드를 작성을 기준으로 하지만 짝이 있는 함수일 경우 같이 작성 합니다.
4348
*/
49+
var eventChecker = '';
50+
var eventCheckerFn = function(){
51+
eventChecker = "click_event_on";
52+
};
53+
4454
var check_list = [
55+
//ax5.util----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4556
{
4657
label:"ax5.util.alert",
4758
fn: function(){
4859
return (function A(){ return typeof ax5.util.alert; })();
4960
}
5061
},
62+
{
63+
label:"ax5.util.attr",
64+
fn: function(){
65+
ax5.util.attr(ax5.util.get_elements("[data-attr=A]"), "set", {"data-ax-spt":"ABCD"});
66+
ax5.util.attr(ax5.util.get_elements("[data-attr=A]"), "set", {"customn-attr-1":"ca1", "customn-attr-2":"ca2"});
67+
var getAttr = ax5.util.attr(ax5.util.get_elements("[data-attr=A]"), "data-ax-spt");
68+
var getAttr2 = ax5.util.attr(ax5.util.get_elements("[data-attr=A]"), "customn-attr-2");
69+
ax5.util.attr(ax5.util.get_elements("[data-attr=A]"), "remove", "customn-attr-1" );
70+
var getAttr3 = ax5.util.attr(ax5.util.get_elements("[data-attr=A]"), "customn-attr-1");
71+
72+
return ( getAttr + " " + getAttr2 + " " + getAttr3 );
73+
},
74+
r:"ABCD ca2 null"
75+
},
76+
{
77+
label:"ax5.util.clazz",
78+
fn: function(){
79+
var hasResult1 = ax5.util.clazz(ax5.util.get_elements("#test-result"), "test-result");
80+
var hasResult_false = ax5.util.clazz(ax5.util.get_elements("#test-result"), "no-exist");
81+
var addResult = ax5.util.clazz(ax5.util.get_elements("#test-result"), "add", "add-class-name");
82+
var hasResult2 = ax5.util.clazz(ax5.util.get_elements("#test-result"), "add-class-name");
83+
var removeResult = ax5.util.clazz(ax5.util.get_elements("#test-result"), "remove", "add-class-name");
84+
var hasResult3 = ax5.util.clazz(ax5.util.get_elements("#test-result"), "add-class-name");
85+
var toggleResult = ax5.util.clazz(ax5.util.get_elements("#test-result"), "toggle", "add-class-name");
86+
var hasResult4 = ax5.util.clazz(ax5.util.get_elements("#test-result"), "add-class-name");
87+
var toggleResult = ax5.util.clazz(ax5.util.get_elements("#test-result"), "toggle", "add-class-name");
88+
var hasResult5 = ax5.util.clazz(ax5.util.get_elements("#test-result"), "add-class-name");
89+
90+
var po = [];
91+
po.push(hasResult1);
92+
po.push(hasResult_false);
93+
po.push(hasResult2);
94+
po.push(hasResult3);
95+
po.push(hasResult4);
96+
po.push(hasResult5);
97+
98+
return po.join(' ');
99+
},
100+
r: "true false true false true false"
101+
},
51102
{
52103
label:"ax5.util.clone(object)",
53104
fn: function(){
@@ -68,6 +119,18 @@ <h1>AX5 API Check</h1>
68119
},
69120
r: "string A"
70121
},
122+
{
123+
label:"ax5.util.create_elements",
124+
fn: function(){
125+
var ele = ax5.util.create_elements("div", {id:"createEleId", class:"createEleClass"});
126+
var target = document.getElementById("test-result");
127+
target.appendChild(ele);
128+
129+
//return ax5.util.is_element(document.getElementById("test-result"));
130+
return ax5.util.is_element(document.getElementById("createEleId"));
131+
},
132+
r: true
133+
},
71134
{
72135
label:"ax5.util.each",
73136
fn: function(){
@@ -96,6 +159,29 @@ <h1>AX5 API Check</h1>
96159
return (function A(){ return typeof ax5.util.error; })();
97160
}
98161
},
162+
{
163+
label:"ax5.util.event_on",
164+
fn: function(){
165+
var mydom = ax5.util.get_elements("#author");
166+
ax5.util.event_on(mydom, "click", eventCheckerFn);
167+
168+
mydom[0].click();
169+
return eventChecker;
170+
},
171+
r: "click_event_on"
172+
},
173+
{
174+
label:"ax5.util.event_off",
175+
fn: function(){
176+
var mydom = ax5.util.get_elements("#author");
177+
ax5.util.event_off(mydom, "click", eventCheckerFn);
178+
179+
eventChecker = "off";
180+
mydom[0].click();
181+
return eventChecker;
182+
},
183+
r: "off"
184+
},
99185

100186
{
101187
label:"ax5.util.extend : add key",
@@ -176,8 +262,8 @@ <h1>AX5 API Check</h1>
176262
{
177263
label:"ax5.util.first(object)",
178264
fn: function(){
179-
var aarray = {a:11, b:22, c:33, d:44};
180-
var result = ax5.util.first(aarray);
265+
var obj = {a:11, b:22, c:33, d:44};
266+
var result = ax5.util.first(obj);
181267

182268
return result[Object.keys(result)[0]];
183269
},
@@ -194,8 +280,8 @@ <h1>AX5 API Check</h1>
194280
{
195281
label:"ax5.util.last(object)",
196282
fn: function(){
197-
var aarray = {a:11, b:22, c:33, d:44}
198-
var result = ax5.util.last(aarray);
283+
var obj = {a:11, b:22, c:33, d:44}
284+
var result = ax5.util.last(obj);
199285

200286
return result[Object.keys(result)[0]];
201287
},
@@ -257,14 +343,38 @@ <h1>AX5 API Check</h1>
257343
return ax5.util.get_elements("div.progress #progress-bar");
258344
}
259345
},
260-
261346
{
262-
label:"ax5.util.get_elements(selecter, parent_element)",
347+
label:"ax5.util.get_elements(selecter, parent_element_selecter)",
263348
fn: function(){
264-
return ax5.util.get_elements("div:first-child", document.querySelector('#test-result') );
349+
return ax5.util.get_elements('div#test-result div' );
265350
}
266351
},
352+
{
353+
label:"ax5.util.get_elements(selecter, parent_element_selecter)",
354+
fn: function(){
355+
return ax5.util.get_element('div#test-result div' );
356+
}
357+
},
358+
{
359+
label:"ax5.util.get_element_right",
360+
fn: function(){
361+
var tg = ax5.util.get_element("#progress-bar");
362+
var cond = {
363+
tagname: "div",
364+
clazz:"progress"
267365

366+
//,"custom-attr":"ca"
367+
};
368+
/*
369+
var cond = {
370+
tagname: "body"
371+
//,"custom-attr":"ca"
372+
};
373+
*/
374+
375+
return ax5.util.get_element_right(tg, cond);
376+
}
377+
},
268378
{
269379
label:"ax5.util.get_type",
270380
fn: function(){
@@ -298,6 +408,12 @@ <h1>AX5 API Check</h1>
298408
return ax5.util.is_function(a);
299409
}
300410
},
411+
{
412+
label:"ax5.util.is_nodelist",
413+
fn: function(){
414+
return ax5.util.is_nodelist(document.querySelectorAll('div'));
415+
}
416+
},
301417
{
302418
label:"ax5.util.is_nothing",
303419
fn: function(){
@@ -398,6 +514,28 @@ <h1>AX5 API Check</h1>
398514
},
399515
r : "ready-response"
400516
},
517+
{
518+
label: "ax5.util.require(not found), fail is OK",
519+
fn : function (callBack) {
520+
ax5.util.require(["src/ax5_class_sample_not_found.js"], function(){
521+
callBack(true);
522+
}, function(){
523+
callBack(false);
524+
});
525+
},
526+
r : "ready-response"
527+
},
528+
{
529+
label: "ax5.util.require(large file)",
530+
fn : function (callBack) {
531+
ax5.util.require(["src/ax5_large_class_sample.js?v="+parseInt(Math.random()*100) ], function(){
532+
callBack(true);
533+
}, function(){
534+
callBack(false);
535+
});
536+
},
537+
r : "ready-response"
538+
},
401539
{
402540
label: "ax5.util.search",
403541
fn : function () {
@@ -453,16 +591,20 @@ <h1>AX5 API Check</h1>
453591
},
454592
r : "/api-test.html"
455593
},
594+
//ax5.dom----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
595+
{
596+
label: "split"
597+
},
456598
{
457599
label: "ax5.dom('#id')",
458600
fn : function () {
459-
return ax5.util.is_element(ax5.dom("#id-test").elements[0])
601+
return ax5.util.is_element(ax5.dom("#id-test").elements[0]);
460602
}
461603
},
462604
{
463605
label: "ax5.dom('.class')",
464606
fn : function () {
465-
return ax5.util.is_element(ax5.dom(".class-text").elements[0])
607+
return ax5.util.is_element(ax5.dom(".class-text").elements[0]);
466608
}
467609
},
468610
{
@@ -474,7 +616,7 @@ <h1>AX5 API Check</h1>
474616
{
475617
label: "ax5.dom('[attr=value]')",
476618
fn : function () {
477-
return ax5.util.is_element(ax5.dom("[data-attr=A]").elements[0])
619+
return ax5.util.is_element(ax5.dom("[data-attr=A]").elements[0]);
478620
}
479621
},
480622
{
@@ -550,35 +692,64 @@ <h1>AX5 API Check</h1>
550692
var result, err_string;
551693

552694
if(O.r === "ready-response"){
695+
var skipFlag = false;
696+
697+
/*
698+
var skipFn = setTimeout(function () {
699+
//var req = new XMLHttpRequest();
700+
//req.abort();
701+
console.log("settimeout");
702+
skipFlag = true;
703+
704+
newDiv.innerHTML = "<h3 class='red'>" + O.label + " : <u>skip</u></h3>";
705+
target.appendChild(newDiv);
706+
checker(check_list.shift());
707+
}, 1000);
708+
*/
709+
553710
O.fn(function(res){
554-
if(res){
555-
newDiv.innerHTML = "<h3 class='blue'>" + O.label + " : <u>OK</u></h3>";
556-
target.appendChild(newDiv);
557-
setTimeout(function () {
558-
checker(check_list.shift());
559-
}, 100);
711+
if (!skipFlag) {
712+
//if(skipFn) clearTimeout(skipFn);
713+
if (res) {
714+
newDiv.innerHTML = "<h3 class='blue'>" + O.label + " : <u>OK</u></h3>";
715+
target.appendChild(newDiv);
716+
setTimeout(function () {
717+
checker(check_list.shift());
718+
}, 100);
719+
} else {
720+
newDiv.innerHTML = "<h3 class='red'>" + O.label + " : <u>fail</u></h3>";
721+
target.appendChild(newDiv);
722+
setTimeout(function () {
723+
checker(check_list.shift());
724+
}, 100);
725+
}
560726
}
561727
});
562728
}else{
563-
try{
564-
result = O.fn();
565-
}catch(e){
566-
err_string = e.toString();
567-
console.error(e);
568-
}
729+
if(O.label === "split") {
730+
newDiv.innerHTML = "<hr class='split' />";
731+
}else{
732+
try{
733+
result = O.fn();
734+
}catch(e){
735+
err_string = e.toString();
736+
console.error(e);
737+
}
569738

570-
if (typeof O.r != "undefined" && (result == O.r)) {
571-
newDiv.innerHTML = "<h3 class='blue'>" + O.label + " : <u>OK</u></h3>";
572-
} else if (typeof O.r == "undefined" && result) {
573-
newDiv.innerHTML = "<h3 class='blue'>" + O.label + " : <u>OK : "+ result +"</u></h3>";
574-
} else {
575-
newDiv.innerHTML = "<h3 class='red'>" + O.label + " : <u>?? " + result + "["+ err_string +"]" + "</u></h3>";
739+
if (typeof O.r != "undefined" && (result == O.r)) {
740+
newDiv.innerHTML = "<h3 class='blue'>" + O.label + " : <u>OK</u></h3>";
741+
} else if (typeof O.r == "undefined" && result) {
742+
newDiv.innerHTML = "<h3 class='blue'>" + O.label + " : <u>OK : "+ result +"</u></h3>";
743+
} else {
744+
newDiv.innerHTML = "<h3 class='red'>" + O.label + " : <u>?? " + result + "["+ err_string +"]" + "</u></h3>";
745+
}
576746
}
577747

578748
target.appendChild(newDiv);
579749
setTimeout(function () {
580750
checker(check_list.shift());
581751
}, 10);
752+
582753
}
583754
}
584755
checker(check_list.shift());

0 commit comments

Comments
 (0)