How to use containsNode method in Playwright Internal

Best JavaScript code snippet using playwright-internal

sel_contain.js

Source:sel_contain.js Github

copy

Full Screen

...125 expect(selection.focusOffset).toBe(2);126 expect(selection.toString()).toBe('AB');127 // containsNode128 if (selection.containsNode) {129 expect(selection.containsNode(span1, true)).toBe(false);130 expect(selection.containsNode(span1, false)).toBe(false);131 }132 // selContainsNode133 expect(selContainsNode(selection, span1, true)).toBe(false);134 expect(selContainsNode(selection, span1, false)).toBe(false);135 // nodeContainsSel136 expect(nodeContainsSel(span1, selection)).toBe(false);137 // Reversed direction138 setSelection(indexEnd, indexStart);139 // Check selection140 selection = ('getSelection' in window ? window : document).getSelection();141 expect(selection.rangeCount).toBe(1);142 if (!IS_TRIDENT) { // Trident doesn't support reversed143 expect(selection.anchorNode).toBe(NODES[0].node);144 expect(selection.anchorOffset).toBe(2);145 expect(selection.focusNode).toBe(NODES[0].node);146 expect(selection.focusOffset).toBe(0);147 }148 expect(selection.toString()).toBe('AB');149 // containsNode150 if (selection.containsNode) {151 expect(selection.containsNode(span1, true)).toBe(false);152 expect(selection.containsNode(span1, false)).toBe(false);153 }154 // selContainsNode155 expect(selContainsNode(selection, span1, true)).toBe(false);156 expect(selContainsNode(selection, span1, false)).toBe(false);157 // nodeContainsSel158 expect(nodeContainsSel(span1, selection)).toBe(false);159 if (IS_GECKO) { // Multiple ranges160 // Add `C`161 addSelection(2, 2);162 selection = ('getSelection' in window ? window : document).getSelection();163 expect(selection.rangeCount).toBe(2);164 expect(selection.getRangeAt(0).toString()).toBe('AB');165 expect(selection.getRangeAt(1).toString()).toBe('C');166 // containsNode167 if (selection.containsNode) {168 expect(selection.containsNode(span1, true)).toBe(false);169 expect(selection.containsNode(span1, false)).toBe(false);170 }171 // selContainsNode172 expect(selContainsNode(selection, span1, true)).toBe(false);173 expect(selContainsNode(selection, span1, false)).toBe(false);174 // nodeContainsSel175 expect(nodeContainsSel(span1, selection)).toBe(false);176 // Add `E`177 setSelection(indexStart, indexEnd);178 addSelection(4, 4);179 selection = ('getSelection' in window ? window : document).getSelection();180 expect(selection.rangeCount).toBe(2);181 expect(selection.getRangeAt(0).toString()).toBe('AB');182 expect(selection.getRangeAt(1).toString()).toBe('E');183 // containsNode184 if (selection.containsNode) {185 expect(selection.containsNode(span1, true)).toBe(true);186 expect(selection.containsNode(span1, false)).toBe(false);187 }188 // selContainsNode189 expect(selContainsNode(selection, span1, true)).toBe(true);190 expect(selContainsNode(selection, span1, false)).toBe(false);191 // nodeContainsSel192 expect(nodeContainsSel(span1, selection)).toBe(false);193 // Add `J`194 setSelection(indexStart, indexEnd);195 addSelection(9, 9);196 selection = ('getSelection' in window ? window : document).getSelection();197 expect(selection.rangeCount).toBe(2);198 expect(selection.getRangeAt(0).toString()).toBe('AB');199 expect(selection.getRangeAt(1).toString()).toBe('J');200 // containsNode201 if (selection.containsNode) {202 expect(selection.containsNode(span1, true)).toBe(false);203 expect(selection.containsNode(span1, false)).toBe(false);204 }205 // selContainsNode206 expect(selContainsNode(selection, span1, true)).toBe(false);207 expect(selContainsNode(selection, span1, false)).toBe(false);208 // nodeContainsSel209 expect(nodeContainsSel(span1, selection)).toBe(false);210 // Add `CDEFGH`211 setSelection(indexStart, indexEnd);212 addSelection(2, 7);213 selection = ('getSelection' in window ? window : document).getSelection();214 expect(selection.rangeCount).toBe(2);215 expect(selection.getRangeAt(0).toString()).toBe('AB');216 expect(selection.getRangeAt(1).toString()).toBe('CDEFGH');217 // containsNode218 if (selection.containsNode) {219 expect(selection.containsNode(span1, true)).toBe(true);220 expect(selection.containsNode(span1, false)).toBe(true);221 }222 // selContainsNode223 expect(selContainsNode(selection, span1, true)).toBe(true);224 expect(selContainsNode(selection, span1, false)).toBe(true);225 // nodeContainsSel226 expect(nodeContainsSel(span1, selection)).toBe(false);227 }228 done();229 });230 it('Select `BC`', function(done) {231 var indexStart = 1,232 indexEnd = 2,233 selection;234 setSelection(indexStart, indexEnd);235 // Check selection236 selection = ('getSelection' in window ? window : document).getSelection();237 expect(selection.rangeCount).toBe(1);238 expect(selection.anchorNode).toBe(NODES[0].node);239 expect(selection.anchorOffset).toBe(1);240 expect(selection.focusNode).toBe(NODES[0].node);241 expect(selection.focusOffset).toBe(3);242 expect(selection.toString()).toBe('BC');243 // containsNode244 if (selection.containsNode) {245 expect(selection.containsNode(span1, true)).toBe(false);246 expect(selection.containsNode(span1, false)).toBe(false);247 }248 // selContainsNode249 expect(selContainsNode(selection, span1, true)).toBe(false);250 expect(selContainsNode(selection, span1, false)).toBe(false);251 // nodeContainsSel252 expect(nodeContainsSel(span1, selection)).toBe(false);253 // Reversed direction254 setSelection(indexEnd, indexStart);255 // Check selection256 selection = ('getSelection' in window ? window : document).getSelection();257 expect(selection.rangeCount).toBe(1);258 if (!IS_TRIDENT) { // Trident doesn't support reversed259 expect(selection.anchorNode).toBe(NODES[0].node);260 expect(selection.anchorOffset).toBe(3);261 expect(selection.focusNode).toBe(NODES[0].node);262 expect(selection.focusOffset).toBe(1);263 }264 expect(selection.toString()).toBe('BC');265 // containsNode266 if (selection.containsNode) {267 expect(selection.containsNode(span1, true)).toBe(false);268 expect(selection.containsNode(span1, false)).toBe(false);269 }270 // selContainsNode271 expect(selContainsNode(selection, span1, true)).toBe(false);272 expect(selContainsNode(selection, span1, false)).toBe(false);273 // nodeContainsSel274 expect(nodeContainsSel(span1, selection)).toBe(false);275 done();276 });277 it('Select `CD`', function(done) {278 var indexStart = 2,279 indexEnd = 3,280 selection;281 setSelection(indexStart, indexEnd);282 // Check selection283 selection = ('getSelection' in window ? window : document).getSelection();284 expect(selection.rangeCount).toBe(1);285 expect(selection.anchorNode).toBe(NODES[0].node);286 expect(selection.anchorOffset).toBe(2);287 expect(selection.focusNode).toBe(NODES[1].node);288 expect(selection.focusOffset).toBe(1);289 expect(selection.toString()).toBe('CD');290 // containsNode291 if (selection.containsNode) {292 expect(selection.containsNode(span1, true)).toBe(true);293 expect(selection.containsNode(span1, false)).toBe(false);294 }295 // selContainsNode296 expect(selContainsNode(selection, span1, true)).toBe(true);297 expect(selContainsNode(selection, span1, false)).toBe(false);298 // nodeContainsSel299 expect(nodeContainsSel(span1, selection)).toBe(false);300 // Reversed direction301 setSelection(indexEnd, indexStart);302 // Check selection303 selection = ('getSelection' in window ? window : document).getSelection();304 expect(selection.rangeCount).toBe(1);305 if (!IS_TRIDENT) { // Trident doesn't support reversed306 expect(selection.anchorNode).toBe(NODES[1].node);307 expect(selection.anchorOffset).toBe(1);308 expect(selection.focusNode).toBe(NODES[0].node);309 expect(selection.focusOffset).toBe(2);310 }311 expect(selection.toString()).toBe('CD');312 // containsNode313 if (selection.containsNode) {314 expect(selection.containsNode(span1, true)).toBe(true);315 expect(selection.containsNode(span1, false)).toBe(false);316 }317 // selContainsNode318 expect(selContainsNode(selection, span1, true)).toBe(true);319 expect(selContainsNode(selection, span1, false)).toBe(false);320 // nodeContainsSel321 expect(nodeContainsSel(span1, selection)).toBe(false);322 if (IS_GECKO) { // Multiple ranges323 // Add `A`324 addSelection(0, 0);325 selection = ('getSelection' in window ? window : document).getSelection();326 expect(selection.rangeCount).toBe(2);327 expect(selection.getRangeAt(0).toString()).toBe('A');328 expect(selection.getRangeAt(1).toString()).toBe('CD');329 // containsNode330 if (selection.containsNode) {331 expect(selection.containsNode(span1, true)).toBe(true);332 expect(selection.containsNode(span1, false)).toBe(false);333 }334 // selContainsNode335 expect(selContainsNode(selection, span1, true)).toBe(true);336 expect(selContainsNode(selection, span1, false)).toBe(false);337 // nodeContainsSel338 expect(nodeContainsSel(span1, selection)).toBe(false);339 // Add `F`340 setSelection(indexStart, indexEnd);341 addSelection(5, 5);342 selection = ('getSelection' in window ? window : document).getSelection();343 expect(selection.rangeCount).toBe(2);344 expect(selection.getRangeAt(0).toString()).toBe('CD');345 expect(selection.getRangeAt(1).toString()).toBe('F');346 // containsNode347 if (selection.containsNode) {348 expect(selection.containsNode(span1, true)).toBe(true);349 expect(selection.containsNode(span1, false)).toBe(false);350 }351 // selContainsNode352 expect(selContainsNode(selection, span1, true)).toBe(true);353 expect(selContainsNode(selection, span1, false)).toBe(false);354 // nodeContainsSel355 expect(nodeContainsSel(span1, selection)).toBe(false);356 // Add `J`357 setSelection(indexStart, indexEnd);358 addSelection(9, 9);359 selection = ('getSelection' in window ? window : document).getSelection();360 expect(selection.rangeCount).toBe(2);361 expect(selection.getRangeAt(0).toString()).toBe('CD');362 expect(selection.getRangeAt(1).toString()).toBe('J');363 // containsNode364 if (selection.containsNode) {365 expect(selection.containsNode(span1, true)).toBe(true);366 expect(selection.containsNode(span1, false)).toBe(false);367 }368 // selContainsNode369 expect(selContainsNode(selection, span1, true)).toBe(true);370 expect(selContainsNode(selection, span1, false)).toBe(false);371 // nodeContainsSel372 expect(nodeContainsSel(span1, selection)).toBe(false);373 }374 done();375 });376 it('Select `DE`', function(done) {377 var indexStart = 3,378 indexEnd = 4,379 selection;380 setSelection(indexStart, indexEnd);381 // Check selection382 selection = ('getSelection' in window ? window : document).getSelection();383 expect(selection.rangeCount).toBe(1);384 if (IS_TRIDENT) { // Trident changes points385 expect(selection.anchorNode).toBe(NODES[0].node);386 expect(selection.anchorOffset).toBe(3);387 } else {388 expect(selection.anchorNode).toBe(NODES[1].node);389 expect(selection.anchorOffset).toBe(0);390 }391 expect(selection.focusNode).toBe(NODES[1].node);392 expect(selection.focusOffset).toBe(2);393 expect(selection.toString()).toBe('DE');394 // containsNode395 if (selection.containsNode) {396 expect(selection.containsNode(span1, true)).toBe(true);397 expect(selection.containsNode(span1, false)).toBe(false);398 }399 // selContainsNode400 expect(selContainsNode(selection, span1, true)).toBe(true);401 expect(selContainsNode(selection, span1, false)).toBe(false);402 // nodeContainsSel403 expect(nodeContainsSel(span1, selection)).toBe(!IS_TRIDENT); // Trident changed404 // Reversed direction405 setSelection(indexEnd, indexStart);406 // Check selection407 selection = ('getSelection' in window ? window : document).getSelection();408 expect(selection.rangeCount).toBe(1);409 if (!IS_TRIDENT) { // Trident doesn't support reversed410 expect(selection.anchorNode).toBe(NODES[1].node);411 expect(selection.anchorOffset).toBe(2);412 expect(selection.focusNode).toBe(NODES[1].node);413 expect(selection.focusOffset).toBe(0);414 }415 expect(selection.toString()).toBe('DE');416 // containsNode417 if (selection.containsNode) {418 expect(selection.containsNode(span1, true)).toBe(true);419 expect(selection.containsNode(span1, false)).toBe(false);420 }421 // selContainsNode422 expect(selContainsNode(selection, span1, true)).toBe(true);423 expect(selContainsNode(selection, span1, false)).toBe(false);424 // nodeContainsSel425 expect(nodeContainsSel(span1, selection)).toBe(!IS_TRIDENT); // Trident changed426 if (IS_GECKO) { // Multiple ranges427 // Add `A`428 addSelection(0, 0);429 selection = ('getSelection' in window ? window : document).getSelection();430 expect(selection.rangeCount).toBe(2);431 expect(selection.getRangeAt(0).toString()).toBe('A');432 expect(selection.getRangeAt(1).toString()).toBe('DE');433 // containsNode434 if (selection.containsNode) {435 expect(selection.containsNode(span1, true)).toBe(true);436 expect(selection.containsNode(span1, false)).toBe(false);437 }438 // selContainsNode439 expect(selContainsNode(selection, span1, true)).toBe(true);440 expect(selContainsNode(selection, span1, false)).toBe(false);441 // nodeContainsSel442 expect(nodeContainsSel(span1, selection)).toBe(false);443 // Add `G`444 setSelection(indexStart, indexEnd);445 addSelection(6, 6);446 selection = ('getSelection' in window ? window : document).getSelection();447 expect(selection.rangeCount).toBe(2);448 expect(selection.getRangeAt(0).toString()).toBe('DE');449 expect(selection.getRangeAt(1).toString()).toBe('G');450 // containsNode451 if (selection.containsNode) {452 expect(selection.containsNode(span1, true)).toBe(true);453 expect(selection.containsNode(span1, false)).toBe(false);454 }455 // selContainsNode456 expect(selContainsNode(selection, span1, true)).toBe(true);457 expect(selContainsNode(selection, span1, false)).toBe(false);458 // nodeContainsSel459 expect(nodeContainsSel(span1, selection)).toBe(true);460 // Add `J`461 setSelection(indexStart, indexEnd);462 addSelection(9, 9);463 selection = ('getSelection' in window ? window : document).getSelection();464 expect(selection.rangeCount).toBe(2);465 expect(selection.getRangeAt(0).toString()).toBe('DE');466 expect(selection.getRangeAt(1).toString()).toBe('J');467 // containsNode468 if (selection.containsNode) {469 expect(selection.containsNode(span1, true)).toBe(true);470 expect(selection.containsNode(span1, false)).toBe(false);471 }472 // selContainsNode473 expect(selContainsNode(selection, span1, true)).toBe(true);474 expect(selContainsNode(selection, span1, false)).toBe(false);475 // nodeContainsSel476 expect(nodeContainsSel(span1, selection)).toBe(false);477 }478 done();479 });480 it('Select `EF`', function(done) {481 var indexStart = 4,482 indexEnd = 5,483 selection;484 setSelection(indexStart, indexEnd);485 // Check selection486 selection = ('getSelection' in window ? window : document).getSelection();487 expect(selection.rangeCount).toBe(1);488 expect(selection.anchorNode).toBe(NODES[1].node);489 expect(selection.anchorOffset).toBe(1);490 expect(selection.focusNode).toBe(NODES[1].node);491 expect(selection.focusOffset).toBe(3);492 expect(selection.toString()).toBe('EF');493 // containsNode494 if (selection.containsNode) {495 expect(selection.containsNode(span1, true)).toBe(true);496 expect(selection.containsNode(span1, false)).toBe(false);497 }498 // selContainsNode499 expect(selContainsNode(selection, span1, true)).toBe(true);500 expect(selContainsNode(selection, span1, false)).toBe(false);501 // nodeContainsSel502 expect(nodeContainsSel(span1, selection)).toBe(true);503 // Reversed direction504 setSelection(indexEnd, indexStart);505 // Check selection506 selection = ('getSelection' in window ? window : document).getSelection();507 expect(selection.rangeCount).toBe(1);508 if (!IS_TRIDENT) { // Trident doesn't support reversed509 expect(selection.anchorNode).toBe(NODES[1].node);510 expect(selection.anchorOffset).toBe(3);511 expect(selection.focusNode).toBe(NODES[1].node);512 expect(selection.focusOffset).toBe(1);513 }514 expect(selection.toString()).toBe('EF');515 // containsNode516 if (selection.containsNode) {517 expect(selection.containsNode(span1, true)).toBe(true);518 expect(selection.containsNode(span1, false)).toBe(false);519 }520 // selContainsNode521 expect(selContainsNode(selection, span1, true)).toBe(true);522 expect(selContainsNode(selection, span1, false)).toBe(false);523 // nodeContainsSel524 expect(nodeContainsSel(span1, selection)).toBe(true);525 done();526 });527 it('Select `FG`', function(done) {528 var indexStart = 5,529 indexEnd = 6,530 selection;531 setSelection(indexStart, indexEnd);532 // Check selection533 selection = ('getSelection' in window ? window : document).getSelection();534 expect(selection.rangeCount).toBe(1);535 expect(selection.anchorNode).toBe(NODES[1].node);536 expect(selection.anchorOffset).toBe(2);537 expect(selection.focusNode).toBe(NODES[1].node);538 expect(selection.focusOffset).toBe(4);539 expect(selection.toString()).toBe('FG');540 // containsNode541 if (selection.containsNode) {542 expect(selection.containsNode(span1, true)).toBe(true);543 expect(selection.containsNode(span1, false)).toBe(false);544 }545 // selContainsNode546 expect(selContainsNode(selection, span1, true)).toBe(true);547 expect(selContainsNode(selection, span1, false)).toBe(false);548 // nodeContainsSel549 expect(nodeContainsSel(span1, selection)).toBe(true);550 // Reversed direction551 setSelection(indexEnd, indexStart);552 // Check selection553 selection = ('getSelection' in window ? window : document).getSelection();554 expect(selection.rangeCount).toBe(1);555 if (!IS_TRIDENT) { // Trident doesn't support reversed556 expect(selection.anchorNode).toBe(NODES[1].node);557 expect(selection.anchorOffset).toBe(4);558 expect(selection.focusNode).toBe(NODES[1].node);559 expect(selection.focusOffset).toBe(2);560 }561 expect(selection.toString()).toBe('FG');562 // containsNode563 if (selection.containsNode) {564 expect(selection.containsNode(span1, true)).toBe(true);565 expect(selection.containsNode(span1, false)).toBe(false);566 }567 // selContainsNode568 expect(selContainsNode(selection, span1, true)).toBe(true);569 expect(selContainsNode(selection, span1, false)).toBe(false);570 // nodeContainsSel571 expect(nodeContainsSel(span1, selection)).toBe(true);572 done();573 });574 it('Select `GH`', function(done) {575 var indexStart = 6,576 indexEnd = 7,577 selection;578 setSelection(indexStart, indexEnd);579 // Check selection580 selection = ('getSelection' in window ? window : document).getSelection();581 expect(selection.rangeCount).toBe(1);582 expect(selection.anchorNode).toBe(NODES[1].node);583 expect(selection.anchorOffset).toBe(3);584 expect(selection.focusNode).toBe(NODES[2].node);585 expect(selection.focusOffset).toBe(1);586 expect(selection.toString()).toBe('GH');587 // containsNode588 if (selection.containsNode) {589 expect(selection.containsNode(span1, true)).toBe(true);590 expect(selection.containsNode(span1, false)).toBe(false);591 }592 // selContainsNode593 expect(selContainsNode(selection, span1, true)).toBe(true);594 expect(selContainsNode(selection, span1, false)).toBe(false);595 // nodeContainsSel596 expect(nodeContainsSel(span1, selection)).toBe(false);597 // Reversed direction598 setSelection(indexEnd, indexStart);599 // Check selection600 selection = ('getSelection' in window ? window : document).getSelection();601 expect(selection.rangeCount).toBe(1);602 if (!IS_TRIDENT) { // Trident doesn't support reversed603 expect(selection.anchorNode).toBe(NODES[2].node);604 expect(selection.anchorOffset).toBe(1);605 expect(selection.focusNode).toBe(NODES[1].node);606 expect(selection.focusOffset).toBe(3);607 }608 expect(selection.toString()).toBe('GH');609 // containsNode610 if (selection.containsNode) {611 expect(selection.containsNode(span1, true)).toBe(true);612 expect(selection.containsNode(span1, false)).toBe(false);613 }614 // selContainsNode615 expect(selContainsNode(selection, span1, true)).toBe(true);616 expect(selContainsNode(selection, span1, false)).toBe(false);617 // nodeContainsSel618 expect(nodeContainsSel(span1, selection)).toBe(false);619 if (IS_GECKO) { // Multiple ranges620 // Add `A`621 addSelection(0, 0);622 selection = ('getSelection' in window ? window : document).getSelection();623 expect(selection.rangeCount).toBe(2);624 expect(selection.getRangeAt(0).toString()).toBe('A');625 expect(selection.getRangeAt(1).toString()).toBe('GH');626 // containsNode627 if (selection.containsNode) {628 expect(selection.containsNode(span1, true)).toBe(true);629 expect(selection.containsNode(span1, false)).toBe(false);630 }631 // selContainsNode632 expect(selContainsNode(selection, span1, true)).toBe(true);633 expect(selContainsNode(selection, span1, false)).toBe(false);634 // nodeContainsSel635 expect(nodeContainsSel(span1, selection)).toBe(false);636 // Add `E`637 setSelection(indexStart, indexEnd);638 addSelection(4, 4);639 selection = ('getSelection' in window ? window : document).getSelection();640 expect(selection.rangeCount).toBe(2);641 expect(selection.getRangeAt(0).toString()).toBe('E');642 expect(selection.getRangeAt(1).toString()).toBe('GH');643 // containsNode644 if (selection.containsNode) {645 expect(selection.containsNode(span1, true)).toBe(true);646 expect(selection.containsNode(span1, false)).toBe(false);647 }648 // selContainsNode649 expect(selContainsNode(selection, span1, true)).toBe(true);650 expect(selContainsNode(selection, span1, false)).toBe(false);651 // nodeContainsSel652 expect(nodeContainsSel(span1, selection)).toBe(false);653 // Add `J`654 setSelection(indexStart, indexEnd);655 addSelection(9, 9);656 selection = ('getSelection' in window ? window : document).getSelection();657 expect(selection.rangeCount).toBe(2);658 expect(selection.getRangeAt(0).toString()).toBe('GH');659 expect(selection.getRangeAt(1).toString()).toBe('J');660 // containsNode661 if (selection.containsNode) {662 expect(selection.containsNode(span1, true)).toBe(true);663 expect(selection.containsNode(span1, false)).toBe(false);664 }665 // selContainsNode666 expect(selContainsNode(selection, span1, true)).toBe(true);667 expect(selContainsNode(selection, span1, false)).toBe(false);668 // nodeContainsSel669 expect(nodeContainsSel(span1, selection)).toBe(false);670 }671 done();672 });673 it('Select `HI`', function(done) {674 var indexStart = 7,675 indexEnd = 8,676 selection;677 setSelection(indexStart, indexEnd);678 // Check selection679 selection = ('getSelection' in window ? window : document).getSelection();680 expect(selection.rangeCount).toBe(1);681 if (IS_TRIDENT) { // Trident changes points682 expect(selection.anchorNode).toBe(NODES[1].node);683 expect(selection.anchorOffset).toBe(4);684 } else {685 expect(selection.anchorNode).toBe(NODES[2].node);686 expect(selection.anchorOffset).toBe(0);687 }688 expect(selection.focusNode).toBe(NODES[2].node);689 expect(selection.focusOffset).toBe(2);690 expect(selection.toString()).toBe('HI');691 // containsNode692 if (selection.containsNode) {693 expect(selection.containsNode(span1, true)).toBe(false);694 expect(selection.containsNode(span1, false)).toBe(false);695 }696 // selContainsNode697 expect(selContainsNode(selection, span1, true)).toBe(IS_TRIDENT); // Trident changed698 expect(selContainsNode(selection, span1, false)).toBe(false);699 // nodeContainsSel700 expect(nodeContainsSel(span1, selection)).toBe(false);701 // Reversed direction702 setSelection(indexEnd, indexStart);703 // Check selection704 selection = ('getSelection' in window ? window : document).getSelection();705 expect(selection.rangeCount).toBe(1);706 if (!IS_TRIDENT) { // Trident doesn't support reversed707 expect(selection.anchorNode).toBe(NODES[2].node);708 expect(selection.anchorOffset).toBe(2);709 expect(selection.focusNode).toBe(NODES[2].node);710 expect(selection.focusOffset).toBe(0);711 }712 expect(selection.toString()).toBe('HI');713 // containsNode714 if (selection.containsNode) {715 expect(selection.containsNode(span1, true)).toBe(false);716 expect(selection.containsNode(span1, false)).toBe(false);717 }718 // selContainsNode719 expect(selContainsNode(selection, span1, true)).toBe(IS_TRIDENT); // Trident changed720 expect(selContainsNode(selection, span1, false)).toBe(false);721 // nodeContainsSel722 expect(nodeContainsSel(span1, selection)).toBe(false);723 if (IS_GECKO) { // Multiple ranges724 // Add `A`725 addSelection(0, 0);726 selection = ('getSelection' in window ? window : document).getSelection();727 expect(selection.rangeCount).toBe(2);728 expect(selection.getRangeAt(0).toString()).toBe('A');729 expect(selection.getRangeAt(1).toString()).toBe('HI');730 // containsNode731 if (selection.containsNode) {732 expect(selection.containsNode(span1, true)).toBe(false);733 expect(selection.containsNode(span1, false)).toBe(false);734 }735 // selContainsNode736 expect(selContainsNode(selection, span1, true)).toBe(false);737 expect(selContainsNode(selection, span1, false)).toBe(false);738 // nodeContainsSel739 expect(nodeContainsSel(span1, selection)).toBe(false);740 // Add `E`741 setSelection(indexStart, indexEnd);742 addSelection(4, 4);743 selection = ('getSelection' in window ? window : document).getSelection();744 expect(selection.rangeCount).toBe(2);745 expect(selection.getRangeAt(0).toString()).toBe('E');746 expect(selection.getRangeAt(1).toString()).toBe('HI');747 // containsNode748 if (selection.containsNode) {749 expect(selection.containsNode(span1, true)).toBe(true);750 expect(selection.containsNode(span1, false)).toBe(false);751 }752 // selContainsNode753 expect(selContainsNode(selection, span1, true)).toBe(true);754 expect(selContainsNode(selection, span1, false)).toBe(false);755 // nodeContainsSel756 expect(nodeContainsSel(span1, selection)).toBe(false);757 // Add `J`758 setSelection(indexStart, indexEnd);759 addSelection(9, 9);760 selection = ('getSelection' in window ? window : document).getSelection();761 expect(selection.rangeCount).toBe(2);762 expect(selection.getRangeAt(0).toString()).toBe('HI');763 expect(selection.getRangeAt(1).toString()).toBe('J');764 // containsNode765 if (selection.containsNode) {766 expect(selection.containsNode(span1, true)).toBe(false);767 expect(selection.containsNode(span1, false)).toBe(false);768 }769 // selContainsNode770 expect(selContainsNode(selection, span1, true)).toBe(false);771 expect(selContainsNode(selection, span1, false)).toBe(false);772 // nodeContainsSel773 expect(nodeContainsSel(span1, selection)).toBe(false);774 }775 done();776 });777 it('Select `IJ`', function(done) {778 var indexStart = 8,779 indexEnd = 9,780 selection;781 setSelection(indexStart, indexEnd);782 // Check selection783 selection = ('getSelection' in window ? window : document).getSelection();784 expect(selection.rangeCount).toBe(1);785 expect(selection.anchorNode).toBe(NODES[2].node);786 expect(selection.anchorOffset).toBe(1);787 expect(selection.focusNode).toBe(NODES[2].node);788 expect(selection.focusOffset).toBe(3);789 expect(selection.toString()).toBe('IJ');790 // containsNode791 if (selection.containsNode) {792 expect(selection.containsNode(span1, true)).toBe(false);793 expect(selection.containsNode(span1, false)).toBe(false);794 }795 // selContainsNode796 expect(selContainsNode(selection, span1, true)).toBe(false);797 expect(selContainsNode(selection, span1, false)).toBe(false);798 // nodeContainsSel799 expect(nodeContainsSel(span1, selection)).toBe(false);800 // Reversed direction801 setSelection(indexEnd, indexStart);802 // Check selection803 selection = ('getSelection' in window ? window : document).getSelection();804 expect(selection.rangeCount).toBe(1);805 if (!IS_TRIDENT) { // Trident doesn't support reversed806 expect(selection.anchorNode).toBe(NODES[2].node);807 expect(selection.anchorOffset).toBe(3);808 expect(selection.focusNode).toBe(NODES[2].node);809 expect(selection.focusOffset).toBe(1);810 }811 expect(selection.toString()).toBe('IJ');812 // containsNode813 if (selection.containsNode) {814 expect(selection.containsNode(span1, true)).toBe(false);815 expect(selection.containsNode(span1, false)).toBe(false);816 }817 // selContainsNode818 expect(selContainsNode(selection, span1, true)).toBe(false);819 expect(selContainsNode(selection, span1, false)).toBe(false);820 // nodeContainsSel821 expect(nodeContainsSel(span1, selection)).toBe(false);822 done();823 });824 it('Select `DEFG`', function(done) {825 var indexStart = 3,826 indexEnd = 6,827 selection;828 setSelection(indexStart, indexEnd);829 // Check selection830 selection = ('getSelection' in window ? window : document).getSelection();831 expect(selection.rangeCount).toBe(1);832 if (IS_TRIDENT) { // Trident changes points833 expect(selection.anchorNode).toBe(NODES[0].node);834 expect(selection.anchorOffset).toBe(3);835 } else {836 expect(selection.anchorNode).toBe(NODES[1].node);837 expect(selection.anchorOffset).toBe(0);838 }839 expect(selection.focusNode).toBe(NODES[1].node);840 expect(selection.focusOffset).toBe(4);841 expect(selection.toString()).toBe('DEFG');842 // containsNode843 if (selection.containsNode) {844 expect(selection.containsNode(span1, true)).toBe(true);845 expect(selection.containsNode(span1, false)).toBe(false);846 }847 // selContainsNode848 expect(selContainsNode(selection, span1, true)).toBe(true);849 expect(selContainsNode(selection, span1, false)).toBe(false);850 // nodeContainsSel851 expect(nodeContainsSel(span1, selection)).toBe(!IS_TRIDENT); // Trident changed852 // Reversed direction853 setSelection(indexEnd, indexStart);854 // Check selection855 selection = ('getSelection' in window ? window : document).getSelection();856 expect(selection.rangeCount).toBe(1);857 if (!IS_TRIDENT) { // Trident doesn't support reversed858 expect(selection.anchorNode).toBe(NODES[1].node);859 expect(selection.anchorOffset).toBe(4);860 expect(selection.focusNode).toBe(NODES[1].node);861 expect(selection.focusOffset).toBe(0);862 }863 expect(selection.toString()).toBe('DEFG');864 // containsNode865 if (selection.containsNode) {866 expect(selection.containsNode(span1, true)).toBe(true);867 expect(selection.containsNode(span1, false)).toBe(false);868 }869 // selContainsNode870 expect(selContainsNode(selection, span1, true)).toBe(true);871 expect(selContainsNode(selection, span1, false)).toBe(false);872 // nodeContainsSel873 expect(nodeContainsSel(span1, selection)).toBe(!IS_TRIDENT); // Trident changed874 if (IS_GECKO) { // Multiple ranges875 // Add `A`876 addSelection(0, 0);877 selection = ('getSelection' in window ? window : document).getSelection();878 expect(selection.rangeCount).toBe(2);879 expect(selection.getRangeAt(0).toString()).toBe('A');880 expect(selection.getRangeAt(1).toString()).toBe('DEFG');881 // containsNode882 if (selection.containsNode) {883 expect(selection.containsNode(span1, true)).toBe(true);884 expect(selection.containsNode(span1, false)).toBe(false);885 }886 // selContainsNode887 expect(selContainsNode(selection, span1, true)).toBe(true);888 expect(selContainsNode(selection, span1, false)).toBe(false);889 // nodeContainsSel890 expect(nodeContainsSel(span1, selection)).toBe(false);891 // Add `J`892 setSelection(indexStart, indexEnd);893 addSelection(9, 9);894 selection = ('getSelection' in window ? window : document).getSelection();895 expect(selection.rangeCount).toBe(2);896 expect(selection.getRangeAt(0).toString()).toBe('DEFG');897 expect(selection.getRangeAt(1).toString()).toBe('J');898 // containsNode899 if (selection.containsNode) {900 expect(selection.containsNode(span1, true)).toBe(true);901 expect(selection.containsNode(span1, false)).toBe(false);902 }903 // selContainsNode904 expect(selContainsNode(selection, span1, true)).toBe(true);905 expect(selContainsNode(selection, span1, false)).toBe(false);906 // nodeContainsSel907 expect(nodeContainsSel(span1, selection)).toBe(false);908 }909 done();910 });911 it('Select `CDEFG`', function(done) {912 var indexStart = 2,913 indexEnd = 6,914 selection;915 setSelection(indexStart, indexEnd);916 // Check selection917 selection = ('getSelection' in window ? window : document).getSelection();918 expect(selection.rangeCount).toBe(1);919 expect(selection.anchorNode).toBe(NODES[0].node);920 expect(selection.anchorOffset).toBe(2);921 expect(selection.focusNode).toBe(NODES[1].node);922 expect(selection.focusOffset).toBe(4);923 expect(selection.toString()).toBe('CDEFG');924 // containsNode925 if (selection.containsNode) {926 expect(selection.containsNode(span1, true)).toBe(true);927 expect(selection.containsNode(span1, false)).toBe(false);928 }929 // selContainsNode930 expect(selContainsNode(selection, span1, true)).toBe(true);931 expect(selContainsNode(selection, span1, false)).toBe(false);932 // nodeContainsSel933 expect(nodeContainsSel(span1, selection)).toBe(false);934 // Reversed direction935 setSelection(indexEnd, indexStart);936 // Check selection937 selection = ('getSelection' in window ? window : document).getSelection();938 expect(selection.rangeCount).toBe(1);939 if (!IS_TRIDENT) { // Trident doesn't support reversed940 expect(selection.anchorNode).toBe(NODES[1].node);941 expect(selection.anchorOffset).toBe(4);942 expect(selection.focusNode).toBe(NODES[0].node);943 expect(selection.focusOffset).toBe(2);944 }945 expect(selection.toString()).toBe('CDEFG');946 // containsNode947 if (selection.containsNode) {948 expect(selection.containsNode(span1, true)).toBe(true);949 expect(selection.containsNode(span1, false)).toBe(false);950 }951 // selContainsNode952 expect(selContainsNode(selection, span1, true)).toBe(true);953 expect(selContainsNode(selection, span1, false)).toBe(false);954 // nodeContainsSel955 expect(nodeContainsSel(span1, selection)).toBe(false);956 done();957 });958 it('Select `DEFGH`', function(done) {959 var indexStart = 3,960 indexEnd = 7,961 selection;962 setSelection(indexStart, indexEnd);963 // Check selection964 selection = ('getSelection' in window ? window : document).getSelection();965 expect(selection.rangeCount).toBe(1);966 if (IS_TRIDENT) { // Trident changes points967 expect(selection.anchorNode).toBe(NODES[0].node);968 expect(selection.anchorOffset).toBe(3);969 } else {970 expect(selection.anchorNode).toBe(NODES[1].node);971 expect(selection.anchorOffset).toBe(0);972 }973 expect(selection.focusNode).toBe(NODES[2].node);974 expect(selection.focusOffset).toBe(1);975 expect(selection.toString()).toBe('DEFGH');976 // containsNode977 if (selection.containsNode) {978 expect(selection.containsNode(span1, true)).toBe(true);979 expect(selection.containsNode(span1, false)).toBe(false);980 }981 // selContainsNode982 expect(selContainsNode(selection, span1, true)).toBe(true);983 expect(selContainsNode(selection, span1, false)).toBe(IS_TRIDENT); // Trident changed984 // nodeContainsSel985 expect(nodeContainsSel(span1, selection)).toBe(false);986 // Reversed direction987 setSelection(indexEnd, indexStart);988 // Check selection989 selection = ('getSelection' in window ? window : document).getSelection();990 expect(selection.rangeCount).toBe(1);991 if (!IS_TRIDENT) { // Trident doesn't support reversed992 expect(selection.anchorNode).toBe(NODES[2].node);993 expect(selection.anchorOffset).toBe(1);994 expect(selection.focusNode).toBe(NODES[1].node);995 expect(selection.focusOffset).toBe(0);996 }997 expect(selection.toString()).toBe('DEFGH');998 // containsNode999 if (selection.containsNode) {1000 expect(selection.containsNode(span1, true)).toBe(true);1001 expect(selection.containsNode(span1, false)).toBe(false);1002 }1003 // selContainsNode1004 expect(selContainsNode(selection, span1, true)).toBe(true);1005 expect(selContainsNode(selection, span1, false)).toBe(IS_TRIDENT); // Trident changed1006 // nodeContainsSel1007 expect(nodeContainsSel(span1, selection)).toBe(false);1008 done();1009 });1010 it('Select `CDEFGH`', function(done) {1011 var indexStart = 2,1012 indexEnd = 7,1013 selection;1014 setSelection(indexStart, indexEnd);1015 // Check selection1016 selection = ('getSelection' in window ? window : document).getSelection();1017 expect(selection.rangeCount).toBe(1);1018 expect(selection.anchorNode).toBe(NODES[0].node);1019 expect(selection.anchorOffset).toBe(2);1020 expect(selection.focusNode).toBe(NODES[2].node);1021 expect(selection.focusOffset).toBe(1);1022 expect(selection.toString()).toBe('CDEFGH');1023 // containsNode1024 if (selection.containsNode) {1025 expect(selection.containsNode(span1, true)).toBe(true);1026 expect(selection.containsNode(span1, false)).toBe(true);1027 }1028 // selContainsNode1029 expect(selContainsNode(selection, span1, true)).toBe(true);1030 expect(selContainsNode(selection, span1, false)).toBe(true);1031 // nodeContainsSel1032 expect(nodeContainsSel(span1, selection)).toBe(false);1033 // Reversed direction1034 setSelection(indexEnd, indexStart);1035 // Check selection1036 selection = ('getSelection' in window ? window : document).getSelection();1037 expect(selection.rangeCount).toBe(1);1038 if (!IS_TRIDENT) { // Trident doesn't support reversed1039 expect(selection.anchorNode).toBe(NODES[2].node);1040 expect(selection.anchorOffset).toBe(1);1041 expect(selection.focusNode).toBe(NODES[0].node);1042 expect(selection.focusOffset).toBe(2);1043 }1044 expect(selection.toString()).toBe('CDEFGH');1045 // containsNode1046 if (selection.containsNode) {1047 expect(selection.containsNode(span1, true)).toBe(true);1048 expect(selection.containsNode(span1, false)).toBe(true);1049 }1050 // selContainsNode1051 expect(selContainsNode(selection, span1, true)).toBe(true);1052 expect(selContainsNode(selection, span1, false)).toBe(true);1053 // nodeContainsSel1054 expect(nodeContainsSel(span1, selection)).toBe(false);1055 if (IS_GECKO) { // Multiple ranges1056 // Add `A`1057 addSelection(0, 0);1058 selection = ('getSelection' in window ? window : document).getSelection();1059 expect(selection.rangeCount).toBe(2);1060 expect(selection.getRangeAt(0).toString()).toBe('A');1061 expect(selection.getRangeAt(1).toString()).toBe('CDEFGH');1062 // containsNode1063 if (selection.containsNode) {1064 expect(selection.containsNode(span1, true)).toBe(true);1065 expect(selection.containsNode(span1, false)).toBe(true);1066 }1067 // selContainsNode1068 expect(selContainsNode(selection, span1, true)).toBe(true);1069 expect(selContainsNode(selection, span1, false)).toBe(true);1070 // nodeContainsSel1071 expect(nodeContainsSel(span1, selection)).toBe(false);1072 // Add `J`1073 setSelection(indexStart, indexEnd);1074 addSelection(9, 9);1075 selection = ('getSelection' in window ? window : document).getSelection();1076 expect(selection.rangeCount).toBe(2);1077 expect(selection.getRangeAt(0).toString()).toBe('CDEFGH');1078 expect(selection.getRangeAt(1).toString()).toBe('J');1079 // containsNode1080 if (selection.containsNode) {1081 expect(selection.containsNode(span1, true)).toBe(true);1082 expect(selection.containsNode(span1, false)).toBe(true);1083 }1084 // selContainsNode1085 expect(selContainsNode(selection, span1, true)).toBe(true);1086 expect(selContainsNode(selection, span1, false)).toBe(true);1087 // nodeContainsSel1088 expect(nodeContainsSel(span1, selection)).toBe(false);1089 }1090 done();1091 });1092 it('Select `` the right of `B`', function(done) {1093 var indexStart = 2,1094 indexEnd = indexStart,1095 selection;1096 setSelection(indexStart, indexEnd);1097 // Check selection1098 selection = ('getSelection' in window ? window : document).getSelection();1099 selection.collapseToStart();1100 expect(selection.rangeCount).toBe(1);1101 expect(selection.anchorNode).toBe(NODES[0].node);1102 expect(selection.anchorOffset).toBe(2);1103 expect(selection.focusNode).toBe(NODES[0].node);1104 expect(selection.focusOffset).toBe(2);1105 expect(selection.toString()).toBe('');1106 expect(selection.isCollapsed).toBe(true);1107 // containsNode1108 if (selection.containsNode) {1109 expect(selection.containsNode(span1, true)).toBe(false);1110 expect(selection.containsNode(span1, false)).toBe(false);1111 }1112 // selContainsNode1113 expect(selContainsNode(selection, span1, true)).toBe(false);1114 expect(selContainsNode(selection, span1, false)).toBe(false);1115 // nodeContainsSel1116 expect(nodeContainsSel(span1, selection)).toBe(false);1117 done();1118 });1119 it('Select `` the right of `C`', function(done) {1120 var indexStart = 2,1121 indexEnd = indexStart,1122 selection;1123 setSelection(indexStart, indexEnd);1124 // Check selection1125 selection = ('getSelection' in window ? window : document).getSelection();1126 selection.collapseToEnd();1127 expect(selection.rangeCount).toBe(1);1128 expect(selection.anchorNode).toBe(NODES[0].node);1129 expect(selection.anchorOffset).toBe(3);1130 expect(selection.focusNode).toBe(NODES[0].node);1131 expect(selection.focusOffset).toBe(3);1132 expect(selection.toString()).toBe('');1133 expect(selection.isCollapsed).toBe(true);1134 // containsNode1135 if (selection.containsNode) {1136 expect(selection.containsNode(span1, true)).toBe(false);1137 expect(selection.containsNode(span1, false)).toBe(false);1138 }1139 // selContainsNode1140 expect(selContainsNode(selection, span1, true)).toBe(false);1141 expect(selContainsNode(selection, span1, false)).toBe(false);1142 // nodeContainsSel1143 expect(nodeContainsSel(span1, selection)).toBe(false);1144 done();1145 });1146 it('Select `` the left of `D`', function(done) {1147 if (IS_TRIDENT) { done(); return; } // Trident changes points -> right of `C`1148 var indexStart = 3,1149 indexEnd = indexStart,1150 selection;1151 setSelection(indexStart, indexEnd);1152 // Check selection1153 selection = ('getSelection' in window ? window : document).getSelection();1154 selection.collapseToStart();1155 expect(selection.rangeCount).toBe(1);1156 expect(selection.anchorNode).toBe(NODES[1].node);1157 expect(selection.anchorOffset).toBe(0);1158 expect(selection.focusNode).toBe(NODES[1].node);1159 expect(selection.focusOffset).toBe(0);1160 expect(selection.toString()).toBe('');1161 expect(selection.isCollapsed).toBe(true);1162 // containsNode1163 if (selection.containsNode) {1164 expect(selection.containsNode(span1, true)).toBe(!IS_BLINK); // Blink bug1165 expect(selection.containsNode(span1, false)).toBe(false);1166 }1167 // selContainsNode1168 expect(selContainsNode(selection, span1, true)).toBe(true);1169 expect(selContainsNode(selection, span1, false)).toBe(false);1170 // nodeContainsSel1171 expect(nodeContainsSel(span1, selection)).toBe(true);1172 done();1173 });1174 it('Select `` the right of `E`', function(done) {1175 var indexStart = 5,1176 indexEnd = indexStart,1177 selection;1178 setSelection(indexStart, indexEnd);1179 // Check selection1180 selection = ('getSelection' in window ? window : document).getSelection();1181 selection.collapseToStart();1182 expect(selection.rangeCount).toBe(1);1183 expect(selection.anchorNode).toBe(NODES[1].node);1184 expect(selection.anchorOffset).toBe(2);1185 expect(selection.focusNode).toBe(NODES[1].node);1186 expect(selection.focusOffset).toBe(2);1187 expect(selection.toString()).toBe('');1188 expect(selection.isCollapsed).toBe(true);1189 // containsNode1190 if (selection.containsNode) {1191 expect(selection.containsNode(span1, true)).toBe(true);1192 expect(selection.containsNode(span1, false)).toBe(false);1193 }1194 // selContainsNode1195 expect(selContainsNode(selection, span1, true)).toBe(true);1196 expect(selContainsNode(selection, span1, false)).toBe(false);1197 // nodeContainsSel1198 expect(nodeContainsSel(span1, selection)).toBe(true);1199 done();1200 });1201 it('Select `` the right of `G`', function(done) {1202 var indexStart = 6,1203 indexEnd = indexStart,1204 selection;1205 setSelection(indexStart, indexEnd);1206 // Check selection1207 selection = ('getSelection' in window ? window : document).getSelection();1208 selection.collapseToEnd();1209 expect(selection.rangeCount).toBe(1);1210 expect(selection.anchorNode).toBe(NODES[1].node);1211 expect(selection.anchorOffset).toBe(4);1212 expect(selection.focusNode).toBe(NODES[1].node);1213 expect(selection.focusOffset).toBe(4);1214 expect(selection.toString()).toBe('');1215 expect(selection.isCollapsed).toBe(true);1216 // containsNode1217 if (selection.containsNode) {1218 expect(selection.containsNode(span1, true)).toBe(true);1219 expect(selection.containsNode(span1, false)).toBe(false);1220 }1221 // selContainsNode1222 expect(selContainsNode(selection, span1, true)).toBe(true);1223 expect(selContainsNode(selection, span1, false)).toBe(false);1224 // nodeContainsSel1225 expect(nodeContainsSel(span1, selection)).toBe(true);1226 done();1227 });1228 it('Select `` the left of `H`', function(done) {1229 if (IS_TRIDENT) { done(); return; } // Trident changes points -> right of `G`1230 var indexStart = 7,1231 indexEnd = indexStart,1232 selection;1233 setSelection(indexStart, indexEnd);1234 // Check selection1235 selection = ('getSelection' in window ? window : document).getSelection();1236 selection.collapseToStart();1237 expect(selection.rangeCount).toBe(1);1238 expect(selection.anchorNode).toBe(NODES[2].node);1239 expect(selection.anchorOffset).toBe(0);1240 expect(selection.focusNode).toBe(NODES[2].node);1241 expect(selection.focusOffset).toBe(0);1242 expect(selection.toString()).toBe('');1243 expect(selection.isCollapsed).toBe(true);1244 // containsNode1245 if (selection.containsNode) {1246 expect(selection.containsNode(span1, true)).toBe(IS_BLINK); // Blink bug1247 expect(selection.containsNode(span1, false)).toBe(false);1248 }1249 // selContainsNode1250 expect(selContainsNode(selection, span1, true)).toBe(false);1251 expect(selContainsNode(selection, span1, false)).toBe(false);1252 // nodeContainsSel1253 expect(nodeContainsSel(span1, selection)).toBe(false);1254 done();1255 });1256 it('Select `` the right of `H`', function(done) {1257 var indexStart = 7,1258 indexEnd = indexStart,1259 selection;1260 setSelection(indexStart, indexEnd);1261 // Check selection1262 selection = ('getSelection' in window ? window : document).getSelection();1263 selection.collapseToEnd();1264 expect(selection.rangeCount).toBe(1);1265 expect(selection.anchorNode).toBe(NODES[2].node);1266 expect(selection.anchorOffset).toBe(1);1267 expect(selection.focusNode).toBe(NODES[2].node);1268 expect(selection.focusOffset).toBe(1);1269 expect(selection.toString()).toBe('');1270 expect(selection.isCollapsed).toBe(true);1271 // containsNode1272 if (selection.containsNode) {1273 expect(selection.containsNode(span1, true)).toBe(false);1274 expect(selection.containsNode(span1, false)).toBe(false);1275 }1276 // selContainsNode1277 expect(selContainsNode(selection, span1, true)).toBe(false);1278 expect(selContainsNode(selection, span1, false)).toBe(false);1279 // nodeContainsSel1280 expect(nodeContainsSel(span1, selection)).toBe(false);1281 done();1282 });...

