Best JavaScript code snippet using appium-xcuitest-driver
h5.core.view_binding.js
Source:h5.core.view_binding.js
...122 * @param {Array} expectAry çµæäºæ³é
å123 * @param {String} message ãã¹ãã¡ãã»ã¼ã¸124 * @param {String} [selector='li'] ãã§ãã¯ããè¦ç´ ã®ã»ã¬ã¯ã¿ãããã©ã«ãã¯liã125 */126 function checkTexts(expectAry, message, selector) {127 var sel = selector ? selector : 'li';128 var textList = [];129 // è¦ç´ ãåå¾ããã¨ãã«è¨è¿°ããã¦ããé çªéãã«ãªãããã«åå¾ãã130 function makeTextList(root) {131 var node = root.firstChild;132 while (node) {133 //1 === NodeType.ELEMENT_NODE134 if (node.nodeType === 1) {135 if ($(node).is(sel)) {136 textList.push($(node).text());137 } else {138 makeTextList(node);139 }140 }141 node = node.nextSibling;142 }143 }144 makeTextList($('#dataBindTest')[0]);145 deepEqual(textList, expectAry, message);146 }147148 // =========================================================================149 //150 // Test Module151 //152 // =========================================================================153154 //=============================155 // Definition156 //=============================157158 module('ãã¤ã³ã');159160 //=============================161 // Body162 //=============================163 test('data-h5-bindå±æ§ã«æå®ããååã®ããããã£ããã¤ã³ãã§ãããã¨', function() {164 view.append($fixture, 'bindTest1');165 view.bind($('#dataBindTest', $fixture), {166 test: 'abc',167 test2: 'abcd'168 });169 strictEqual($('#dataBindTest>span').text(), 'abc', 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨');170 strictEqual($('#dataBindTest>p').text(), 'abcd', 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨');171 strictEqual($('#dataBindTest>div>pre').text(), 'abcd', 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨');172 });173174 test('data-h5-bindå±æ§ã®æå®ãã¦ããè¦ç´ èªä½ã«ãã¤ã³ãã§ãããã¨', 1, function() {175 view.append($fixture, 'bindSpan');176 view.bind($fixture.find('span'), {177 test: 'test'178 });179 strictEqual($fixture.find('span').text(), 'test', 'data-h5-bindå±æ§ãæå®ãã¦ããè¦ç´ èªä½ã«ãã¤ã³ãããã¦ãããã¨');180 });181182 test('ã³ã³ããã¹ãã«å®ç¾©ããã¦ããããããã£åãæã¤ãã¼ã¿ããã¤ã³ããã', function() {183 view.append($fixture, 'simple');184 view.bind($('#dataBindTest'), {185 test: 'abc'186 });187 strictEqual($('#dataBindTest>span').text(), 'abc', 'data-h5-bindæå®ããè¦ç´ ã®å¤ãæ¸ãå¤ãããã¨');188 });189190 test('ã³ã³ããã¹ãã«å®ç¾©ããã¦ããªãããããã£åãæã¤ãã¼ã¿ããã¤ã³ããã', function() {191 view.append($fixture, 'simple');192193 view.bind($('#dataBindTest'), {194 test2: 'abcd'195 });196197 strictEqual($('#dataBindTest>span').text(), '', 'ãã¼ã¿ã空ã®ç¶æ
ã§ãã¤ã³ãããããã¨(nullã®ã¨ãã¨åã)');198 });199200 // TODO Arrayåã¨Objectåã®ãã¤ã³ãã«å¯¾ãããã¹ãã¯å¾ã§è¿½å ãã201 test('null, undefined, String, Numberãããããã表示ããããã¨', function() {202 var func = function() {203 return;204 };205206 view.append($fixture, 'variableType');207 view.bind('#dataBindTest', {208 dataNull: null,209 dataUndef: undefined,210 dataStr: 'abc',211 dataNum: -1234.567,212 dataNaN: NaN,213 dataInf: Infinity,214 dataMInf: -Infinity,215 dataFunc: func216 });217 var exp = ['', '', 'abc', '-1234.567', 'NaN', 'Infinity', '-Infinity', ''];218 checkTexts(exp, 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨', 'span');219 });220221 test('HTMLæååãå«ããããªæååãããã¹ããã¼ãã«ãã¤ã³ãã§ãããã¨', 2, function() {222 view.append($fixture, 'simple');223224 var str = '<a href="aa"></a><!--aa-->';225 view.bind($fixture.find('span'), {226 test: str227 });228 strictEqual($fixture.find('span').text(), str, 'ãã¤ã³ãããå¤ã表示ããã¦ãããã¨');229 strictEqual($fixture.find('a').length, 0, 'ãã¤ã³ãããæååã«HTMLã¿ã°ãå«ã¾ãã¦ãã¦ããããã¹ããã¼ãæ±ãã«ãªã£ã¦ãããã¨');230 });231232 test('è¤æ°è¦ç´ ã«ãã¤ã³ãã§ãããã¨', 2, function() {233 view.append($fixture, 'bindSpan');234 view.append($fixture, 'bindSpan');235 try {236 view.bind($fixture.find('span'), {237 test: 'test'238 });239240 equal($('#qunit-fixture>span:first').text(), 'test');241 equal($('#qunit-fixture>span:last').text(), 'test');242 } catch (e) {243 ok(false, 'ã¨ã©ã¼ãçºçãããããã¹ã失æã');244 }245 });246247 test('ãã¤ã³ãããè¦ç´ ãåå¨ããªãå ´åã¯ãã¨ã©ã¼ã«ãªããã¨', 3, function() {248 var args = [$fixture.find('#noExist'), '#noExist', $([])];249 for (var i = 0, l = args.length; i < l; i++) {250 try {251 view.bind(args[i], {252 test: 'test'253 });254 ok(false, 'ãã¹ã失æãã¨ã©ã¼ãçºçãã¦ãã¾ããã');255 } catch (e) {256 strictEqual(e.code, ERR_VIEW.ERR_CODE_BIND_INVALID_TARGET, e.message);257 }258 }259 });260261 test('ãã¤ã³ãããè¦ç´ ã®æå®æ¹æ³ã¯jQueryãªãã¸ã§ã¯ããDOMãã»ã¬ã¯ã¿ã®ããããã§ãããã¨', function() {262 view.append($fixture, 'bindSpan');263 var strs = ['jQueryãªãã¸ã§ã¯ã', 'DOM', 'ã»ã¬ã¯ã¿'];264 var arg = null;265266 for (var i = 0, l = strs.length; i < l; i++) {267 switch (i) {268 case 0:269 arg = $fixture.find('span');270 break;271 case 1:272 arg = $fixture.find('span')[0];273 break;274 case 2:275 arg = '#qunit-fixture>span';276 break;277 }278 var binding = view.bind(arg, {279 test: i280 });281 equal($fixture.find('span').text(), i, strs[i] + 'ãå¼æ°ã«æå®ã§ãããã¨');282283 binding.unbind();284 }285 });286287 test('ãã¤ã³ãããè¦ç´ ã®æå®ã«ä¸æ£ãªå¤ã渡ãã¨ã¨ã©ã¼ã«ãªããã¨', function() {288 view.append($fixture, 'bindSpan');289 var invalids = [$(), null, undefined];290 for (var i = 0, l = invalids.length; i < l; i++) {291 try {292 view.bind(invalids[i], {293 test: i294 });295 ok(false, 'ãã¹ã失æãã¨ã©ã¼ãçºçãã¦ãã¾ããã' + invalids[i]);296 } catch (e) {297 strictEqual(e.code, ERR_VIEW.ERR_CODE_BIND_INVALID_TARGET, e.message);298 }299 }300 });301302 test('ãã¤ã³ãæå®ãããã®ããªãã¸ã§ã¯ãã§ãªãå ´åã¯ã¨ã©ã¼ã«ãªããã¨', function() {303 view.append($fixture, 'bindSpan');304 /** @type Any */305 var args = [null, undefined, [{}], 1, 'abc', true];306 for (var i = 0, l = args.length; i < l; i++) {307 try {308 view.bind($fixture.find('span'), args[i]);309 ok(false, 'ãã¹ã失æãã¨ã©ã¼ãçºçãã¦ãã¾ããã' + args[i]);310 } catch (e) {311 strictEqual(e.code, ERR_VIEW.ERR_CODE_BIND_CONTEXT_INVALID, e.message);312 }313 }314 });315 //=============================316 // Definition317 //=============================318 module('ãªãã¸ã§ã¯ãã®ãã¤ã³ã');319320 //=============================321 // Body322 //=============================323 test('ãã¤ã³ããããªãã¸ã§ã¯ãã®å
¥ãåé¢ä¿ã表ãããã¨', function() {324 view.append($fixture, 'objectNest');325 view.bind('#dataBindTest', {326 test: 'TEST',327 obj: {328 test: 'OBJ.TEST',329 test2: 'OBJ.TEST2',330 obj: {331 test: 'OBJ.OBJ.TEST'332 }333 }334 });335336 var result = ['TEST', '', 'OBJ.TEST', 'OBJ.TEST2', 'OBJ.OBJ.TEST', ''];337 $('#dataBindTest span').each(function(i) {338 strictEqual($(this).text(), result[i], 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨ã' + result[i]);339 });340 });341342 test('ããã¹ãã»HTMLã»å±æ§ã»ã¹ã¿ã¤ã«ã»ã¯ã©ã¹ã«nullããã¤ã³ããã', function() {343 view.append($fixture, 'object1');344 view.bind('#dataBindTest', {345 obj: null346 });347348 var $span = $fixture.find('#dataBindTest span');349 strictEqual($span.text(), '', 'text:空æåãè¨å®ããã¦ãããã¨');350 strictEqual($span.attr('id'), undefined, 'attr:åé¤ããã¦ãããã¨');351 strictEqual($span[0].style.color, '', 'style:ä½ãè¨å®ããã¦ããªããã¨');352 strictEqual($span[0].className, '', 'class:ä½ãè¨å®ããã¦ããªããã¨');353 });354355 test('å¤ãæ¢ã«è¨å®ããã¦ããããã¹ãã»HTMLã»å±æ§ã»ã¹ã¿ã¤ã«ã»ã¯ã©ã¹ã«nullããã¤ã³ããã', function() {356 view.append($fixture, 'object2');357 view.bind('#dataBindTest', {358 obj: null359 });360361 var $span = $fixture.find('#dataBindTest span');362 strictEqual($span.text(), '', 'text:空æåãè¨å®ããã¦ãããã¨');363 strictEqual($span.attr('id'), undefined, 'attr:åé¤ããã¦ãããã¨');364 strictEqual($span[0].style.color, '', 'style:ä½ãè¨å®ããã¦ããªããã¨');365 strictEqual($span.attr('class'), 'hoge', 'ãã¤ã³ãéå§åã«è¨å®ããã¦ããå¤ã«æ»ããã¨');366 });367368 test('ä¸ã¤ã®è¦ç´ ã«textã¨htmlã®ããããã£ããã¤ã³ããã', function() {369 view.append($fixture, 'object3');370 view.bind('#dataBindTest', {371 v1: 'v1',372 v2: 'v2'373 });374 var $span = $fixture.find('span');375 strictEqual($span.html(), 'v2', 'è¤æ°ã®ããããã£ãhtml,textã§æå®ããå ´åãä¸çªæå¾ã«æå®ãããã®ããã¤ã³ãããããã¨');376 });377378 test('ã¯ã©ã¹ã«æ¢ã«è¨å®ããã¦ããå¤ã¨åãå¤ããã¤ã³ããã', function() {379 view.append($fixture, 'object4');380 view.bind('#dataBindTest', {381 v1: 'c2'382 });383 var $span = $fixture.find('span');384 strictEqual($span[0].className, 'c1 c2 c3', 'åãã¯ã©ã¹ãéè¤ãã¦è¨å®ãããªããã¨');385 });386387 //=============================388 // Definition389 //=============================390 module('é
åã®ãã¤ã³ã');391392 //=============================393 // Body394 //=============================395396 test('é
åããã¤ã³ãã§ãããã¨', 1, function() {397 var items = [{398 test: 'a'399 }, {400 test: 'b'401 }];402 view.append($fixture, 'loopContext1');403 view.bind($('#dataBindTest'), {404 test: 'aaa',405 items: items406 });407408 var result = ['a', 'b'];409 checkTexts(result, 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨');410 });411412 test('空é
åããã¤ã³ãã§ãããã¨', 1, function() {413 view.append($fixture, 'loopContext1');414 view.bind($('#dataBindTest'), {415 items: []416 });417418 strictEqual($('#dataBindTest li').length, 0, 'ç¹°ãè¿ãããè¦ç´ ãä¸ã¤ããªããã¨');419 });420421 test('data-h5-loop-contextã«é
åãObservableArray以å¤ã®ãã®ããã¤ã³ãããå ´åã¯ã¨ã©ã¼ã«ãªããã¨', function() {422 var noArys = [{}, $(), function() {/* no code */}];423 var l = noArys.length;424 for (var i = 0; i < l; i++) {425 view.append($fixture, 'loopContext1');426 try {427 view.bind($('#dataBindTest'), {428 test: 'aaa',429 items: noArys[i]430 });431 ok(false, 'ãã¹ã失æãã¨ã©ã¼ãçºçãã¦ã¾ãã' + noArys[i]);432 } catch (e) {433 strictEqual(e.code, ERR_VIEW.ERR_CODE_INVALID_CONTEXT_SRC, e.message);434 }435 $fixture.find('div').remove();436 }437438 try {439 view.bind($('#dataBindTest'), {440 test: 'aaa'441 });442 ok(false, 'ãã¹ã失æãæå®ç¡ãã§ã¨ã©ã¼ãçºçãã¦ã¾ãã');443 } catch (e) {444 strictEqual(e.code, ERR_VIEW.ERR_CODE_BIND_INVALID_TARGET, e.message);445 }446447 expect(l + 1);448 });449450 test('é
åã®è¦ç´ ã®ãªãã¸ã§ã¯ããããã«é
åãæã¤å ´åãã¤ã³ãã§ãããã¨', function() {451 var ary = [{452 test: 'A',453 ary: [{454 test: 'A-A'455 }]456 }, {457 test: 'B',458 ary: [{459 test: 'B-A'460 }, {461 test: 'B-B'462 }]463 }];464465 view.append($fixture, 'loopContext2');466 view.bind($('#dataBindTest'), {467 items: ary468 });469470 strictEqual($('#dataBindTest>ul>li:eq(0)').text(), 'A', 'ãã¤ã³ãããã¦ãããã¨');471 strictEqual($('#dataBindTest>ul>li:eq(1)>ul:first>li:eq(0)').text(), 'A-A', 'ãã¤ã³ãããã¦ãããã¨');472 strictEqual($('#dataBindTest>ul>li:eq(1)>ul:first>li').length, 1,473 'loop-contextã«æå®ããé
åã®ãµã¤ãºã¨åæ°ãDOMãçæããã¦ãããã¨');474 strictEqual($('#dataBindTest>ul>li:eq(2)').text(), 'B', 'ãã¤ã³ãããã¦ãããã¨');475 strictEqual($('#dataBindTest>ul>li:eq(3)>ul:first>li:eq(0)').text(), 'B-A', 'ãã¤ã³ãããã¦ãããã¨');476 strictEqual($('#dataBindTest>ul>li:eq(3)>ul:first>li:eq(1)').text(), 'B-B', 'ãã¤ã³ãããã¦ãããã¨');477 strictEqual($('#dataBindTest>ul>li:eq(3)>ul:first>li').length, 2,478 'loop-contextã«æå®ããé
åã®ãµã¤ãºã¨åæ°ãDOMãçæããã¦ãããã¨');479 });480481 test('循ç°åç
§ãæã¤é
åããã¤ã³ãã§ãããã¨', function() {482 var ary = [{483 test: 'A',484 ary: [{485 test: 'A'486 }]487488 }, {489 test: 'B',490 ary: [{491 test: 'B-A'492 }, {493 test: 'B-B'494 }]495 }];496 ary[0].ary = ary;497 view.append($fixture, 'loopContext2');498 view.bind($('#dataBindTest'), {499 items: ary500 });501502 strictEqual($('#dataBindTest>ul>li:eq(0)').text(), 'A', 'ãã¤ã³ãããã¦ãããã¨');503 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li:eq(0)').text(), 'A', 'ãã¤ã³ãããã¦ãããã¨');504 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li:eq(1)').text(), 'B', 'ãã¤ã³ãããã¦ãããã¨');505 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li').length, ary[0].ary.length,506 'é
åã®è¦ç´ æ°åDOMãçæããããã¨');507 strictEqual($('#dataBindTest>ul>li:eq(2)').text(), 'B', 'ãã¤ã³ãããã¦ãããã¨');508 strictEqual($('#dataBindTest>ul>li:eq(3)>ul>li:eq(0)').text(), 'B-A', 'ãã¤ã³ãããã¦ãããã¨');509 strictEqual($('#dataBindTest>ul>li:eq(3)>ul>li:eq(1)').text(), 'B-B', 'ãã¤ã³ãããã¦ãããã¨');510 strictEqual($('#dataBindTest>ul>li:eq(3)>ul>li').length, ary[1].ary.length,511 'é
åã®è¦ç´ æ°åDOMãçæããããã¨');512 });513514 //=============================515 // Definition516 //=============================517 module('ObservableArrayã®ãã¤ã³ã');518519 //=============================520 // Body521 //=============================522 test('ObservableArrayããã¤ã³ãã§ãããã¨', function() {523 var items = h5.core.data.createObservableArray();524 items.copyFrom([{525 test: 'a'526 }, {527 test: 'b'528 }]);529530 view.append($fixture, 'loopContext1');531 view.bind($('#dataBindTest'), {532 test: 'aaa',533 items: items534 });535536 var result = ['a', 'b'];537 checkTexts(result, 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨');538 });539540 test('空ã®ObservableArrayããã¤ã³ãã§ãããã¨', function() {541 var items = h5.core.data.createObservableArray();542 items.copyFrom([]);543544 view.append($fixture, 'loopContext1');545 view.bind($('#dataBindTest'), {546 test: 'aaa',547 items: items548 });549550 strictEqual($('#dataBindTest li').length, 0, 'ç¹°ãè¿ãããè¦ç´ ãä¸ã¤ããªããã¨');551 });552553 test('ä¸èº«ããªãã¸ã§ã¯ãã§ãªãObservableArrayããã¤ã³ãããã¨ã¨ã©ã¼ã«ãªããã¨', function() {554 var items = h5.core.data.createObservableArray();555 items.copyFrom([]);556557 /** @type Any */558 var noObjs = [1, 'a', [], [{}]];559560 var l = noObjs.length;561 for (var i = 0; i < l; i++) {562 view.append($fixture, 'loopContext1');563564 throws(function(enviroment) {565 view.bind($('#dataBindTest'), {566 items: [{567 test: 'a'568 }, noObjs[i], {569 test: 'b'570 }]571 });572 }, function(actual) {573 return ERR_VIEW.ERR_CODE_INVALID_CONTEXT_SRC === actual.code;574 }, 'ã³ã³ããã¹ãã«Arrayã¾ãã¯ObservableArrayãæå®ãã¦ããªãããã¨ã©ã¼ã«ãªããã¨"');575576 $fixture.children().remove();577 }578 expect(l);579 });580581 test('ObservableItemãè¦ç´ ã«æã¤ObservableArrayããã¤ã³ãã§ãããã¨', 1, function() {582 var items = h5.core.data.createObservableArray();583 var schema = {584 test: null585 };586 var item1 = h5.core.data.createObservableItem(schema);587 item1.set('test', 'aa');588 var item2 = h5.core.data.createObservableItem(schema);589 item2.set('test', 'bb');590591 items.copyFrom([item1, item2]);592593 view.append($fixture, 'loopContext1');594 view.bind($('#dataBindTest'), {595 items: items596 });597598 var result = ['aa', 'bb'];599 checkTexts(result, 'data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨');600 });601602 test('循ç°åç
§ãæã¤ObservableArrayããã¤ã³ãã§ãããã¨', function() {603 var ary = [{604 test: 'A',605 ary: [{606 test: 'A'607 }]608609 }, {610 test: 'B',611 ary: [{612 test: 'B-A'613 }, {614 test: 'B-B'615 }]616 }];617618 var oAry = h5.core.data.createObservableArray();619 oAry.copyFrom(ary);620621 oAry.get(0).ary = oAry;622 view.append($fixture, 'loopContext2');623 view.bind($('#dataBindTest'), {624 items: oAry625 });626627 strictEqual($('#dataBindTest>ul>li:eq(0)').text(), 'A', 'ãã¤ã³ãããã¦ãããã¨');628 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li:eq(0)').text(), 'A', 'ãã¤ã³ãããã¦ãããã¨');629 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li:eq(1)').text(), 'B', 'ãã¤ã³ãããã¦ãããã¨');630 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li').length, ary[0].ary.length,631 'é
åã®è¦ç´ æ°åDOMãçæããããã¨');632 strictEqual($('#dataBindTest>ul>li:eq(2)').text(), 'B', 'ãã¤ã³ãããã¦ãããã¨');633 strictEqual($('#dataBindTest>ul>li:eq(3)>ul>li:eq(0)').text(), 'B-A', 'ãã¤ã³ãããã¦ãããã¨');634 strictEqual($('#dataBindTest>ul>li:eq(3)>ul>li:eq(1)').text(), 'B-B', 'ãã¤ã³ãããã¦ãããã¨');635 strictEqual($('#dataBindTest>ul>li:eq(3)>ul>li').length, ary[1].ary.length,636 'é
åã®è¦ç´ æ°åDOMãçæããããã¨');637 });638639 test('h5-data-loop-contextã«nulãæå®ãã', 1, function() {640 view.append($fixture, 'loopContext1');641 view.bind($('#dataBindTest'), {642 items: null643 });644645 strictEqual($('#dataBindTest li').length, 0, 'ç¹°ãè¿ãããè¦ç´ ãä¸ã¤ããªããã¨');646 });647648 //=============================649 // Definition650 //=============================651 var oAry = null;652653 var oAryInitValue = [{654 test: 'åæå¤0'655 }, {656 test: 'åæå¤1'657 }, {658 test: 'åæå¤2'659 }];660661 module('ObservableArrayã®å¤æ´æ¤ç¥ åã¡ã½ãã', {662 setup: function() {663 oAry = h5.core.data.createObservableArray();664 oAry.copyFrom(oAryInitValue);665 view.append($fixture, 'loopContext1');666 view.bind($('#dataBindTest'), {667 items: oAry668 });669 },670 teardown: function() {671 oAry = null;672 }673 });674675 //=============================676 // Body677 //=============================678679 test('set', function() {680 //TODO ãã¹ãã±ã¼ã¹æ¹å681682 oAry.set(0, {683 test: 'a'684 });685 checkTexts(['a', 'åæå¤1', 'åæå¤2'], 'æ¢åå¤ã®ä¸æ¸ããåæ ããããã¨');686687 oAry.set(0, {688 test: 'A'689 });690 oAry.set(1, {691 test: 'B'692 });693 oAry.set(3, {694 test: 'C'695 });696 checkTexts(['A', 'B', 'åæå¤2', 'C'], 'æ«å°¾ã«ã»ãããã¦ãµã¤ãºãæ¡å¼µãããå ´å');697698 oAry.copyFrom([]);699 oAry.set(0, {700 test: 'x'701 });702 checkTexts(['x'], '空ã«ããç¶æ
ããã»ããããå ´å');703 });704705 test('copyFrom', function() {706 oAry.copyFrom([{707 test: 'a'708 }, {709 test: 'b'710 }]);711 var result = ['a', 'b'];712 checkTexts(result, 'å¤æ´ãåæ ããããã¨');713714 oAry.copyFrom([]);715 checkTexts([], 'ä¸èº«ã空ã«ããã¨ç¹°ãè¿ãè¦ç´ ããªããªããã¨');716717 oAry.copyFrom([{718 test: 'AA'719 }]);720 checkTexts(['AA'], '空ã®ç¶æ
ããã空ã§ãªãç¶æ
ã«å¤æ´ããæããã¥ã¼ã«å¤æ´ãåæ ããããã¨');721 });722723 test('push', function() {724 oAry.push({725 test: 'a'726 });727 var result = ['åæå¤0', 'åæå¤1', 'åæå¤2', 'a'];728 checkTexts(result, 'å¤æ´ãåæ ããããã¨');729730 oAry.push({731 test: 'b'732 }, {733 test: 'c'734 });735 result.push('b', 'c');736 checkTexts(result, 'è¤æ°è¦ç´ ãå¼æ°ã«æ¸¡ããå ´åããå¤æ´ãåæ ããããã¨');737 });738739 test('pop', function() {740 oAry.pop();741 checkTexts(['åæå¤0', 'åæå¤1'], 'å¤æ´ãåæ ããããã¨');742743 oAry.pop();744 checkTexts(['åæå¤0'], 'å¤æ´ãåæ ããããã¨');745746 oAry.pop();747 checkTexts([], 'å¤æ´ãåæ ããããã¨');748 });749750 test('shift', function() {751 oAry.shift();752 checkTexts(['åæå¤1', 'åæå¤2'], 'å¤æ´ãåæ ããããã¨');753754 oAry.shift();755 checkTexts(['åæå¤2'], 'å¤æ´ãåæ ããããã¨');756757 oAry.shift();758 checkTexts([], 'å¤æ´ãåæ ããããã¨');759 });760761 test('unshift', function() {762 oAry.unshift({763 test: 'a'764 });765 var result = ['a', 'åæå¤0', 'åæå¤1', 'åæå¤2'];766 checkTexts(result, 'å¤æ´ãåæ ããããã¨');767768 oAry.unshift({769 test: 'c'770 }, {771 test: 'b'772 });773 result.unshift('c', 'b');774 checkTexts(result, 'è¤æ°è¦ç´ ãå¼æ°ã«æ¸¡ããå ´åããå¤æ´ãåæ ããããã¨');775 });776777 test('splice', function() {778 oAry.splice(0, 1, {779 test: 'a'780 });781 var result = ['a', 'åæå¤1', 'åæå¤2'];782 checkTexts(result, 'å¤æ´ãåæ ããããã¨');783784 oAry.splice(0, 1, {785 test: 'A'786 }, {787 test: 'B'788 }, {789 test: 'C'790 });791 result.splice(0, 1, 'A', 'B', 'C');792 checkTexts(result, 'å¤æ´ãåæ ããããã¨');793794 oAry.splice(1, 2, {795 test: 'D'796 }, {797 test: 'E'798 });799 result.splice(1, 2, 'D', 'E');800 checkTexts(result, 'å¤æ´ãåæ ããããã¨');801802 oAry.splice(0, 1);803 result.splice(0, 1);804 checkTexts(result, 'å¤æ´ãåæ ããããã¨');805 });806807 test('sort', function() {808 oAry.unshift({809 test: 'åæå¤3'810 });811812 oAry.sort(function(a, b) {813 return a.test > b.test ? 1 : -1;814 });815 checkTexts(['åæå¤0', 'åæå¤1', 'åæå¤2', 'åæå¤3'], 'å¤æ´ãåæ ããããã¨');816 });817818 test('reverse', function() {819 oAry.reverse();820 checkTexts(['åæå¤2', 'åæå¤1', 'åæå¤0'], 'å¤æ´ãåæ ããããã¨');821 });822823824 test('ãã¤ã³ãããã¦ããObservableArrayã®ä¸ã®ObservableItemãå¤æ´ããã¨ã表示ãæ¸ãå¤ãããã¨', function() {825 var schema = {826 test: null827 };828 var item1 = h5.core.data.createObservableItem(schema);829 var item2 = h5.core.data.createObservableItem(schema);830 item1.set('test', 'a');831 item2.set('test', 'b');832833 // oAryã®ä¸ãitem1ã ãã«ããï¼åæå¤ãæ¶ã)834 oAry.splice(0, oAry.length, item1);835 checkTexts(['a'], 'ObservableArrayã«ObservableItemãpushããã¨ããã¥ã¼ã¸åæ ããããã¨');836837 oAry.push(item2);838 checkTexts(['a', 'b'], 'ObservableItemã®ä¸èº«ããã¥ã¼ã¸åæ ããã¦ãããã¨');839840 oAry.push({841 test: 'c'842 });843 checkTexts(['a', 'b', 'c'], 'é常ã®ãªãã¸ã§ã¯ãã®ä¸èº«ããã¥ã¼ã¸åæ ããã¦ãããã¨');844845 item1.set('test', 'A');846 checkTexts(['A', 'b', 'c'], 'ObservableItemã®ä¸èº«ã®å¤æ´ããã¥ã¼ã¸åæ ããã¦ãããã¨');847 });848849850 //=============================851 // Definition852 //=============================853 module('ObservableArrayã®å¤æ´æ¤ç¥');854855 //=============================856 // Body857 //=============================858 test('ObservableArrayã®è¦ç´ ã®ãªãã¸ã§ã¯ããæã¤ObservableArrayãå¤æ´ããæãã¥ã¼ã¸åæ ããããã¨', function() {859 var innerOAry = h5.core.data.createObservableArray();860 innerOAry.copyFrom([{861 test: 'innerA',862 ary: []863 }]);864 var ary = [{865 test: 'a',866 ary: innerOAry867 }];868 var oAry = h5.core.data.createObservableArray();869 oAry.copyFrom(ary);870 view.append($fixture, 'loopContext2');871 view.bind($('#dataBindTest'), {872 items: oAry873 });874875 strictEqual($('#dataBindTest>ul>li:eq(0)').text(), 'a', 'ãã¤ã³ãããã¦ãããã¨');876 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li:eq(0)').text(), 'innerA', 'ãã¤ã³ãããã¦ãããã¨');877878 oAry.push({879 test: 'b',880 ary: []881 });882883 strictEqual($('#dataBindTest>ul>li:eq(2)').text(), 'b', 'ãã¤ã³ãããã¦ãããã¨');884 strictEqual($('#dataBindTest>ul>li:eq(3)>ui:first-child').length, 0,885 '空ã®é
åãæå®ããã®ã§è¦ç´ ãçæããã¦ããªããã¨');886887 innerOAry.push({888 test: 'innerB'889 });890891 strictEqual($('#dataBindTest>ul>li:eq(1)>ul>li:eq(1)').text(), 'innerB', 'ãã¤ã³ãããã¦ãããã¨');892 });893894 test('循ç°åç
§ãæã¤ObservableArrayã®ä¸èº«ãå¤æ´ããæã«ãã¥ã¼ã¸åæ ããããã¨',895 function() {896 var ary = [{897 test: 'A',898 ary: []899 }, {900 test: 'B',901 ary: [{902 test: 'B-A'903 }, {904 test: 'B-B'905 }]906 }];907 var oAry = h5.core.data.createObservableArray();908 oAry.copyFrom(ary);909 oAry.get(0).ary = oAry;910 view.append($fixture, 'loopContext2');911 view.bind($('#dataBindTest'), {912 items: oAry913 });914915 strictEqual($('#dataBindTest>ul>li:first').text(), 'A', 'å¤æ´ãåæ ããã¦ãããã¨');916 strictEqual($('#dataBindTest>ul>li:eq(1)>ul:first>li:eq(0)').text(), 'A',917 'å¤æ´ãåæ ããã¦ãããã¨');918 strictEqual($('#dataBindTest>ul>li:eq(1)>ul:first>li:eq(1)').text(), 'B',919 'å¤æ´ãåæ ããã¦ãããã¨');920 strictEqual($('#dataBindTest>ul>li:eq(2)').text(), 'B', 'å¤æ´ãåæ ããã¦ãããã¨');921 strictEqual($('#dataBindTest>ul>li:eq(3)>ul:first>li:eq(0)').text(), 'B-A',922 'å¤æ´ãåæ ããã¦ãããã¨');923 strictEqual($('#dataBindTest>ul>li:eq(3)>ul:first>li:eq(1)').text(), 'B-B',924 'å¤æ´ãåæ ããã¦ãããã¨');925926 oAry.splice(1, 1, {927 test: 'BB',928 ary: oAry929 });930931 strictEqual($('#dataBindTest>ul>li:first').text(), 'A', 'å¤æ´ãåæ ããã¦ãããã¨');932 strictEqual($('#dataBindTest>ul>li:eq(1)>ul:first>li:eq(0)').text(), 'A',933 'å¤æ´ãåæ ããã¦ãããã¨');934 strictEqual($('#dataBindTest>ul>li:eq(1)>ul:first>li:eq(1)').text(), 'BB',935 'å¤æ´ãåæ ããã¦ãããã¨');936 strictEqual($('#dataBindTest>ul>li:eq(2)').text(), 'BB', 'å¤æ´ãåæ ããã¦ãããã¨');937 strictEqual($('#dataBindTest>ul>li:eq(3)>ul:first>li:eq(0)').text(), 'A',938 'å¤æ´ãåæ ããã¦ãããã¨');939 strictEqual($('#dataBindTest>ul>li:eq(3)>ul:first>li:eq(1)').text(), 'BB',940 'å¤æ´ãåæ ããã¦ãããã¨');941 });942943 //=============================944 // Definition945 //=============================946 var testSchema = null;947 module('ObservableItem/DataItem', {948 setup: function() {949 var obj = {950 a: 'obj.a'951 };952 var oAry = h5.core.data.createObservableArray();953 oAry.copyFrom([1, 'b']);954 testSchema = {955 str: {956 type: 'string',957 defaultValue: 'abc'958 },959 num: {960 type: 'number',961 defaultValue: -123.45962 },963 obj: {964 defaultValue: obj965 },966 item: null,967 ary: {968 type: 'any',969 defaultValue: [{970 a: 'ary.1'971 }, {972 a: 'ary.2'973 }]974 },975 oAry: {976 type: 'any[]',977 defaultValue: [{978 a: 'oAry.1'979 }, {980 a: 'oAry.2'981 }]982 }983 };984 },985 teardown: function() {986 testSchema = null;987 }988 });989990 //=============================991 // Body992 //=============================993 test('ãã¤ã³ãã§ãããã¨', 2, function() {994 var exp = ['abc', '-123.45', 'obj.a', 'abc', '-123.45', 'ary.1', 'ary.2', 'oAry.1',995 'oAry.2'];996 testDataItemObsItem(function(item, isDataItem) {997 var itemType = isDataItem ? 'DataItem' : 'ObservableItem';998 item.set('item', item);9991000 // ãã¤ã³ãå
ã®è¨å®1001 $fixture.find('#dataBindTest').remove();1002 view.append($fixture, 'itemBind5');10031004 view.bind('#dataBindTest', item);10051006 checkTexts(exp, itemType + 'ã®ä¸èº«ããã¤ã³ãããã¦ãããã¨', 'span');1007 }, testSchema);1008 });10091010 test('循ç°åç
§ãæã£ã¦ãã¦ããã¤ã³ãã§ãããã¨', 2, function() {1011 var exp = ['abc', '-123.45', 'obj.a', 'abc', '-123.45', 'ary.1', 'ary.2', 'oAry.1',1012 'oAry.2'];1013 testDataItemObsItem(function(item, isDataItem) {1014 var itemType = isDataItem ? 'DataItem' : 'ObservableItem';1015 item.set('item', item);10161017 // ãã¤ã³ãå
ã®è¨å®1018 $fixture.find('#dataBindTest').remove();1019 view.append($fixture, 'itemBind5');1020 view.bind('#dataBindTest', item);10211022 checkTexts(exp, itemType + 'ã®ä¸èº«ããã¤ã³ãããã¦ãããã¨', 'span');1023 }, testSchema);1024 });10251026 test('ãªãã¸ã§ã¯ãå
ã®ObservableItem/DataItemããã¤ã³ãã§ãããã¨', 2, function() {1027 testDataItemObsItem(function(item, isDataItem) {1028 var itemType = isDataItem ? 'DataItem' : 'ObservableItem';1029 item.set('item', item);10301031 // ãã¤ã³ãå
ã®è¨å®1032 $fixture.find('#dataBindTest').remove();1033 view.append($fixture, 'itemBind5');10341035 // ä¸æ®µã©ãããã1036 $('#dataBindTest').wrapInner('<div data-h5-context="item">');10371038 view.bind('#dataBindTest', {1039 item: item1040 });10411042 var exp = ['abc', '-123.45', 'obj.a', 'abc', '-123.45', 'ary.1', 'ary.2', 'oAry.1',1043 'oAry.2'];1044 checkTexts(exp, itemType + 'ã®ä¸èº«ããã¤ã³ãããã¦ãããã¨', 'span');1045 }, testSchema);1046 });10471048 //=============================1049 // Definition1050 //=============================1051 module('ObservableItem/DataItemã®å¤æ´ã®é©ç¨', {1052 setup: function() {1053 testSchema = {1054 str: {1055 type: 'string',1056 defaultValue: 'abc'1057 },1058 num: {1059 type: 'number',1060 defaultValue: -123.451061 },1062 ary: {1063 type: 'any[]'1064 },1065 any: null1066 };1067 },1068 teardown: function() {1069 testSchema = null;1070 }1071 });10721073 //=============================1074 // Body1075 //=============================10761077 test('ObserbableArrayã®ä¸èº«ãå¤æ´ããã¨ãå¤æ´çµæããã¥ã¼ã«åæ ããããã¨', function() {1078 function createExpAry(oary) {1079 var ret = [];1080 for (var i = 0, l = oary.length; i < l; i++) {1081 var val = oary.get(i).test;1082 ret.push(val != null ? val.toString() : '');1083 }1084 return ret;1085 }1086 var oar = h5.core.data.createObservableArray();1087 oar.push({1088 test: 11089 });10901091 view.append($fixture, 'loopContext1');1092 view.bind($('#dataBindTest'), {1093 items: oar1094 });10951096 checkTexts(createExpAry(oar), 'li[i].text() == ObservableArray[i].test');10971098 // å¤ã追å ãã1099 oar.push({1100 test: 21101 });1102 checkTexts(createExpAry(oar), 'li[i].text() == ObservableArray[i].test');11031104 // nullã追å ãã1105 oar.push({1106 test: null1107 });1108 checkTexts(createExpAry(oar), 'li[i].text() == ObservableArray[i].test');11091110 // å¤ãåãåºã1111 oar.pop();1112 checkTexts(createExpAry(oar), 'li[i].text() == ObservableArray[i].test');11131114 // å¤ã®å¤æ´ããã£ã³ã»ã«ãã1115 oar.addEventListener('changeBefore', function(ev) {1116 ev.preventDefault();1117 });1118 oar.pop();1119 checkTexts(createExpAry(oar),1120 'changeBeforeã¤ãã³ãããã£ã³ã»ã«ãã¦ObservableArrayã®ä¸èº«ã«å¤æ´ããªãã®ã§ããã¥ã¼ã¯å¤æ´ãããªããã¨');1121 });11221123 test('ObserbableItem/DataItemã®ä¸èº«ãå¤æ´ããã¨ããã¥ã¼ã«åæ ããããã¨', 4, function() {1124 testDataItemObsItem(function(item, isDataItem) {1125 var itemType = isDataItem ? 'DataItem' : 'ObservableItem';11261127 item.set({1128 str: 'AA',1129 num: 111130 });11311132 // ãã¤ã³ãå
ã®è¨å®1133 $fixture.find('#dataBindTest').remove();1134 view.append($fixture, 'itemBind1');11351136 view.bind($('#dataBindTest'), item);1137 var result = ['AA', '11'];1138 checkTexts(result, itemType + ' data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨', 'span');11391140 item.set({1141 str: 'BB',1142 num: 221143 });1144 result = ['BB', '22'];1145 checkTexts(result, itemType + ' å¤æ´ãåæ ããã¦ãããã¨', 'span');1146 }, testSchema);1147 });11481149 test('ObserbableItem/DataItemãæã¤ObservableArrayè¦ç´ ã®ä¸èº«ãå¤æ´ããã¨ããã¥ã¼ã«åæ ããããã¨', 6, function() {1150 testDataItemObsItem(function(item, isDataItem) {1151 var itemType = isDataItem ? 'DataItem' : 'ObservableItem';11521153 item.set('ary', [{1154 test: 'ary[0]'1155 }, {1156 test: 'ary[1]'1157 }]);11581159 // ãã¤ã³ãå
ã®è¨å®1160 $fixture.find('#dataBindTest').remove();1161 view.append($fixture, 'itemBind2');11621163 view.bind($('#dataBindTest'), item);1164 var result = ['ary[0]', 'ary[1]'];1165 checkTexts(result, itemType + ' data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨', 'span');11661167 item.set('ary', [{1168 test: 'newAry[0]'1169 }]);1170 result = ['newAry[0]'];1171 checkTexts(result, itemType + ' setã§å¤æ´ããæã«åæ ããã¦ãããã¨', 'span');11721173 // ObservableArrayã®ã¡ã½ããã§é
åãå¤æ´1174 item.get('ary').push({1175 test: 'newAry[1]'1176 });1177 result.push('newAry[1]');1178 checkTexts(result, itemType + ' ã¡ã½ããæä½ã«ããå¤æ´ããã£ãæã«åæ ããã¦ãããã¨', 'span');1179 }, testSchema);1180 });11811182 test('ObserbableItem/DataItemãæã¤type:anyã®è¦ç´ ã«æ ¼ç´ãããObservableItem/DataItemãããã¥ã¼ã«åæ ããããã¨', 8,1183 function() {1184 testDataItemObsItem(function(item, isDataItem) {1185 var itemType = isDataItem ? 'DataItem' : 'ObservableItem';11861187 // itemã«æãããItemã®ä½æ1188 var item2 = {};1189 var item3 = { // é常ãªãã¸ã§ã¯ã1190 str: 'c',1191 num: 31192 };1193 var item4 = {};1194 if (isDataItem) {1195 item2 = item.getModel().create({1196 id: 'item2',1197 str: 'b',1198 num: 21199 });1200 item4 = item.getModel().create({1201 id: 'item4',1202 str: 'd',1203 num: 41204 });1205 } else {1206 item2 = h5.core.data.createObservableItem(testSchema);1207 item4 = h5.core.data.createObservableItem(testSchema);1208 item2.set({1209 str: 'b',1210 num: 21211 });1212 item4.set({1213 str: 'd',1214 num: 41215 });1216 }1217 item.set({1218 str: 'a',1219 num: 1,1220 any: item21221 });12221223 // ãã¤ã³ãå
ã®è¨å®1224 $fixture.find('#dataBindTest').remove();1225 view.append($fixture, 'itemBind3');12261227 view.bind($('#dataBindTest'), item);1228 var result = ['a', '1', 'b', '2'];1229 checkTexts(result, itemType + ' data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨', 'span');12301231 // ãã¤ã³ãããã¢ã¤ãã ãæã¤ã¢ã¤ãã ãå¤æ´1232 item2.set({1233 str: 'bb',1234 num: 221235 });1236 result = ['a', '1', 'bb', '22'];1237 checkTexts(result, itemType + ' setã§å¤æ´ããæã«åæ ããã¦ãããã¨', 'span');12381239 // ãã¤ã³ãããã¢ã¤ãã ãæã¤ã¢ã¤ãã ãé常ãªãã¸ã§ã¯ãã«å¤æ´1240 item.set('any', item3);1241 result = ['a', '1', 'c', '3'];1242 checkTexts(result, itemType + ' setã§å¤æ´ããæã«åæ ããã¦ãããã¨', 'span');12431244 // ãã¤ã³ãããã¢ã¤ãã ãæã¤ã¢ã¤ãã ãå¥ã®ã¢ã¤ãã ã«å¤æ´1245 item.set('any', item4);1246 result = ['a', '1', 'd', '4'];1247 checkTexts(result, itemType + ' setã§å¤æ´ããæã«åæ ããã¦ãããã¨', 'span');1248 }, testSchema);1249 });12501251 test('ObserbableItem/DataItemãæã¤type:anyã®è¦ç´ ã«æ ¼ç´ãããé
åãObservableArrayãããã¥ã¼ã«åæ ããããã¨', 10,1252 function() {1253 testDataItemObsItem(function(item, isDataItem) {1254 var itemType = isDataItem ? 'DataItem' : 'ObservableItem';12551256 var obsArray = h5.core.data.createObservableArray();1257 obsArray.copyFrom([{1258 test: 'ary[0]'1259 }, {1260 test: 'ary[1]'1261 }]);1262 item.set({1263 any: obsArray1264 });12651266 // ãã¤ã³ãå
ã®è¨å®1267 $('#dataBindTest').remove();1268 view.append($fixture, 'itemBind4');12691270 view.bind('#dataBindTest', item);1271 var result = ['ary[0]', 'ary[1]'];1272 checkTexts(result, itemType + ' data-h5-bindæå®ããè¦ç´ ã«å¤ã表示ããã¦ãããã¨', 'span');12731274 // ObservableArrayã®ã¡ã½ããã§é
åãå¤æ´1275 item.get('any').push({1276 test: 'newAry[1]'1277 });1278 result.push('newAry[1]');1279 checkTexts(result, itemType + ' ã¡ã½ããæä½ã«ããå¤æ´ããã£ãæã«åæ ããã¦ãããã¨', 'span');12801281 // å¥ã®é
åã¤ã³ã¹ã¿ã³ã¹ã«å¤æ´1282 item.set('any', [{1283 test: 'otherAry[0]'1284 }, {1285 test: 'otherAry[1]'1286 }]);1287 result = ['otherAry[0]', 'otherAry[1]'];1288 checkTexts(result, itemType + ' å¥ã®é
åã¤ã³ã¹ã¿ã³ã¹ã«å¤æ´ããæã«åæ ããã¦ãããã¨', 'span');12891290 // å¥ã®ObservableArrayã¤ã³ã¹ã¿ã³ã¹ã«å¤æ´1291 var oAry = h5.core.data.createObservableArray();1292 oAry.copyFrom([{1293 test: 'otherOAry[0]'1294 }]);1295 item.set('any', oAry);1296 result = ['otherOAry[0]'];1297 checkTexts(result, itemType + ' å¥ã®ObservableArrayã¤ã³ã¹ã¿ã³ã¹ã«å¤æ´ããæã«åæ ããã¦ãããã¨',1298 'span');12991300 // ObservableArrayã®ã¡ã½ããã§é
åãå¤æ´1301 oAry.push({1302 test: 'otherOAry[1]'1303 });1304 result = ['otherOAry[0]', 'otherOAry[1]'];1305 checkTexts(result, itemType + ' å·®ãæ¿ãå¾ã®ObservableArrayã®ä¸èº«ãå¤æ´ããæã«åæ ããã¦ãããã¨',1306 'span');13071308 }, testSchema);1309 });13101311 //=============================1312 // Definition1313 //=============================1314 module('DataItem/ObservableItemãä¿æããObservableArrayã«å¯¾ããå¤æ´', {1315 setup: function() {1316 var schema = {1317 id: {1318 id: true1319 },1320 ary: {1321 type: 'any[]'1322 },1323 ary2: {1324 type: 'any'1325 }1326 };1327 this.testDataModelManager = h5.core.data.createManager('TestManager');1328 this.testDataModel = this.testDataModelManager.createModel({1329 name: 'TestModel',1330 schema: schema1331 });1332 this.testDataItem = this.testDataModel.create({1333 id: '1'1334 });13351336 this.testObsItem = h5.core.data.createObservableItem(schema);1337 },1338 teardown: function() {1339 $('#dataBindTest').remove();1340 this.testDataModel.remove('1');1341 this.testDataModelManager.dropModel(this.testDataModel);1342 this.testDataModel = null;1343 this.testDataItem = null;1344 this.testObsItem = null;1345 },1346 testDataModelManager: null,1347 testDataModel: null,1348 testDataItem: null,1349 testObsItem: null1350 });13511352 //=============================1353 // Body1354 //=============================1355 test(1356 'type:any[]ã«æ ¼ç´ãããObservableArrayãDataItem#set()ã§æ´æ°ãã',1357 function() {1358 function testFunc(item) {1359 var name = item.getModel ? 'DataItem' : 'ObservableItem';1360 view.append($fixture, 'itemBind7');13611362 // åæå¤ãè¨å®1363 var oar = h5.core.data.createObservableArray();1364 oar.push({1365 test: 'AAAA'1366 });1367 item.set('ary', oar);13681369 var binding = view.bind($('#dataBindTest'), {1370 item: item1371 });13721373 // loop-contextãnullã§æ´æ°1374 item.set('ary', null);1375 equal($('#dataBindTest .loop1').length, 0, name1376 + ': ObservableArrayã®å¤æ´ããã¥ã¼ã«åæ ããã¦ãããã¨');13771378 // loop-contextãå¥ã®ObsArrayã§æ´æ°1379 var oar2 = h5.core.data.createObservableArray();1380 oar2.push({1381 test: 101382 }, {1383 test: 201384 });1385 item.set('ary', oar2);1386 checkTexts(['10', '20'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', '.loop1');13871388 binding.unbind();1389 $('#dataBindTest').remove();1390 }13911392 testFunc(this.testDataItem);1393 testFunc(this.testObsItem);1394 });13951396 test(1397 'type:anyã«æ ¼ç´ãããObservableArrayãDataItem#set()ã§æ´æ°ãã',1398 function() {1399 function testFunc(item) {1400 var name = item.getModel ? 'DataItem' : 'ObservableItem';1401 view.append($fixture, 'itemBind7');14021403 // åæå¤ãè¨å®1404 var oar = h5.core.data.createObservableArray();1405 oar.push({1406 test: 'AAAA'1407 });1408 item.set('ary2', oar);14091410 var binding = view.bind($('#dataBindTest'), {1411 item: item1412 });14131414 // loop-contextãnullã§æ´æ°1415 item.set('ary2', null);1416 equal($('#dataBindTest .loop2').length, 0, name1417 + ': ObservableArrayã®å¤æ´ããã¥ã¼ã«åæ ããã¦ãããã¨');14181419 // loop-contextãå¥ã®ObsArrayã§æ´æ°1420 var oar2 = h5.core.data.createObservableArray();1421 oar2.push({1422 test: 101423 }, {1424 test: 201425 });1426 item.set('ary2', oar2);1427 checkTexts(['10', '20'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', '.loop2');14281429 binding.unbind();1430 $('#dataBindTest').remove();1431 }14321433 testFunc(this.testDataItem);1434 testFunc(this.testObsItem);1435 });14361437 test('copyFrom()', function() {1438 function testFunc(item) {1439 var name = item.getModel ? 'DataItem' : 'ObservableItem';1440 view.append($fixture, 'itemBind7');14411442 var binding = view.bind($('#dataBindTest'), {1443 item: item1444 });14451446 var oar = item.get('ary');1447 equal(oar.length, 0, name + ': ObservableArrayã«ã¯ä½ãæ ¼ç´ããã¦ããªããã¨ã');14481449 oar.copyFrom([{1450 test: 'a'1451 }, {1452 test: 'b'1453 }, {1454 test: 'c'1455 }]);1456 checkTexts(['a', 'b', 'c'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');14571458 oar.copyFrom([{1459 test: 'a'1460 }]);1461 equal($('#dataBindTest span').text(), oar.get(0).test, name1462 + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨');14631464 binding.unbind();14651466 oar.copyFrom([{1467 test: 'A'1468 }, {1469 test: 'B'1470 }, {1471 test: 'C'1472 }]);1473 equal($('#dataBindTest span').text(), 'a', name1474 + ': unbind()å¾ObservableArrayã«å¤æ´ãå ãã¦ããã¥ã¼ã¯æ´æ°ãããªããã¨');14751476 $('#dataBindTest').remove();1477 }1478 testFunc(this.testDataItem);1479 testFunc(this.testObsItem);1480 });14811482 test('push()', function() {1483 function testFunc(item) {1484 var name = item.getModel ? 'DataItem' : 'ObservableItem';1485 view.append($fixture, 'itemBind7');14861487 var binding = view.bind($('#dataBindTest'), {1488 item: item1489 });14901491 item.addEventListener('change', function(ev) {1492 ok(true, 'ã¢ã¤ãã ã®changeã¤ãã³ããçºçãããã¨');1493 });14941495 var oar = item.get('ary');14961497 equal(oar.length, 0, name + ': ObservableArrayã«ã¯ä½ãæ ¼ç´ããã¦ããªããã¨ã');1498 oar.push({1499 test: 'AAA'1500 });15011502 equal($('#dataBindTest span').text(), 'AAA', name1503 + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨');15041505 oar.push({1506 test: 'BBB'1507 });15081509 checkTexts(['AAA', 'BBB'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');15101511 oar.push({1512 test: 'CCC'1513 });15141515 checkTexts(['AAA', 'BBB', 'CCC'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');15161517 binding.unbind();15181519 oar.push({1520 test: 'DDD'1521 });15221523 checkTexts(['AAA', 'BBB', 'CCC'], name1524 + ': unbind()å¾ObservableArrayã«å¤æ´ãå ãã¦ããã¥ã¼ã¯æ´æ°ãããªããã¨', 'span');15251526 $('#dataBindTest').remove();1527 }1528 testFunc(this.testDataItem);1529 testFunc(this.testObsItem);1530 });15311532 test('pop()', function() {1533 function testFunc(item) {1534 var name = item.getModel ? 'DataItem' : 'ObservableItem';1535 view.append($fixture, 'itemBind7');1536 var binding = view.bind($('#dataBindTest'), {1537 item: item1538 });15391540 item.addEventListener('change', function(ev) {1541 ok(true, 'ã¢ã¤ãã ã®changeã¤ãã³ããçºçãããã¨');1542 });15431544 item.set('ary', [{1545 test: 'a'1546 }, {1547 test: 'b'1548 }, {1549 test: 'c'1550 }, {1551 test: 'd'1552 }]);1553 var oar = item.get('ary');15541555 checkTexts(['a', 'b', 'c', 'd'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');15561557 oar.pop();1558 checkTexts(['a', 'b', 'c'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');15591560 oar.pop();1561 checkTexts(['a', 'b'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');15621563 oar.pop();1564 checkTexts(['a'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');15651566 binding.unbind();15671568 oar.pop();1569 checkTexts(['a'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');15701571 $('#dataBindTest').remove();1572 }1573 testFunc(this.testDataItem);1574 testFunc(this.testObsItem);1575 });15761577 test('shift()', function() {1578 function testFunc(item) {1579 var name = item.getModel ? 'DataItem' : 'ObservableItem';1580 view.append($fixture, 'itemBind7');1581 var binding = view.bind($('#dataBindTest'), {1582 item: item1583 });15841585 item.set('ary', [{1586 test: 'a'1587 }, {1588 test: 'b'1589 }, {1590 test: 'c'1591 }, {1592 test: 'd'1593 }]);1594 var oar = item.get('ary');15951596 checkTexts(['a', 'b', 'c', 'd'], name + ': set()ã§è¨å®ããå¤ãæ ¼ç´ããã¦ãããã¨', 'span');15971598 oar.shift();1599 checkTexts(['b', 'c', 'd'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16001601 oar.shift();1602 checkTexts(['c', 'd'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16031604 oar.shift();1605 checkTexts(['d'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');1606 binding.unbind();16071608 oar.shift();16091610 checkTexts(['d'], name + ': unbind()å¾ObservableArrayã«å¤æ´ãå ãã¦ããã¥ã¼ã¯æ´æ°ãããªããã¨', 'span');16111612 $('#dataBindTest').remove();1613 }1614 testFunc(this.testDataItem);1615 testFunc(this.testObsItem);1616 });16171618 test('unshift()', function() {1619 function testFunc(item) {1620 var name = item.getModel ? 'DataItem' : 'ObservableItem';1621 view.append($fixture, 'itemBind7');1622 var binding = view.bind($('#dataBindTest'), {1623 item: item1624 });16251626 var oar = item.get('ary');16271628 equal(oar.length, 0, name + ': ObservableArrayã«ã¯ä½ãæ ¼ç´ããã¦ããªããã¨ã');1629 oar.unshift({1630 test: 'a'1631 });1632 checkTexts(['a'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16331634 oar.unshift({1635 test: 'b'1636 });1637 checkTexts(['b', 'a'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16381639 oar.unshift({1640 test: 'c'1641 });1642 checkTexts(['c', 'b', 'a'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16431644 binding.unbind();16451646 oar.unshift({1647 test: 'd'1648 });1649 checkTexts(['c', 'b', 'a'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16501651 $('#dataBindTest').remove();1652 }1653 testFunc(this.testDataItem);1654 testFunc(this.testObsItem);1655 });16561657 test('splice()', function() {1658 function testFunc(item) {1659 var name = item.getModel ? 'DataItem' : 'ObservableItem';1660 view.append($fixture, 'itemBind7');1661 var binding = view.bind($('#dataBindTest'), {1662 item: item1663 });16641665 var ar = [{1666 test: 'a'1667 }, {1668 test: 'b'1669 }, {1670 test: 'c'1671 }];16721673 item.set('ary', ar);1674 var oar = item.get('ary');16751676 checkTexts(['a', 'b', 'c'], name + ': set()ã§è¨å®ããå¤ãæ ¼ç´ããã¦ãããã¨', 'span');16771678 oar.splice(1, 2);1679 checkTexts(['a'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16801681 var obj = {1682 test: 'AA'1683 };1684 oar.splice(0, 1, obj);1685 checkTexts(['AA'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16861687 binding.unbind();16881689 oar.splice(0, 1);1690 checkTexts(['AA'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');16911692 $('#dataBindTest').remove();1693 }1694 testFunc(this.testDataItem);1695 testFunc(this.testObsItem);1696 });16971698 test('sort()', function() {1699 function testFunc(item) {1700 var name = item.getModel ? 'DataItem' : 'ObservableItem';1701 view.append($fixture, 'itemBind7');1702 var binding = view.bind($('#dataBindTest'), {1703 item: item1704 });17051706 item.set('ary', [{1707 test: 11708 }, {1709 test: 51710 }, {1711 test: 31712 }]);1713 var oar = item.get('ary');17141715 checkTexts(['1', '5', '3'], name + ': set()ã§è¨å®ããå¤ãæ ¼ç´ããã¦ãããã¨', 'span');17161717 oar.sort(function(a, b) {1718 return a.test < b.test ? 1 : a.test > b.test ? -1 : 0;1719 });17201721 checkTexts(['5', '3', '1'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');17221723 oar.sort(function(a, b) {1724 return a.test > b.test ? 1 : a.test < b.test ? -1 : 0;1725 });17261727 checkTexts(['1', '3', '5'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');17281729 binding.unbind();17301731 oar.sort(function(a, b) {1732 return a.test < b.test ? 1 : a.test > b.test ? -1 : 0;1733 });1734 checkTexts(['1', '3', '5'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');17351736 $('#dataBindTest').remove();1737 }1738 testFunc(this.testDataItem);1739 testFunc(this.testObsItem);1740 });17411742 test('reverse()', function() {1743 function testFunc(item) {1744 var name = item.getModel ? 'DataItem' : 'ObservableItem';1745 view.append($fixture, 'itemBind7');1746 var binding = view.bind($('#dataBindTest'), {1747 item: item1748 });17491750 item.set('ary', [{1751 test: 11752 }, {1753 test: 51754 }, {1755 test: 31756 }]);1757 var oar = item.get('ary');17581759 checkTexts(['1', '5', '3'], name + ': set()ã§è¨å®ããå¤ãæ ¼ç´ããã¦ãããã¨', 'span');17601761 oar.reverse();17621763 checkTexts(['3', '5', '1'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');17641765 binding.unbind();17661767 oar.reverse();1768 checkTexts(['3', '5', '1'], name + ': ObservableArrayã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');17691770 $('#dataBindTest').remove();1771 }1772 testFunc(this.testDataItem);1773 testFunc(this.testObsItem);1774 });17751776 test('beginUpdate/endUpdateã§ã¤ãã³ãå¶å¾¡ããã¦ããã¨ãã«ãDataItemã«å±ããObservableArrayãå¤æ´ãã', 2, function() {1777 var item = this.testDataItem;1778 view.append($fixture, 'itemBind7');17791780 // åæå¤ãè¨å®1781 var oar = h5.core.data.createObservableArray();1782 oar.push({1783 test: 'A'1784 });1785 item.set('ary', oar);17861787 var binding = view.bind($('#dataBindTest'), {1788 item: item1789 });17901791 this.testDataModelManager.beginUpdate();1792 item.get('ary').push({1793 test: 'B'1794 });1795 checkTexts(['A'], 'beginUpdate()å¾ã®æ´æ°ã¯ObservableArrayã®å¤æ´ã¯ãã¥ã¼ã«åæ ãããªããã¨', '.loop1');1796 this.testDataModelManager.endUpdate();1797 checkTexts(['A', 'B'], 'endUpdateã®ã¿ã¤ãã³ã°ã§ãã¥ã¼ã«åæ ããããã¨', '.loop1');17981799 binding.unbind();1800 $('#dataBindTest').remove();1801 });180218031804 //=============================1805 // Definition1806 //=============================1807 var testBaseDataModel = null;1808 var testBaseDataItem = null;1809 var testDataModel2 = null;1810 var testDataItem2 = null;18111812 module('DataItemãä¿æããDataItemã«å¯¾ããå¤æ´', {1813 setup: function() {1814 var schema = {1815 id: {1816 id: true1817 },1818 test: {1819 type: 'integer',1820 defaultValue: 101821 }1822 };1823 var schema2 = {1824 id: {1825 id: true1826 },1827 val: {1828 type: 'string',1829 defaultValue: 'AAA'1830 },1831 data: {1832 type: '@BaseTestModel'1833 }1834 };1835 var manager = h5.core.data.createManager('TestManager');1836 testBaseDataModel = manager.createModel({1837 name: 'BaseTestModel',1838 schema: schema1839 });1840 testBaseDataItem = testBaseDataModel.create({1841 id: '1'1842 });1843 testDataModel2 = manager.createModel({1844 name: 'TestModel',1845 schema: schema21846 });1847 testDataItem2 = testDataModel2.create({1848 id: '1',1849 data: testBaseDataItem1850 });1851 },1852 teardown: function() {1853 $('#dataBindTest').remove();1854 testDataModel2.remove('1');1855 testDataModel2 = null;1856 testBaseDataModel.remove('1');1857 testBaseDataModel = null;1858 }1859 });18601861 //=============================1862 // Body1863 //=============================18641865 test('å¤ãæ´æ°ãã', function() {1866 view.append($fixture, 'itemBind9');1867 var binding = view.bind($('#dataBindTest'), {1868 item: testDataItem21869 });187018711872 checkTexts(['10'], 'DataItemã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');18731874 testBaseDataItem.set({1875 test: 10001876 });18771878 checkTexts(['1000'], 'æ´æ°ããå¤ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');18791880 binding.unbind();18811882 testBaseDataItem.set({1883 test: 50001884 });18851886 checkTexts(['1000'], 'unbind()å¾ã«DataItemãæ´æ°ãã¦ããã¥ã¼ã«åæ ãããªããã¨', 'span');1887 });18881889 test('ãã¥ã¼ã«è¡¨ç¤ºããã¦ããDataItemãå¥ã®DataItemã«å¤æ´ãã', function() {1890 var item = testBaseDataModel.create({1891 id: '2',1892 test: 5001893 });1894 var item2 = testBaseDataModel.create({1895 id: '3',1896 test: 50001897 });1898 var item3 = testBaseDataModel.create({1899 id: '4',1900 test: 100001901 });19021903 view.append($fixture, 'itemBind9');1904 var binding = view.bind($('#dataBindTest'), {1905 item: testDataItem21906 });1907 checkTexts(['10'], 'DataItemã®å
容ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');19081909 testDataItem2.set({1910 data: item1911 });1912 checkTexts(['500'], 'æ´æ°ããå¤ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');19131914 testDataItem2.set({1915 data: null1916 });1917 checkTexts([''], 'æ´æ°ããå¤ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');19181919 testDataItem2.set({1920 data: item21921 });1922 checkTexts(['5000'], 'æ´æ°ããå¤ããã¥ã¼ã«åæ ããã¦ãããã¨', 'span');19231924 binding.unbind();19251926 testDataItem2.set({1927 data: item31928 });1929 checkTexts(['5000'], 'unbind()å¾ã«DataItemãæ´æ°ãã¦ããã¥ã¼ã«åæ ãããªããã¨', 'span');1930 });1931193219331934 //=============================1935 // Definition1936 //=============================1937 module('ãã¤ã³ãã®è©³ç´°æå®');19381939 //=============================1940 // Body1941 //=============================19421943 test('å±æ§ã¸ã®ãã¤ã³ã', function() {1944 // ãã¤ã³ãå
ã®è¨å®1945 view.append($fixture, 'id');19461947 view.bind('#dataBindTest', {1948 id: 'bindTest123'1949 });19501951 var $span = $fixture.find('span');1952 strictEqual($span.attr('id'), 'bindTest123', 'idå±æ§ã®å¤ãæ¸ãå¤ãã£ã¦ãããã¨');1953 strictEqual($span.text(), 'before', 'ããã¹ããã¼ãã®å¤ã¯æ¸ãå¤ãã£ã¦ããªããã¨');1954 });19551956 test('å±æ§åãæå®ããã«ãå±æ§ã¸ãã¤ã³ã', 1, function() {1957 view.append($fixture, 'id2');19581959 throws(function(enviroment) {1960 view.bind('#dataBindTest', {1961 id: 'bindTest123'1962 });1963 }, function(actual) {1964 return ERR_VIEW.ERR_CODE_REQUIRE_DETAIL === actual.code;1965 }, 'data-h5-bindã®attrã«å±æ§åãæå®ãã¦ããªãããã¨ã©ã¼ã«ãªããã¨"');1966 });19671968 test('classã¸ã®ãã¤ã³ã', function() {1969 // ãã¤ã³ãå
ã®è¨å®1970 view.append($fixture, 'class');19711972 view.bind('#dataBindTest', {1973 cls: 'bindTestCls123'1974 });19751976 var $span = $fixture.find('span');1977 strictEqual($span.attr('class'), 'testClass bindTestCls123', 'classå±æ§ã«ãã¤ã³ãããå¤ã追å ããã¦ãããã¨');1978 strictEqual($span.text(), 'test', 'ããã¹ããã¼ãã®å¤ã¯æ¸ãå¤ãã£ã¦ããªããã¨');1979 });19801981 test('styleã¸ã®ãã¤ã³ã', function() {1982 // ãã¤ã³ãå
ã®è¨å®1983 view.append($fixture, 'style');19841985 view.bind('#dataBindTest', {1986 marginLeft: '15px',1987 margin: '5px 10px 20px 30px'1988 });19891990 var $span = $fixture.find('span');1991 var span1 = $span[0];1992 var span2 = $span[1];1993 strictEqual(span1.style.marginLeft, '15px', 'ãã¤ã³ãããã¹ã¿ã¤ã«ãé©å¿ããã¦ãããã¨');1994 strictEqual(rgbToHex($(span1).css('display')), 'block', 'ä¸æ¸ãããã¦ããªãã¹ã¿ã¤ã«ã¯ãã®ã¾ã¾æ®ã£ã¦ãããã¨');1995 strictEqual(span2.style.marginTop, '5px', 'ãã¤ã³ãããã¹ã¿ã¤ã«ãé©å¿ããã¦ãããã¨');1996 strictEqual(span2.style.marginRight, '10px', 'ãã¤ã³ãããã¹ã¿ã¤ã«ãé©å¿ããã¦ãããã¨');1997 strictEqual(span2.style.marginBottom, '20px', 'ãã¤ã³ãããã¹ã¿ã¤ã«ãé©å¿ããã¦ãããã¨');1998 strictEqual(span2.style.marginLeft, '30px', 'ãã¤ã³ãããã¹ã¿ã¤ã«ãé©å¿ããã¦ãããã¨');1999 strictEqual(rgbToHex($(span2).css('display')), 'block', 'ä¸æ¸ãããã¦ããªãã¹ã¿ã¤ã«ã¯ãã®ã¾ã¾æ®ã£ã¦ãããã¨');2000 });20012002 test('ããããã£åãæå®ããã«ãstyleã¸ãã¤ã³ã', function() {2003 // ãã¤ã³ãå
ã®è¨å®2004 view.append($fixture, 'style2');20052006 throws(function(enviroment) {2007 view.bind('#dataBindTest', {2008 color: 'red'2009 });2010 }, function(actual) {2011 return ERR_VIEW.ERR_CODE_REQUIRE_DETAIL === actual.code;2012 }, 'data-h5-bindã®styleã«ããããã£åãæå®ãã¦ããªãããã¨ã©ã¼ã«ãªããã¨"');2013 });20142015 test('ããã¹ããã¼ãã¸ã®ãã¤ã³ã', function() {2016 // ãã¤ã³ãå
ã®è¨å®2017 view.append($fixture, 'text');20182019 var str = '<a href="#e">a</a>';2020 view.bind($('#dataBindTest'), {2021 test: str2022 });20232024 var $span = $fixture.find('span');2025 strictEqual($span.text(), str, 'å¤ãããã¹ããã¼ãã¨ãã¦ãã¤ã³ãããã¦ãããã¨');2026 });20272028 test('HTMLã¸ã®ãã¤ã³ã', function() {2029 var e = document.createElement('span');2030 e.innerHTML = '<a href="#e"/>';2031 var url = e.firstChild.href;20322033 // ãã¤ã³ãå
ã®è¨å®2034 view.append($fixture, 'html');20352036 var str = '<a href="' + url + '">a</a>';2037 view.bind($('#dataBindTest'), {2038 test: str2039 });20402041 // strã«"&"ãå«ã¾ããå ´åãbind(å
é¨çã«ã¯$.html())ã§å¤ãã»ããããæã«"&"ã«ã¨ã¹ã±ã¼ãããã2042 // (element.innerHTML = '&' ã§ãåã)2043 // URLä¸ã®æåãã¨ã¹ã±ã¼ãããã¦ãã¦ãæ£ããURLã¨è§£éããã¦ãªã³ã¯ãè¸ããã®ã§åé¡ãªãã20442045 var $span = $fixture.find('span');2046 strictEqual($span.html().toLowerCase().replace(/&/g, '&'), str.toLowerCase(),2047 'å¤ãinnerHTMLã¨ãã¦ãã¤ã³ãããã¦ãããã¨');2048 strictEqual($span.find('a').length, 1, 'DOMè¦ç´ ãæ°ããä½æããã¦ãããã¨');2049 });20502051 test('ã:ããå«ãããããã£ã®ãã¤ã³ã', function() {2052 // ãã¤ã³ãå
ã®è¨å®2053 view.append($fixture, 'id');20542055 view.bind('#dataBindTest', {2056 'attr(id):id': 'after'2057 });20582059 var $span = $fixture.find('span');2060 strictEqual($span.text(), 'before', 'ã:ããå«ãããããã£ã¯ãã¤ã³ããããªããã¨');2061 strictEqual($span.attr('id'), undefined, 'ã:ããå«ãããããã£ã¯ãã¤ã³ããããªããã¨');2062 });20632064 test('ç¡å¹ãªãã¤ã³ã種å¥ãæå®', function() {2065 // ãã¤ã³ãå
ã®è¨å®2066 view.append($fixture, 'invalidDef');20672068 throws(function(enviroment) {2069 view.bind('#dataBindTest', {2070 id: 'bindTest123'2071 });2072 }, function(actual) {2073 return ERR_VIEW.ERR_CODE_UNKNOWN_BIND_DIRECTION === actual.code;2074 }, 'data-h5-bindã®styleã«ããããã£åãæå®ãã¦ããªãããã¨ã©ã¼ã«ãªããã¨"');2075 });20762077 //=============================2078 // Definition2079 //=============================2080 var bindItem = h5.core.data.createObservableItem({2081 test: null2082 });2083 module('get', {2084 setup: function() {2085 $fixture.append('<div id="inFixture">');20862087 bindItem.set({2088 test: 'a'2089 });2090 },2091 teardown: function() {2092 clearController();2093 }2094 });20952096 //=============================2097 // Body2098 //=============================209921002101 test('getã¯ãã¼ã¿ãã¤ã³ããããªããã¨', function() {2102 var str = view.get('simple', {2103 test: 'a'2104 });21052106 var $dom = $(str);2107 strictEqual($dom.find('span').text(), 'ãã¤ã³ãå', 'ãã¼ã¿ãã¤ã³ãããã¦ããªããã¨');2108 });21092110 asyncTest('ã³ã³ããã¼ã©å
this.view.get ãã¼ã¿ãã¤ã³ããããªããã¨', function() {2111 h5.core.controller($fixture, {2112 __name: 'TestController',2113 __templates: 'template/data-bind.ejs',2114 __ready: function() {2115 var str = this.view.get('simple', {2116 test: 'a'2117 });21182119 var $dom = $(str);2120 strictEqual($dom.find('span').text(), 'ãã¤ã³ãå', 'ãã¼ã¿ãã¤ã³ãããã¦ããªããã¨');2121 start();2122 }2123 });2124 });21252126 //=============================2127 // Definition2128 //=============================2129 module('ã³ã¡ã³ããã¥ã¼ã«ãã¤ã³ã', {2130 teardown: function() {2131 clearController();2132 }2133 });21342135 //=============================2136 // Body2137 //=============================2138 test('ã³ã³ããã¼ã©å
ã®viewã§ãªãviewã¤ã³ã¹ã¿ã³ã¹ããã¯ãã¤ã³ãã§ããªããã¨', 2, function() {2139 view.append($fixture, 'comment1');21402141 try {2142 view.bind('h5view#item', {2143 text: 'a',2144 cls: 'testClass'2145 });2146 } catch (e) {2147 strictEqual(e.code, ERR_VIEW.ERR_CODE_BIND_INVALID_TARGET, e.message);2148 }2149 var $span = $fixture.find('span');2150 strictEqual($span.length, 0, 'ã³ã¡ã³ããã¥ã¼ã¯å±éããã¦ããªããã¨');2151 });21522153 asyncTest('ã³ã¡ã³ããã¥ã¼ã«ãã¤ã³ãã§ãããã¨', function() {2154 view.append($fixture, 'comment1');21552156 h5.core.controller($fixture, {2157 __name: 'TestController',2158 __ready: function() {2159 this.view.bind('h5view#item', {2160 text: 'a',2161 cls: 'testClass'2162 });21632164 var $span = $fixture.find('span');2165 strictEqual($span.text(), 'a', 'ã³ã¡ã³ããã¥ã¼ã«ãã¤ã³ãããã¦ãããã¨');2166 strictEqual($span.attr('class'), 'testClass', 'ã³ã¡ã³ããã¥ã¼ã«ãã¤ã³ãããã¦ãããã¨');2167 start();2168 }2169 });2170 });21712172 asyncTest('ã³ã¡ã³ããã¥ã¼ã«ObservableItemããã¤ã³ã', 2, function() {21732174 view.append($fixture, 'comment2');2175 var item = h5.core.data.createObservableItem({2176 v1: null,2177 v2: null,2178 item: null2179 });2180 item.set({2181 v1: 'a',2182 v2: 'b',2183 item: {2184 v1: 'aa',2185 v2: 'bb'2186 }2187 });21882189 var c = h5.core.controller($fixture, {2190 __name: 'TestController'2191 });21922193 c.readyPromise.done(function() {2194 c.view.bind('h5view#item', item);21952196 checkTexts(['a', 'b', 'aa', 'bb'], 'ã³ã¡ã³ããã¥ã¼ã«æ¸ããç®æã«ãã¤ã³ãããã¦ãããã¨', 'span');21972198 //å¤ã®å¤æ´2199 item.set({2200 v1: 'aaa',2201 v2: 'bbb'2202 });22032204 checkTexts(['aaa', 'bbb', 'aa', 'bb'], 'å¤æ´ãåæ ããããã¨', 'span');2205 start();2206 });2207 });22082209 asyncTest('ã³ã¡ã³ããã¥ã¼ã«é
åããã¤ã³ã', function() {2210 view.append($fixture, 'comment3');22112212 var item = h5.core.data.createObservableItem({2213 test: null2214 });22152216 item.set('test', 'c');22172218 var items = [{2219 test: 'a'2220 }, {2221 test: 'b'2222 }, item];22232224 var c = h5.core.controller($fixture, {2225 __name: 'TestController'2226 });22272228 c.readyPromise.done(function() {2229 c.view.bind('h5view#item', {2230 items: items2231 });22322233 checkTexts(['a', 'b', 'c'], 'ã³ã¡ã³ããã¥ã¼ã«æ¸ããç®æã«ãã¤ã³ãããã¦ãããã¨');22342235 //å¤æ´2236 item.set('test', 'cc');2237 checkTexts(['a', 'b', 'cc'], 'é
åå
ã®ObservableItemã®å¤æ´ãåæ ããããã¨');22382239 start();2240 });2241 });224222432244 asyncTest('ã³ã¡ã³ããã¥ã¼ã«ObservableArrayããã¤ã³ã', function() {2245 view.append($fixture, 'comment3');22462247 var item = h5.core.data.createObservableItem({2248 test: null2249 });2250 var items = h5.core.data.createObservableArray();22512252 item.set('test', 'c');22532254 items.copyFrom([{2255 test: 'a'2256 }, {2257 test: 'b'2258 }, item]);22592260 var c = h5.core.controller($fixture, {2261 __name: 'TestController'2262 });22632264 c.readyPromise.done(function() {2265 c.view.bind('h5view#item', {2266 items: items2267 });22682269 checkTexts(['a', 'b', 'c'], 'ã³ã¡ã³ããã¥ã¼ã«æ¸ããç®æã«ãã¤ã³ãããã¦ãããã¨');22702271 //å¤æ´2272 items.shift();2273 checkTexts(['b', 'c'], 'å¤æ´ãåæ ããã¦ãããã¨');22742275 item.set('test', 'cc');2276 checkTexts(['b', 'cc'], 'ObservableArrayå
ã®ObservableItemã®å¤æ´ãåæ ããããã¨');22772278 items.copyFrom([]);2279 strictEqual($('#dataBindTest li').length, 0, '空é
åã«ãªã£ããç¹°ãè¿ãè¦ç´ ããªããªããã¨');22802281 start();2282 });2283 });22842285 asyncTest('inputã¿ã°ã¸ã®ãã¤ã³ãã¯valueã«å¤ãè¨å®ããããã¨', 6, function() {2286 view.append($fixture, 'inputtext1');22872288 var item = h5.core.data.createObservableItem({2289 txt1: null,2290 txt2: null,2291 txt3: null2292 });2293 item.set('txt2', 'hoge2');2294 item.set('txt3', 'hoge3');22952296 var c = h5.core.controller($fixture, {2297 __name: 'TestController'2298 });22992300 c.readyPromise.done(function() {2301 c.view.bind('h5view#item', {2302 items: item2303 });23042305 equal($('#txt2').val(), 'hoge2', 'valueã«å¤ãè¨å®ããã¦ãããã¨ã');2306 equal($('#txt3').val(), 'hoge3', 'valueã«å¤ãè¨å®ããã¦ãããã¨ãattr(value)æå®');2307 equal($('#txt2').text(), '', 'ããã¹ããã¼ãã«ã¯ä½ãè¨å®ããã¦ããªããã¨ã');2308 equal($('#txt3').text(), '', 'ããã¹ããã¼ãã«ã¯ä½ãè¨å®ããã¦ããªããã¨ãâ»attr(value)æå®');23092310 $('#txt2')[0].value = 'ã¦ã¼ã¶ã¼å
¥å';2311 $('#txt3')[0].value = 'ã¦ã¼ã¶ã¼å
¥å';2312 item.set('txt2', 'fuga2');2313 item.set('txt3', 'fuga3');2314 equal($('#txt2').val(), 'fuga2',2315 'ã¦ã¼ã¶å
¥åããã£ãå¾(valueã®å¤æ´å¾)ã§ãããã¤ã³ãããã¦ããå¤ãæ´æ°ãããã¨valueãæ´æ°ããããã¨');2316 equal($('#txt3').val(), 'fuga3',2317 'ã¦ã¼ã¶å
¥åããã£ãå¾(valueã®å¤æ´å¾)ã§ãããã¤ã³ãããã¦ããå¤ãæ´æ°ãããã¨valueãæ´æ°ãããã㨠â»attr(value)æå®');2318 start();2319 });2320 });23212322 asyncTest('inputã¿ã°ã¸nullããã¤ã³ããã', 5, function() {2323 view.append($fixture, 'inputtext1');23242325 var items = {2326 txt1: null,2327 txt2: null,2328 txt3: null2329 };23302331 var c = h5.core.controller($fixture, {2332 __name: 'TestController'2333 });23342335 c.readyPromise.done(function() {2336 c.view.bind('h5view#item', {2337 items: items2338 });23392340 equal($('#txt1').val(), '', 'valueå±æ§ã«å¤ãè¨å®ããã¦ãããã¨ã');2341 equal($('#txt2').val(), '', 'valueå±æ§ã«å¤ãè¨å®ããã¦ãããã¨ã');2342 equal($('#txt3').val(), '', 'valueå±æ§ã«å¤ãè¨å®ããã¦ãããã¨ã');2343 equal($('#txt1').text(), '', 'ããã¹ããã¼ãã«ã¯ä½ãè¨å®ããã¦ããªããã¨ã');2344 equal($('#txt2').text(), '', 'ããã¹ããã¼ãã«ã¯ä½ãè¨å®ããã¦ããªããã¨ã');2345 start();2346 });2347 });23482349 asyncTest('input[type="checkbox"]ã®checkedããããã£ã«å¤ãè¨å®ããããã¨', 2, function() {2350 view.append($fixture, 'inputcheck1');23512352 var items = {2353 check1: 'checked',2354 check2: 'checked'2355 };23562357 var c = h5.core.controller($fixture, {2358 __name: 'TestController'2359 });23602361 c.readyPromise.done(function() {2362 c.view.bind('h5view#item', {2363 items: items2364 });23652366 equal($('#txt1').attr('checked'), items.check1, 'valueå±æ§ã«å¤ãè¨å®ããã¦ãããã¨ã');2367 equal($('#txt2').attr('checked'), items.check2, 'valueå±æ§ã«å¤ãè¨å®ããã¦ãããã¨ã');2368 start();2369 });2370 });23712372 asyncTest('ãã¹ãããã³ã³ããã¹ãã«å®ç¾©ãããinput[type="checkbox"]ã®checkedããããã£ã«å¤ãè¨å®ããããã¨', 2, function() {2373 view.append($fixture, 'inputcheck2');23742375 var items = {2376 check1: 'checked',2377 items2: {2378 check2: 'checked'2379 }2380 };23812382 var c = h5.core.controller($fixture, {2383 __name: 'TestController'2384 });23852386 c.readyPromise.done(function() {2387 c.view.bind('h5view#item', {2388 items: items2389 });23902391 equal($('#txt1').attr('checked'), items.check1, 'valueå±æ§ã«å¤ãè¨å®ããã¦ãããã¨ã');2392 equal($('#txt2').attr('checked'), items.check2, 'valueå±æ§ã«å¤ãè¨å®ããã¦ãããã¨ã');2393 start();2394 });2395 });23962397 //=============================2398 // Definition2399 //=============================2400 module('loop-contextã³ã³ããã¹ãã®ãã¹ã');24012402 //=============================2403 // Body2404 //=============================2405 test('loop-contextã®åè¦ç´ ã«loop-contextãããè¦ç´ ã«é
åããã¤ã³ããã', function() {2406 var ar = [{2407 ar: [{2408 val: 12409 }, {2410 val: 22411 }, {2412 val: 32413 }]2414 }];24152416 view.append($fixture, 'nestloop1');2417 view.bind($('#dataBindTest'), {2418 items: ar2419 });242024212422 checkTexts(['1', '2', '3'], 'ãã¤ã³ãããã¦ãããã¨', 'span');2423 });24242425 test('loop-contextã®åè¦ç´ ã«loop-contextãããè¦ç´ ã«nullãå«ã¾ãã¦ããé
åããã¤ã³ããã', function() {2426 var ar = [{2427 ar: [{2428 val: 12429 }, null, {2430 val: 32431 }]2432 }];24332434 view.append($fixture, 'nestloop1');2435 view.bind($('#dataBindTest'), {2436 items: ar2437 });24382439 checkTexts(['1', '', '3'], 'ãã¤ã³ãããã¦ãããã¨', 'span');2440 });24412442 test('loop-contextã®åè¦ç´ ã«è¤æ°loop-contextãããè¦ç´ ã«é
åããã¤ã³ããã', function() {2443 var ar = [{2444 ar: [{2445 val: 12446 }, {2447 val: 22448 }, {2449 val: 32450 }],2451 ar2: [{2452 val: 102453 }, {2454 val: 202455 }, {2456 val: 302457 }]24582459 }];24602461 view.append($fixture, 'nestloop2');2462 view.bind($('#dataBindTest'), {2463 items: ar2464 });246524662467 checkTexts(['1', '2', '3', '10', '20', '30'], 'ãã¤ã³ãããã¦ãããã¨', 'span');2468 });24692470 test('loop-contextã®åè¦ç´ ã«è¤æ°loop-contextãããè¦ç´ ã«nullãå«ã¾ãã¦ããé
åããã¤ã³ããã', function() {2471 var ar = [{2472 ar: [{2473 val: 12474 }, {2475 val: 22476 }, {2477 val: 32478 }],2479 ar2: [{2480 val: 102481 }, {2482 val: 202483 }, {2484 val: 302485 }]2486 }, {2487 ar: null,2488 ar2: [{2489 val: 1002490 }, {2491 val: 2002492 }, {2493 val: 3002494 }]2495 }];24962497 view.append($fixture, 'nestloop2');2498 view.bind($('#dataBindTest'), {2499 items: ar2500 });25012502 checkTexts(['1', '2', '3', '10', '20', '30', '100', '200', '300'], 'ãã¤ã³ãããã¦ãããã¨', 'span');2503 });25042505 test('loop-contextã®åè¦ç´ ã«loop-contextãããè¦ç´ ã«ObservableArrayããã¤ã³ããã', function() {2506 var ar = [{2507 ar: [{2508 val: 12509 }, {2510 val: 22511 }, {2512 val: 32513 }]2514 }];2515 var oar = h5.core.data.createObservableArray();2516 oar.copyFrom(ar);25172518 view.append($fixture, 'nestloop1');2519 view.bind($('#dataBindTest'), {2520 items: oar2521 });252225232524 checkTexts(['1', '2', '3'], 'ãã¤ã³ãããã¦ãããã¨', 'span');2525 });25262527 test('loop-contextã®åè¦ç´ ã«loop-contextãããè¦ç´ ã«nullãå«ã¾ãã¦ããObservableArrayããã¤ã³ããã', function() {2528 var ar = [{2529 ar: [{2530 val: 12531 }, null, {2532 val: 32533 }]2534 }];2535 var oar = h5.core.data.createObservableArray();2536 oar.copyFrom(ar);25372538 view.append($fixture, 'nestloop1');2539 view.bind($('#dataBindTest'), {2540 items: oar2541 });25422543 checkTexts(['1', '', '3'], 'ãã¤ã³ãããã¦ãããã¨', 'span');2544 });25452546 test('loop-contextã®åè¦ç´ ã«è¤æ°loop-contextãããè¦ç´ ã«nullãå«ã¾ãã¦ããObservableArrayããã¤ã³ããã', function() {2547 var ar = [{2548 ar: [{2549 val: 12550 }, {2551 val: 22552 }, {2553 val: 32554 }],2555 ar2: [{2556 val: 102557 }, {2558 val: 202559 }, {2560 val: 302561 }]2562 }, {2563 ar: null,2564 ar2: [{2565 val: 1002566 }, {2567 val: 2002568 }, {2569 val: 3002570 }]2571 }];25722573 var oar = h5.core.data.createObservableArray();2574 oar.copyFrom(ar);25752576 view.append($fixture, 'nestloop2');2577 view.bind($('#dataBindTest'), {2578 items: oar2579 });25802581 checkTexts(['1', '2', '3', '10', '20', '30', '100', '200', '300'], 'ãã¤ã³ãããã¦ãããã¨', 'span');2582 });25832584 //=============================2585 // Definition2586 //=============================2587 module('unbind', {2588 teardown: function() {2589 clearController();2590 }2591 });25922593 //=============================2594 // Body2595 //=============================2596 test('DataItemããã¤ã³ãå¾ãunbind()ãå®è¡ãã', function() {2597 var schema = {2598 id: {2599 id: true2600 },2601 test: {2602 type: 'string',2603 defaultValue: 'abc'2604 }2605 };2606 var manager = h5.core.data.createManager('TestManager');2607 var model = manager.createModel({2608 name: 'TestModel',2609 schema: schema2610 });2611 var dataItem = model.create({2612 id: '1'2613 });26142615 view.append($fixture, 'itemBind8');2616 var binding = view.bind($('#dataBindTest'), {2617 item: dataItem2618 });26192620 equal($('#dataBindTest span').text(), 'abc', 'strããããã£ã®defaultValueããã¥ã¼ã«åæ ããã¦ãããã¨');26212622 var ctx = $('[' + DATA_H5_BIND + '],[' + DATA_H5_CONTEXT + '],[' + DATA_H5_LOOP_CONTEXT2623 + ']', '#dataBindTest').length;26242625 binding.unbind();26262627 equal($('[' + DATA_H5_BIND + '],[' + DATA_H5_CONTEXT + '],[' + DATA_H5_LOOP_CONTEXT + ']',2628 '#dataBindTest').length, ctx, 'data-h5-bind, context, loop-contextã¯åé¤ããã¦ããªããã¨');2629 equal($('[' + DATA_H5_DYN_CTX + '],[' + DATA_H5_DYN_VID + '],[' + DATA_H5_DYN_BIND_ROOT2630 + '],[' + DATA_H5_DYN_CN + ']', '#dataBindTest').length, 0,2631 'data-h5-dyn-*å±æ§ãå
¨ã¦åé¤ããã¦ãããã¨');26322633 dataItem.set({2634 test: 'AAAA'2635 });26362637 equal($('#dataBindTest span').text(), 'abc', 'unbindå¾ã«DataItemãå¤æ´ãã¦ãããã¥ã¼ã¯å¤æ´ãããªããã¨');2638 });26392640 test('ObservableItemããã¤ã³ãå¾ãunbind()ãå®è¡ãã', function() {2641 var schema = {2642 id: {2643 id: true2644 },2645 test: {2646 type: 'string',2647 defaultValue: 'abc'2648 }2649 };2650 var obsItem = h5.core.data.createObservableItem(schema);26512652 view.append($fixture, 'itemBind8');2653 var binding = view.bind($('#dataBindTest'), {2654 item: obsItem2655 });26562657 equal($('#dataBindTest span').text(), 'abc', 'strããããã£ã®defaultValueããã¥ã¼ã«åæ ããã¦ãããã¨');26582659 var ctx = $('[' + DATA_H5_BIND + '],[' + DATA_H5_CONTEXT + '],[' + DATA_H5_LOOP_CONTEXT2660 + ']', '#dataBindTest').length;26612662 binding.unbind();26632664 equal($('[' + DATA_H5_BIND + '],[' + DATA_H5_CONTEXT + '],[' + DATA_H5_LOOP_CONTEXT + ']',2665 '#dataBindTest').length, ctx, 'data-h5-bind, context, loop-contextã¯åé¤ããã¦ããªããã¨');2666 equal($('[' + DATA_H5_DYN_CTX + '],[' + DATA_H5_DYN_VID + '],[' + DATA_H5_DYN_BIND_ROOT2667 + '],[' + DATA_H5_DYN_CN + ']', '#dataBindTest').length, 0,2668 'data-h5-dyn-*å±æ§ãå
¨ã¦åé¤ããã¦ãããã¨');26692670 obsItem.set({2671 test: 'AAAA'2672 });26732674 equal($('#dataBindTest span').text(), 'abc', 'unbindå¾ã«DataItemãå¤æ´ãã¦ãããã¥ã¼ã¯å¤æ´ãããªããã¨');2675 });26762677 test('ObservableArrayããã¤ã³ãå¾ãunbind()ãå®è¡ãã',2678 function() {2679 var oar = h5.core.data.createObservableArray();2680 oar.copyFrom([{2681 test: 12682 }, {2683 test: 22684 }, {2685 test: 32686 }]);26872688 view.append($fixture, 'itemBind7');2689 var binding = view.bind($('#dataBindTest'), {2690 item: {2691 ary: oar2692 }2693 });26942695 checkTexts(['1', '2', '3'], 'ObservableArrayã®å
容ããã¥ã¼ã«è¡¨ç¤ºããã¦ãããã¨', 'span');26962697 var ctx = $('[' + DATA_H5_BIND + '],[' + DATA_H5_CONTEXT + '],['2698 + DATA_H5_LOOP_CONTEXT + ']', '#dataBindTest').length;26992700 binding.unbind();27012702 equal($('[' + DATA_H5_BIND + '],[' + DATA_H5_CONTEXT + '],[' + DATA_H5_LOOP_CONTEXT2703 + ']', '#dataBindTest').length, ctx,2704 'data-h5-bind, context, loop-contextã¯åé¤ããã¦ããªããã¨');2705 equal(2706 $('[' + DATA_H5_DYN_CTX + '],[' + DATA_H5_DYN_VID + '],['2707 + DATA_H5_DYN_BIND_ROOT + '],[' + DATA_H5_DYN_CN + ']',2708 '#dataBindTest').length, 0, 'data-h5-dyn-*å±æ§ãå
¨ã¦åé¤ããã¦ãããã¨');27092710 oar.push({2711 test: 10002712 });2713 checkTexts(['1', '2', '3'], 'push: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨',2714 'span');27152716 oar.splice(1, 1, {2717 test: 102718 });2719 checkTexts(['1', '2', '3'], 'splice: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨',2720 'span');27212722 oar.pop();2723 checkTexts(['1', '2', '3'], 'pop: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨',2724 'span');27252726 oar.copyFrom([{2727 test: 10002728 }, {2729 test: 20002730 }, {2731 test: 30002732 }]);27332734 checkTexts(['1', '2', '3'],2735 'copyFrom: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨', 'span');27362737 oar.shift();27382739 checkTexts(['1', '2', '3'], 'shift: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨',2740 'span');27412742 oar.unshift({2743 test: 4442744 });27452746 checkTexts(['1', '2', '3'],2747 'unshift: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨', 'span');27482749 oar.sort();27502751 checkTexts(['1', '2', '3'], 'sort: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨',2752 'span');27532754 oar.reverse();27552756 checkTexts(['1', '2', '3'],2757 'reverse: unbindå¾ã«ObservableArrayã®å
容ãå¤æ´ãã¦ããã¥ã¼ã«åæ ãããªããã¨', 'span');2758 });27592760 test('è¤æ°è¦ç´ ã«ObservableArray[ObseItem]ããã¤ã³ããunbind()ãå®è¡', 8, function() {2761 var $el1 = $('<div data-h5-loop-context="data"></div>');2762 $el1.append('<div data-h5-bind="str"></div>');2763 $fixture.append($el1);2764 var $el2 = $('<div data-h5-loop-context="data"></div>');2765 $el2.append('<div data-h5-bind="str"></div>');2766 $fixture.append($el2);27672768 try {2769 var ar = h5.core.data.createObservableArray();2770 var data = {
...
script.js
Source:script.js
1//è¦ç´ ã®åå¾2const wrap = document.getElementById('wrap');3const start = document.getElementById('start');4//è¤æ°ã®ããã¹ããæ ¼ç´æ°ããé
å5const textLists = [6 'Hello World','This is my App','How are you?',7 'Today is sunny','I love JavaScript!','Good morning',8 'I am Japanese','Let it be','Samurai',9 'Typing Game','Information Technology',10 'I want to be a programmer','What day is today?',11 'I want to build a web app','Nice to meet you',12 'Chrome Firefox Edge Safari','machine learning',13 'Brendan Eich','John Resig','React Vue Angular',14 'Netscape Communications','undefined null NaN',15 'Thank you very much','Google Apple Facebook Amazon',16 'ECMAScript','console.log','for while if switch',17 'var let const','Windows Mac Linux iOS Android',18 'programming'19 ];20//ã©ã³ãã ãªããã¹ããç»é¢ã«è¡¨ç¤ºãã21let checkTexts = [];22const createText = () => {23 const p = document.getElementById('text');24 const rnd = Math.floor(Math.random() * textLists.length);25 //pè¦ç´ ã®ä¸èº«ã空ã£ã½ã«ãã26 p.textContent = '';27 //textLists[rnd].split('').map( string => {28 checkTexts = textLists[rnd].split('').map( string => {29 //spanè¦ç´ ãä½ã30 const span = document.createElement('span');31 //spanè¦ç´ ã®é
åã«ï¼æåãã¤å²ãå½ã¦ã32 span.textContent = string;33 //spanè¦ç´ ãpè¦ç´ ã«è¿½å ãã¦ãã34 p.appendChild(span);35 //p.appendChild(string);36 37 //1æåãã¤checkTextsã«æ ¼ç´ãã¦ãã38 return span;39 40 })41};42//ã¹ã³ã¢ã®åæå¤ãè¨å®43let score = 0;44//ãã¼ã¤ãã³ãï¼å
¥åå¤å®å¦ç45const keyDown = e => {46 //console.log(e.key);47 //console.log(checkTexts);48 //console.log(checkTexts[0]);49 if( e.key === checkTexts[0].textContent){50 wrap.style.backgroundColor = '#666';51 //checkTextsã®è¦ç´ ã«add-colorã¯ã©ã¹ãä»ä¸ãã52 checkTexts[0].className = 'add-color';53 //é
åããï¼æååé¤54 checkTexts.shift();55 score ++;56 //æå¾ã¾ã§å
¥åããããæ°ããããã¹ãã表示57 if( !checkTexts.length) createText();58 }else if( e.key === 'Shift'){59 wrap.style.backgroundColor = '#666';60 }else{61 wrap.style.backgroundColor = 'red';62 }63};64//ã©ã³ã¯å¤å®65const rankCheck = rank =>{66 //ããã¹ããæ ¼ç´ããå¤æ°67 let text = '';68 //ã¹ã³ã¢ã«å¿ãã¦ç°ãªãã¡ãã»ã¼ã¸ãå¤æ°textã«æ ¼ç´69 if( score < 100 ){ 70 text = ` Your Rank is C \n ${100 - socre }more to B Rank`;71 }else if( score < 200 ){72 text = `Your Rank is B \n${200-score} more to A Rank`;73 }else if( score < 300 ){74 text = `Your Rank is A \n${300-socre} more to S Rank`;75 }else if( score >= 300){76 text = `Your Rank is S! \n Great Work!`77 }78 return `${score}æåæã¦ã¾ããï¼ \n${text}\n 1.<OK> for Retry / 2.<Cancel> for Exit`;79};80//ã²ã¼ã ã®çµäºå¦ç81const gameOver = id =>{82 clearInterval(id);83 //console.log('Game over');84 //ã¹ã³ã¢ã®å¤ãrankCheck()ã«æ¸¡ã85 const result = confirm(rankCheck(score));86 //okãã¿ã³æ¼ãããããªãã¼ã87 if( result ) window.location.reload();88};89// ã¿ã¤ãã¼å¦ç90const timer = () => {91//ã¿ã¤ãã¼ã®åæå¤ãè¨å®92let time = 60;93 const count = document.getElementById('count');94 const id = setInterval( ()=>{95 //ã«ã¦ã³ã0ã§ã¿ã¤ãã¼åæ¢96 //if( time <= 0 ) clearInterval(id);97 if( time <= 0) gameOver(id);98 //ã«ã¦ã³ããã¦ã³99 count.textContent = time--;100 },1000);101}; 102start.addEventListener('click', ()=>{103 //timeré¢æ°104 timer();105 createText();106 //ã¹ã¿ã¼ããã¿ã³ãé表示ã«107 start.style.display = 'none';108 document.addEventListener( 'keydown', keyDown);...
game.js
Source:game.js
1//get html2const wrap = document.getElementById('wrap');3const start = document.getElementById('start');4const textLists = [5 'Hello World','This is my App','How are you?',6 'Today is sunny','I love JavaScript!','Good morning',7 'I am Japanese','Let it be','Samurai',8 'Typing Game','Information Technology',9 'I want to be a programmer','What day is today?',10 'I want to build a web app','Nice to meet you',11 'Chrome Firefox Edge Safari','machine learning',12 'Brendan Eich','John Resig','React Vue Angular',13 'Netscape Communications','undefined null NaN',14 'Thank you very much','Google Apple Facebook Amazon',15 'ECMAScript','console.log','for while if switch',16 'var let const','Windows Mac Linux iOS Android',17 'programming'18 19 ]; //text20 21let checkTexts = [];22const createText = () => {23 const p = document.getElementById('text');24 //random 25 const rnd = Math.floor(Math.random() * textLists.length);26 27 //p clean28 p.textContent = '';29 30 checkTexts = textLists[rnd].split('').map(value => {31 //span create32 const span = document.createElement('span');33 //span split34 span.textContent = value;35 36 //span => p37 p.appendChild(span);38 return span;39 })40 41}; //random text42let score = 0;43const keyDown = e => {44 if(e.key === checkTexts[0].textContent){45 // add-color46 checkTexts[0].className = 'add-color';47 48 // delete 1word49 checkTexts.shift();50 51 //good tp score ++52 score++;53 54 //clear, and new text55 if(!checkTexts.length)createText();56 } 57 // Shiftãã¼ãæ¼ããæã¯è²ãå¤ãããªã58 else if(e.key === 'Shift') {59 wrap.style.backgroundColor = '#666';60 // ã¿ã¤ããã¹ããæã ãèæ¯è²ã赤è²ã«å¤ãã61 } else {62 wrap.style.backgroundColor = 'red';63 }64 65}; //key event &66const rankCheck = score => {67 let text ='';68 //score => text if?69 if(score<100){70 text = `ããªãã®ã©ã³ã¯ã¯Cã§ãã\nBã©ã³ã¯ã¾ã§ãã¨${100 - score}æåã§ãã`;71 } else if(score < 200) {72 text = `ããªãã®ã©ã³ã¯ã¯Bã§ãã\nAã©ã³ã¯ã¾ã§ãã¨${200 - score}æåã§ãã`; 73 } else if(score < 300) {74 text = `ããªãã®ã©ã³ã¯ã¯Aã§ãã\nSã©ã³ã¯ã¾ã§ãã¨${300 - score}æåã§ãã`; 75 } else if(score >= 300) {76 text = `ããªãã®ã©ã³ã¯ã¯Sã§ãã\nããã§ã¨ããããã¾ãï¼`; 77 }78 return `${score}æåæã¦ã¾ãã\n${text}\nãOKããªãã©ã¤ï¼ããã£ã³ã»ã«ãçµäº`;79}; //rank & message80const gameOver = id => {81 //timer stoped82 clearInterval(id)83 const result = confirm(rankCheck(score));84 // OKãã¿ã³ãã¯ãªãã¯ãããããªãã¼ããã85 if(result) window.location.reload();86}; 87const timer = () => {88 //timer default =60sec89 let time = 60;90 91 const count = document.getElementById('count');92 const id = setInterval(() =>{93 //count timer 0 => stop94 if(time <= 0) gameOver(id);95 //1second96 count.textContent = time--;97 98 },1000);99};100start.addEventListener('click', () => {101 timer();102 createText();103 //start é表示104 start.style.display = 'none';105 //keyborad event106 document.addEventListener('keydown', keyDown);...
code.js
Source:code.js
1var p = document.getElementById('text');2//ã¿ã¤ãã³ã°ããæååãããã§ç¨æãã¦ãã3var textLists =[4 'yaju',5 'tono',6 'tadokoro',7 'tadano',8 'miura',9 'kimura',10 'go',11 'daibou satosi',12 'hide',13 'nikutaihaojarumaru',14 'hatano yusuke',15 'tanioka',16 'DRVS',17 'K B S torio',18 'nisioka',19 'siroino',20 'majimekun',21 'aoki',22 'akiyosi',23 'ikusabatasenpai',24 'okayamanohentaikusooyaji'25];26var checkTexts = [];27createText();28function createText() {29 //æååãã©ã³ãã ã«åå¾ãã30 var rnd = Math.floor(Math.random() * textLists.length);31 //åã®æååãåé¤ãã¦ãã次ã®æååã表示ãã32 p.textContent = '';33 //æååã1æåãã¤ã«å解ãã¦ãããããã«spanã¿ã°ãæ¿å
¥ãã34 checkTexts = textLists[rnd].split('').map(function(value) {35 var span = document.createElement('span');36 span.textContent = value;37 p.appendChild(span);38 return span;39 });40}41document.addEventListener('keydown', keyDown);42function keyDown(e) {43 //ãã¼ãã¼ãããã®å
¥åã¯ãe.keyãã«æ ¼ç´ããã¦ãã44 if(e.key === checkTexts[0].textContent) {45 checkTexts[0].className = 'add-blue';46 //0çªç®ã®é
åè¦ç´ ãåé¤ãã¦ã次ã®1æåãæ¯è¼å¯¾è±¡ã«ãã47 checkTexts.shift();48 //é
åè¦ç´ ã空ã£ã½ã«ãªã£ãã次ã®åé¡ãåºã49 if(!checkTexts.length) createText();50 }...
app.js
Source:app.js
1var p = document.getElementById('text');2//ã¿ã¤ãã³ã°ããæååãããã§ç¨æãã¦ãã3var textLists = [4 'Hello World',5 'This is my App',6 'How are you?',7 'Hello Hello',8 'I love JavaScript!',9 'Good morning',10 'I am Japanese',11 'Let it be'12 'aaa'13 'bbbbb'14];15var checkTexts = [];16createText();17function createText() {18 //æååãã©ã³ãã ã«åå¾ãã19 var rnd = Math.floor(Math.random() * textLists.length);20 //åã®æååãåé¤ãã¦ãã次ã®æååã表示ãã21 p.textContent = '';22 //æååã1æåãã¤ã«å解ãã¦ãããããã«spanã¿ã°ãæ¿å
¥ãã23 checkTexts = textLists[rnd].split('').map(function(value) {24 var span = document.createElement('span');25 span.textContent = value;26 p.appendChild(span);27 return span;28 });29}30document.addEventListener('keydown', keyDown);31function keyDown(e) {32 //ãã¼ãã¼ãããã®å
¥åã¯ãe.keyãã«æ ¼ç´ããã¦ãã33 if(e.key === checkTexts[0].textContent) {34 checkTexts[0].className = 'add-blue';35 //0çªç®ã®é
åè¦ç´ ãåé¤ãã¦ã次ã®1æåãæ¯è¼å¯¾è±¡ã«ãã36 checkTexts.shift();37 //é
åè¦ç´ ã空ã£ã½ã«ãªã£ãã次ã®åé¡ãåºã38 if(!checkTexts.length) createText();39 }...
main.js
Source:main.js
1"use script";2{3 const p = document.getElementById("text");4 const textLists = [5 "Hello World",6 "This is my App",7 "How are you?",8 "Hello Hello",9 "I love JavaScript!",10 "Good morning",11 "I am Japanese",12 "Let it be",13 ];14 let checkTexts = [];15 let checkCount = 0;16 let startTime;17 createText();18 function createText() {19 let rnd = Math.floor(Math.random() * textLists.length);20 checkTexts = textLists[rnd].split("").map((value) => {21 let span = document.createElement("span");22 span.textContent = value;23 p.appendChild(span);24 return span;25 });26 }27 document.addEventListener("keydown", (e) => {28 if (checkCount === 3) return;29 if (e.key === checkTexts[0].textContent) {30 if (checkCount === 0) {31 startTime = Date.now();32 }33 checkTexts[0].className = "add-blue";34 checkTexts.shift();35 if (!checkTexts.length) {36 console.log(checkCount);37 checkCount++;38 p.textContent = "";39 if (checkCount === 3) {40 const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(2);41 p.textContent = "Game Finish!!";42 document.getElementById(43 "score"44 ).textContent = `${elapsedTime} Seconds!`;45 return;46 }47 createText();48 }49 }50 });51 function gameResult() {}...
typing.js
Source:typing.js
1var p = document.getElementById('text');2var textLists = [3 'Hello World',4 'Good',5 'I love JavaScript',6 'This is MyApp',7 'Good Night',8 'ããæ¥ã§ãã',9 'ããã«ã¡ã¯',10 'ã«ãã³ä¸ä¸'11];12var checkTexts = [];13createText();14function createTexts(){15 var rnd = Math.floor(Math.random() * textLists.length);16 p.textContent = '';17 checkTexts = textLists[rnd].split('').map(function(value){18 var span = document.createElement('span');19 span.textContent = value;20 p.appendChild(span);21 return span;22 });23}24document.addEventListener('keydown', keyDown);25function keyDown(e) {26 if(e.key === checkTexts[0].textContent) {27 checkTexts[0].className = 'add-blue';28 checkTexts.shift();29 if(!checkTexts.length) createText();30 }...
index.js
Source:index.js
1var p = document.getElementById('text');2var textLists = [3 'Hello World',4 'This is my App',5 'How are you?',6 'Hello Hello'7];8var checkTexts = [];9createText();10function createText(){11 var rnd = Math.floor(Math.random() * textLists.length);12 p.textContent = '';13 checkTexts = textLists[rnd].split('').map(function(value){14 var span = document.createElement('span');15 span.textContent = value;16 p.appendChild(span);17 return span18})};19console.log(checkTexts)20document.addEventListener('keydown',keyDown);21function keyDown(e){22 if(e.key === checkTexts[0].textContent){23 checkTexts[0].className = 'add-blue';24 checkTexts.shift();25 if (!checkTexts.length) createText();26 }27 else{28 console.log('ééã');29 };...
Using AI Code Generation
1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5chai.should();6chaiAsPromised.transferPromiseness = wd.transferPromiseness;7describe('Test Appium XCUITest driver', function () {8 this.timeout(300000);9 var driver;10 before(function () {11 driver = wd.promiseChainRemote('localhost', 4723);12 var desiredCaps = {13 };14 return driver.init(desiredCaps);15 });16 after(function () {17 return driver.quit();18 });19 it('should check if text is present', function () {20 return driver.checkTexts('TestApp', 'Text Entry', 'Text Entry');21 });22});
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6 .elementById('SomeTextField')7 .sendKeys('SomeText')8 .elementById('SomeOtherTextField')9 .sendKeys('SomeOtherText')10 .elementById('SomeButton')11 .click()12 .checkTexts('SomeTextField', 'SomeText')13 .checkTexts('SomeOtherTextField', 'SomeOtherText')14 .quit();15commands.checkTexts = async function (elementId, expectedText) {16 let element = this.elementIdMap[elementId];17 let text = await element.text();18 if (text !== expectedText) {19 throw new Error(`Text '${text}' does not match expected text '${expectedText}'`);20 }21};22commands.checkTexts = async function (elementId, expectedText) {23 let element = this.elementIdMap[elementId];24 let text = await element.text();25 if (text !== expectedText) {26 throw new Error(`Text '${text}' does not match expected text '${expectedText}'`);27 }28};29commands.checkTexts = async function (elementId, expectedText) {30 let element = this.elementIdMap[elementId];31 let text = await element.text();32 if (text !== expectedText) {33 throw new Error(`Text '${text}' does not match expected text '${expectedText}'`);34 }35};36commands.checkTexts = async function (elementId, expectedText) {37 let element = this.elementIdMap[elementId];38 let text = await element.text();39 if (text !== expectedText) {40 throw new Error(`Text '${text}' does not match expected text '${expectedText}'`);41 }42};43commands.checkTexts = async function (elementId, expectedText) {
Using AI Code Generation
1driver.checkTexts(['text1', 'text2']);2driver.checkTexts('text1');3driver.checkTexts(/regex/);4driver.checkTexts('text1', 'text2');5driver.checkTexts('text1');6driver.checkTexts(Pattern.compile("regex"));7driver.check_texts(['text1', 'text2'])8driver.check_texts('text1')9driver.check_texts(re.compile('regex'))10driver.check_texts(['text1', 'text2'])11driver.check_texts('text1')12driver.check_texts(/regex/)13driver.checkTexts(['text1', 'text2']);14driver.checkTexts('text1');15driver.checkTexts(/regex/);16$driver->checkTexts(['text1', 'text2']);17$driver->checkTexts('text1');18$driver->checkTexts('/regex/');19driver.CheckTexts(new[] { "text1", "text2" });20driver.CheckTexts("text1");21driver.CheckTexts(new Regex("regex"));22$driver->checkTexts(['text1', 'text2']);23$driver->checkTexts('text1');24$driver->checkTexts(qr/regex/);25driver.CheckTexts("text1", "text2")26driver.CheckTexts("text1")27driver.CheckTexts("regex")28driver.checkTexts("text1", "text2")29driver.checkTexts("text1")30driver.checkTexts("regex")31driver.checkTexts("text1", "text2")32driver.checkTexts("text1")33driver.checkTexts("regex")34driver.check_texts(&["text1", "text2"]);
Using AI Code Generation
1describe('Test', function() {2 it('should have the right title', function() {3 browser.setImplicitTimeout(5000);4 browser.click('~Accept');5 browser.click('~Continue');6 browser.click('~Continue');
Using AI Code Generation
1describe('My App', () => {2 it('should have welcome screen', () => {3 expect(checkTexts(['Welcome', 'To', 'My', 'App'])).toEqual([true, true, true, true])4 });5});6describe('My App', () => {7 it('should have welcome screen', () => {8 expect(checkTexts(['Welcome', 'To', 'My', 'App'])).toEqual([true, true, true, true])9 });10});11describe('My App', () => {12 it('should have welcome screen', () => {13 expect(checkTexts(['Welcome', 'To', 'My', 'App'])).toEqual([true, true, true, true])14 });15});16describe('My App', () => {17 it('should have welcome screen', () => {18 expect(checkTexts(['Welcome', 'To', 'My', 'App'])).toEqual([true, true, true, true])19 });20});21describe('My App', () => {22 it('should have welcome screen', () => {23 expect(checkTexts(['Welcome', 'To', 'My', 'App'])).toEqual([true, true, true, true])24 });25});26describe('My App', () => {27 it('should have welcome screen', () => {28 expect(checkTexts(['Welcome', 'To', 'My', 'App'])).toEqual([true, true, true, true])29 });30});
Using AI Code Generation
1const wdio = require("webdriverio");2const assert = require("assert");3const caps = {4};5const client = wdio.remote({6});7async function checkTexts() {8 try {9 await client.init();10 await client.pause(5000);11 const isTextPresent = await client.execute("mobile: checkTexts", {12 });13 console.log(isTextPresent);14 assert.strictEqual(isTextPresent, true);15 } catch (err) {16 console.error(err);17 }18}19checkTexts();
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const { XCUITestDriver } = require('appium-xcuitest-driver');5chai.use(chaiAsPromised);6chai.should();7describe('checkTexts', function () {8 let driver;9 let caps = {10 };11 before(async function () {12 driver = await wd.promiseChainRemote('localhost', 4723);13 await driver.init(caps);14 });15 after(async function () {16 await driver.quit();17 });18 it('should find the right element', async function () {19 let text = await driver.execute('mobile: checkTexts', {20 });21 text.should.deep.equal(['Hello', 'World']);22 });23 it('should find the right element using xpath', async function () {24 let text = await driver.execute('mobile: checkTexts', {25 });26 text.should.deep.equal(['Hello', 'World']);27 });28});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!