Full Screen

Full Screen

ReactScope-test.internal.js

Source:ReactScope-test.internal.js Github

copy

Full Screen

...138 expect(node).toEqual(aRef.current);139 ReactDOM.render(null, container);140 expect(scopeRef.current).toBe(null);141 });142 it('containsNode() works as intended', () => {143 const TestScope = React.unstable_createScope();144 const scopeRef = React.createRef();145 const divRef = React.createRef();146 const spanRef = React.createRef();147 const aRef = React.createRef();148 const outerSpan = React.createRef();149 const emRef = React.createRef();150 function Test({toggle}) {151 return toggle ? (152 <div>153 <span ref={outerSpan}>SPAN</span>154 <TestScope ref={scopeRef}>155 <div ref={divRef}>DIV</div>156 <span ref={spanRef}>SPAN</span>157 <a ref={aRef}>A</a>158 </TestScope>159 <em ref={emRef}>EM</em>160 </div>161 ) : (162 <div>163 <TestScope ref={scopeRef}>164 <a ref={aRef}>A</a>165 <div ref={divRef}>DIV</div>166 <span ref={spanRef}>SPAN</span>167 <em ref={emRef}>EM</em>168 </TestScope>169 <span ref={outerSpan}>SPAN</span>170 </div>171 );172 }173 ReactDOM.render(<Test toggle={true} />, container);174 expect(scopeRef.current.containsNode(divRef.current)).toBe(true);175 expect(scopeRef.current.containsNode(spanRef.current)).toBe(true);176 expect(scopeRef.current.containsNode(aRef.current)).toBe(true);177 expect(scopeRef.current.containsNode(outerSpan.current)).toBe(false);178 expect(scopeRef.current.containsNode(emRef.current)).toBe(false);179 ReactDOM.render(<Test toggle={false} />, container);180 expect(scopeRef.current.containsNode(divRef.current)).toBe(true);181 expect(scopeRef.current.containsNode(spanRef.current)).toBe(true);182 expect(scopeRef.current.containsNode(aRef.current)).toBe(true);183 expect(scopeRef.current.containsNode(outerSpan.current)).toBe(false);184 expect(scopeRef.current.containsNode(emRef.current)).toBe(true);185 ReactDOM.render(<Test toggle={true} />, container);186 expect(scopeRef.current.containsNode(emRef.current)).toBe(false);187 });188 it('scopes support server-side rendering and hydration', () => {189 const TestScope = React.unstable_createScope();190 const ReactDOMServer = require('react-dom/server');191 const scopeRef = React.createRef();192 const divRef = React.createRef();193 const spanRef = React.createRef();194 const aRef = React.createRef();195 function Test({toggle}) {196 return (197 <div>198 <TestScope ref={scopeRef}>199 <div ref={divRef}>DIV</div>200 <span ref={spanRef}>SPAN</span>201 <a ref={aRef}>A</a>202 </TestScope>203 <div>Outside content!</div>204 </div>205 );206 }207 const html = ReactDOMServer.renderToString(<Test />);208 expect(html).toBe(209 '<div data-reactroot=""><div>DIV</div><span>SPAN</span><a>A</a><div>Outside content!</div></div>',210 );211 container.innerHTML = html;212 ReactDOM.hydrate(<Test />, container);213 const testScopeQuery = (type, props) => true;214 const nodes = scopeRef.current.DO_NOT_USE_queryAllNodes(testScopeQuery);215 expect(nodes).toEqual([divRef.current, spanRef.current, aRef.current]);216 });217 it('event responders can be attached to scopes', () => {218 let onKeyDown = jest.fn();219 const TestScope = React.unstable_createScope();220 const ref = React.createRef();221 const useKeyboard = require('react-interactions/events/keyboard')222 .useKeyboard;223 let Component = () => {224 const listener = useKeyboard({225 onKeyDown,226 });227 return (228 <TestScope DEPRECATED_flareListeners={listener}>229 <div ref={ref} />230 </TestScope>231 );232 };233 ReactDOM.render(<Component />, container);234 let target = createEventTarget(ref.current);235 target.keydown({key: 'Q'});236 expect(onKeyDown).toHaveBeenCalledTimes(1);237 onKeyDown = jest.fn();238 Component = () => {239 const listener = useKeyboard({240 onKeyDown,241 });242 return (243 <div>244 <TestScope DEPRECATED_flareListeners={listener}>245 <div ref={ref} />246 </TestScope>247 </div>248 );249 };250 ReactDOM.render(<Component />, container);251 target = createEventTarget(ref.current);252 target.keydown({key: 'Q'});253 expect(onKeyDown).toHaveBeenCalledTimes(1);254 });255 it('getChildContextValues() works as intended', () => {256 const TestContext = React.createContext();257 const TestScope = React.unstable_createScope();258 const scopeRef = React.createRef();259 function Test({toggle}) {260 return toggle ? (261 <TestScope ref={scopeRef}>262 <TestContext.Provider value={1} />263 </TestScope>264 ) : (265 <TestScope ref={scopeRef}>266 <TestContext.Provider value={1} />267 <TestContext.Provider value={2} />268 </TestScope>269 );270 }271 ReactDOM.render(<Test toggle={true} />, container);272 let nodes = scopeRef.current.getChildContextValues(TestContext);273 expect(nodes).toEqual([1]);274 ReactDOM.render(<Test toggle={false} />, container);275 nodes = scopeRef.current.getChildContextValues(TestContext);276 expect(nodes).toEqual([1, 2]);277 ReactDOM.render(null, container);278 expect(scopeRef.current).toBe(null);279 });280 });281 describe('ReactTestRenderer', () => {282 let ReactTestRenderer;283 beforeEach(() => {284 ReactTestRenderer = require('react-test-renderer');285 });286 it('DO_NOT_USE_queryAllNodes() works as intended', () => {287 const testScopeQuery = (type, props) => true;288 const TestScope = React.unstable_createScope();289 const scopeRef = React.createRef();290 const divRef = React.createRef();291 const spanRef = React.createRef();292 const aRef = React.createRef();293 function Test({toggle}) {294 return toggle ? (295 <TestScope ref={scopeRef}>296 <div ref={divRef}>DIV</div>297 <span ref={spanRef}>SPAN</span>298 <a ref={aRef}>A</a>299 </TestScope>300 ) : (301 <TestScope ref={scopeRef}>302 <a ref={aRef}>A</a>303 <div ref={divRef}>DIV</div>304 <span ref={spanRef}>SPAN</span>305 </TestScope>306 );307 }308 const renderer = ReactTestRenderer.create(<Test toggle={true} />, {309 createNodeMock: element => {310 return element;311 },312 });313 let nodes = scopeRef.current.DO_NOT_USE_queryAllNodes(testScopeQuery);314 expect(nodes).toEqual([divRef.current, spanRef.current, aRef.current]);315 renderer.update(<Test toggle={false} />);316 nodes = scopeRef.current.DO_NOT_USE_queryAllNodes(testScopeQuery);317 expect(nodes).toEqual([aRef.current, divRef.current, spanRef.current]);318 });319 it('DO_NOT_USE_queryFirstNode() works as intended', () => {320 const testScopeQuery = (type, props) => true;321 const TestScope = React.unstable_createScope();322 const scopeRef = React.createRef();323 const divRef = React.createRef();324 const spanRef = React.createRef();325 const aRef = React.createRef();326 function Test({toggle}) {327 return toggle ? (328 <TestScope ref={scopeRef}>329 <div ref={divRef}>DIV</div>330 <span ref={spanRef}>SPAN</span>331 <a ref={aRef}>A</a>332 </TestScope>333 ) : (334 <TestScope ref={scopeRef}>335 <a ref={aRef}>A</a>336 <div ref={divRef}>DIV</div>337 <span ref={spanRef}>SPAN</span>338 </TestScope>339 );340 }341 const renderer = ReactTestRenderer.create(<Test toggle={true} />, {342 createNodeMock: element => {343 return element;344 },345 });346 let node = scopeRef.current.DO_NOT_USE_queryFirstNode(testScopeQuery);347 expect(node).toEqual(divRef.current);348 renderer.update(<Test toggle={false} />);349 node = scopeRef.current.DO_NOT_USE_queryFirstNode(testScopeQuery);350 expect(node).toEqual(aRef.current);351 });352 it('containsNode() works as intended', () => {353 const TestScope = React.unstable_createScope();354 const scopeRef = React.createRef();355 const divRef = React.createRef();356 const spanRef = React.createRef();357 const aRef = React.createRef();358 const outerSpan = React.createRef();359 const emRef = React.createRef();360 function Test({toggle}) {361 return toggle ? (362 <div>363 <span ref={outerSpan}>SPAN</span>364 <TestScope ref={scopeRef}>365 <div ref={divRef}>DIV</div>366 <span ref={spanRef}>SPAN</span>367 <a ref={aRef}>A</a>368 </TestScope>369 <em ref={emRef}>EM</em>370 </div>371 ) : (372 <div>373 <TestScope ref={scopeRef}>374 <a ref={aRef}>A</a>375 <div ref={divRef}>DIV</div>376 <span ref={spanRef}>SPAN</span>377 <em ref={emRef}>EM</em>378 </TestScope>379 <span ref={outerSpan}>SPAN</span>380 </div>381 );382 }383 const renderer = ReactTestRenderer.create(<Test toggle={true} />, {384 createNodeMock: element => {385 return element;386 },387 });388 expect(scopeRef.current.containsNode(divRef.current)).toBe(true);389 expect(scopeRef.current.containsNode(spanRef.current)).toBe(true);390 expect(scopeRef.current.containsNode(aRef.current)).toBe(true);391 expect(scopeRef.current.containsNode(outerSpan.current)).toBe(false);392 expect(scopeRef.current.containsNode(emRef.current)).toBe(false);393 renderer.update(<Test toggle={false} />);394 expect(scopeRef.current.containsNode(divRef.current)).toBe(true);395 expect(scopeRef.current.containsNode(spanRef.current)).toBe(true);396 expect(scopeRef.current.containsNode(aRef.current)).toBe(true);397 expect(scopeRef.current.containsNode(outerSpan.current)).toBe(false);398 expect(scopeRef.current.containsNode(emRef.current)).toBe(true);399 renderer.update(<Test toggle={true} />);400 expect(scopeRef.current.containsNode(emRef.current)).toBe(false);401 });402 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('input[name="q"]');7 await page.fill('input[name="q"]', 'playwright');8 await page.waitForSelector('input[value="Google Search"]');9 await page.click('input[value="Google Search"]');10 await page.waitForSelector('text=Playwright is a Node library to automate');11 const elementHandle = await page.$('text=Playwright is a Node library to automate');12 const container = await page.$('div');13 const result = await elementHandle.evaluate( (e, c) => e.containsNode(c), container);14 console.log(result);15 await browser.close();16})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const elementHandle = await page.$('input[name="q"]');7 const boundingBox = await elementHandle.boundingBox();8 const { x, y, width, height } = boundingBox;9 const xCenter = x + width / 2;10 const yCenter = y + height / 2;11 const result = await page._delegate.containsNode(xCenter, yCenter);12 console.log(`Point (${xCenter}, ${yCenter}) is on element: ${result}`);13 await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 const elementHandle = await page.$('input[name="q"]');21 const boundingBox = await elementHandle.boundingBox();22 const { x, y, width, height } = boundingBox;23 const xCenter = x + width / 2;24 const yCenter = y + height / 2;25 const result = await page._delegate.containsNode(xCenter, yCenter);26 console.log(`Point (${xCenter}, ${yCenter}) is on element: ${result}`);27 await browser.close();28})();29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const context = await browser.newContext();33 const page = await context.newPage();34 const elementHandle = await page.$('input[name="q"]');35 const boundingBox = await elementHandle.boundingBox();36 const { x, y, width, height } = boundingBox;37 const xCenter = x + width / 2;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require("playwright");2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const elementHandle = await page.$("text=Get Started");7 const isContained = await page.evaluate((element) => {8 return document.contains(element);9 }, elementHandle);10 console.log(isContained);11 await browser.close();12})();13const { chromium } = require("playwright");14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 const elementHandle = await page.$("text=Get Started");19 const isContained = await page.evaluate((element) => {20 return document.contains(element);21 }, elementHandle);22 console.log(isContained);23 await browser.close();24})();25const { chromium } = require("playwright");26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 const elementHandle = await page.$("text=Get Started");31 const isContained = await page.evaluate((element) => {32 return document.contains(element);33 }, elementHandle);34 console.log(isContained);35 await browser.close();36})();37const { chromium } = require("playwright");38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 const elementHandle = await page.$("text=Get Started");43 const isContained = await page.evaluate((element) => {44 return document.contains(element);45 }, elementHandle);46 console.log(isContained);47 await browser.close();48})();49const { chromium } = require("playwright");50(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const element = await page.$('text=Get started');6 const container = await page.$('text=Playwright');7 const result = await container._page._delegate.containsNode(container._elementHandle, element._elementHandle);8 console.log(result);9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const element = await page.$('text=Get started');6 const element2 = await page.$('text=Documentation');7 console.log(await page.containsNode(element));8 console.log(await page.containsNode(element2));9 await browser.close();10})();11page.containsNode(element)12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const page = await browser.newPage();16 const element = await page.$('text=Get started');17 console.log(await page.containsNode(element));18 await browser.close();19})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const elementHandle = await page.$('text=Get started');6 const element = await elementHandle.asElement();7 const result = await element._page._delegate.containsNode(element._delegate);8 console.log(result);9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { containsNode } = require('playwright/lib/internal/inspectorHelper');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const node = await page.$('input[name="q"]');8 const result = await containsNode(page, node);9 console.log(result);10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const isNodePresent = await page._delegate.containsNode(page._delegate, page._delegate, 'input[name="q"]');6 console.log('isNodePresent: ', isNodePresent);7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium, webkit, firefox } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const elementHandle = await page.$('text="Get started"');7 const containingElementHandle = await page.$('text="Playwright"');8 const isContained = await elementHandle._page._delegate.containsNode(9 );10 await browser.close();11})();12const { chromium, webkit, firefox } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const elementHandle = await page.$('text="Get started"');18 const containingElementHandle = await page.$('text="Playwright"');19 const isContained = await elementHandle._page._delegate.containsNode(20 );21 await browser.close();22})();23const { chromium, webkit, firefox } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 const elementHandle = await page.$('text="Get started"');29 const containingElementHandle = await page.$('text="Playwright"');30 const isContained = await elementHandle._page._delegate.containsNode(

Full Screen

Using AI Code Generation

copy

Full Screen

1How to get the number of requests in Playwright?=> {2 const browser = await chromium.launch();3 const page = await browser.newPage();4 const elementHandle = await page.$('text=Get started');5 const element = await elementHandle.asElement();6 const result = await element._page._delegate.containsNode(element._delegate);7 console.log(result);8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { containsNode } = require('playwright/lib/internal/inspectorHelper');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const node = await page.$('input[name="q"]');8 const result = await containsNode(page, node);9 console.log(result);10})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful