How to use getChildren method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Tree.js

Source:Tree.js Github

copy

Full Screen

...104 icon: "icon c",105 icon2: "icon c2",106 color: "white"107 });108 this.__model.getChildren().push(this.__a, this.__b, this.__c);109 this.__model.getAltChildren().push(this.__c, this.__b, this.__a);110 // create the controller111 this.__controller = new qx.data.controller.Tree(this.__model, this.__tree, "children", "name");112 this.__controller.setIconPath("icon");113 },114 tearDown : function()115 {116 this.__controller = null;117 this.__model = null;118 this.__tree.dispose();119 },120 testRemoveBindingsRecursive: function(){121 // reform the model tree122 this.__model.getChildren().remove(this.__c);123 this.__a.getChildren().push(this.__c);124 var cFolder = this.__tree.getRoot().getChildren()[0].getChildren()[0];125 this.assertNotNull(cFolder, "Third node does not exist");126 this.assertEquals("c", cFolder.getLabel());127 // remove the model node128 this.__a.getChildren().remove(this.__c);129 // check if its disposed and the bindings have been removed130 this.__c.setName("affe");131 this.assertEquals("c", cFolder.getLabel());132 // destroy is async --> wait for it!133 this.wait(100, function() {134 this.assertTrue(cFolder.isDisposed());135 }, this);136 },137 testModelChange: function(){138 // set model to null139 this.__controller.setModel(null);140 // set the same model again (forces the tree to redraw)141 this.__controller.setModel(this.__model);142 var d = new qx.test.TreeNode();143 d.setName("d");144 var model = this.__model;145 // add the new model146 this.wait(100, function() {147 model.getChildren().push(d);148 });149 // d will be disposed by the model150 },151 testFolderCreation: function() {152 // Test if the tree nodes exist153 this.assertNotNull(this.__tree.getRoot(), "Root node does not exist");154 this.assertNotNull(this.__tree.getRoot().getChildren()[0], "First node does not exist");155 this.assertNotNull(this.__tree.getRoot().getChildren()[1], "Second node does not exist");156 this.assertNotNull(this.__tree.getRoot().getChildren()[2], "Third node does not exist");157 },158 testFolderLabelInitial: function() {159 // check the initial Labels160 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");161 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");162 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");163 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");164 },165 testFolderLabelChangeName: function() {166 // change the names167 this.__model.setName("ROOT");168 this.__a.setName("A");169 this.__b.setName("B");170 this.__c.setName("C");171 // check the initial Labels172 this.assertEquals("ROOT", this.__tree.getRoot().getLabel(), "Root node has a wrong name");173 this.assertEquals("A", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");174 this.assertEquals("B", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");175 this.assertEquals("C", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");176 },177 testFolderLabelPropertyChange: function() {178 // change the label path179 this.__controller.setLabelPath("name2");180 // check the initial Labels181 this.assertEquals("root2", this.__tree.getRoot().getLabel(), "Root node has a wrong name");182 this.assertEquals("a2", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");183 this.assertEquals("b2", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");184 this.assertEquals("c2", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");185 },186 testChildPush: function() {187 var d = new qx.test.TreeNode();188 d.setName("d");189 var children = this.__model.getChildren();190 children.push(d);191 // Test if the tree nodes exist192 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");193 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");194 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");195 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");196 this.assertEquals("d", this.__tree.getRoot().getChildren()[3].getLabel(), "New node has a wrong name");197 },198 testChildPop: function() {199 var children = this.__model.getChildren();200 children.pop();201 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");202 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");203 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");204 this.assertUndefined(this.__tree.getRoot().getChildren()[2], "There is still a third node!");205 },206 testChildShift: function() {207 var children = this.__model.getChildren();208 children.shift();209 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");210 this.assertEquals("b", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");211 this.assertEquals("c", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");212 this.assertUndefined(this.__tree.getRoot().getChildren()[2], "There is still a third node!");213 },214 testChildUnshift: function() {215 var d = new qx.test.TreeNode();216 d.setName("d");217 var children = this.__model.getChildren();218 children.unshift(d);219 // Test if the tree nodes exist220 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");221 this.assertEquals("d", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");222 this.assertEquals("a", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");223 this.assertEquals("b", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");224 this.assertEquals("c", this.__tree.getRoot().getChildren()[3].getLabel(), "Fourth node has a wrong name");225 },226 testTreeDeep: function() {227 // remove all children228 this.__model.getChildren().pop();229 this.__model.getChildren().pop();230 this.__model.getChildren().pop();231 // create a staight tree232 // this.__model233 // \234 // this.__a235 // \236 // this.__b237 // \238 // this.__c239 this.__model.getChildren().push(this.__a);240 this.__a.getChildren().push(this.__b);241 this.__b.getChildren().push(this.__c);242 // test for the model243 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");244 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");245 this.assertEquals("b", this.__tree.getRoot().getChildren()[0].getChildren()[0].getLabel(), "Second node has a wrong name");246 this.assertEquals("c", this.__tree.getRoot().getChildren()[0].getChildren()[0].getChildren()[0].getLabel(), "Third node has a wrong name");247 },248 testBig: function() {249 // build up the model instances250 var aa = new qx.test.TreeNode();251 aa.setName("aa");252 var bb = new qx.test.TreeNode();253 bb.setName("bb");254 var cc = new qx.test.TreeNode();255 cc.setName("cc");256 var bbb = new qx.test.TreeNode();257 bbb.setName("bbb");258 var AA = new qx.test.TreeNode();259 AA.setName("AA");260 // tie the model together261 // this.__model262 // / | \263 // this.__a this.__b this.__c264 // / \ | |265 // aa AA bb cc266 // |267 // bbb268 bb.getChildren().push(bbb);269 this.__b.getChildren().push(bb);270 this.__a.getChildren().push(aa, AA);271 this.__c.getChildren().push(cc);272 // check the initial Labels273 // root layer274 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");275 // first layer276 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "a node has a wrong name");277 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "b node has a wrong name");278 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "c node has a wrong name");279 // second layer280 this.assertEquals("aa", this.__tree.getRoot().getChildren()[0].getChildren()[0].getLabel(), "aa node has a wrong name");281 this.assertEquals("AA", this.__tree.getRoot().getChildren()[0].getChildren()[1].getLabel(), "AA node has a wrong name");282 this.assertEquals("bb", this.__tree.getRoot().getChildren()[1].getChildren()[0].getLabel(), "bb node has a wrong name");283 this.assertEquals("cc", this.__tree.getRoot().getChildren()[2].getChildren()[0].getLabel(), "cc node has a wrong name");284 // third layer285 this.assertEquals("bbb", this.__tree.getRoot().getChildren()[1].getChildren()[0].getChildren()[0].getLabel(), "bbb node has a wrong name");286 },287 testChildReverse: function() {288 // reverse the children289 this.__model.getChildren().reverse();290 // check the labels291 this.assertEquals("a", this.__tree.getRoot().getChildren()[2].getLabel(), "First node has a wrong name");292 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");293 this.assertEquals("c", this.__tree.getRoot().getChildren()[0].getLabel(), "Third node has a wrong name");294 },295 testChangeChildPath: function() {296 // change the child path297 this.__controller.setChildPath("altChildren");298 // check the labels299 this.assertEquals("c", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");300 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");301 this.assertEquals("a", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");302 },303 testChangeTarget: function() {304 // create a new tree305 var tree = new qx.ui.tree.Tree();306 // set the new tree as target307 this.__controller.setTarget(tree);308 // check the new folders309 this.assertEquals("a", tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");310 this.assertEquals("b", tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");311 this.assertEquals("c", tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");312 // check if the old tree is empty313 this.assertNull(this.__tree.getRoot(), "Former tree is not empty.");314 },315 testChangeModel: function() {316 // create a new model317 // this.__model318 // / \319 // this.__a this.__b320 var model = new qx.test.TreeNode();321 var a = new qx.test.TreeNode();322 a.setName("A");323 var b = new qx.test.TreeNode();324 b.setName("B");325 model.getChildren().push(a, b);326 // set the new model327 this.__controller.setModel(model);328 // check the folders329 this.assertEquals("A", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");330 this.assertEquals("B", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");331 },332 testIconPath: function() {333 this.assertEquals(null, this.__tree.getRoot().getIcon(), "Root node has a wrong icon");334 this.assertEquals("icon a", this.__tree.getRoot().getChildren()[0].getIcon(), "First node has a wrong icon");335 this.assertEquals("icon b", this.__tree.getRoot().getChildren()[1].getIcon(), "Second node has a wrong icon");336 this.assertEquals("icon c", this.__tree.getRoot().getChildren()[2].getIcon(), "Third node has a wrong icon");337 },338 testIconPathChange: function() {339 // change the icon path340 this.__controller.setIconPath("icon2");341 // test the binding342 this.assertEquals(null, this.__tree.getRoot().getIcon(), "Root node has a wrong icon");343 this.assertEquals("icon a2", this.__tree.getRoot().getChildren()[0].getIcon(), "First node has a wrong icon");344 this.assertEquals("icon b2", this.__tree.getRoot().getChildren()[1].getIcon(), "Second node has a wrong icon");345 this.assertEquals("icon c2", this.__tree.getRoot().getChildren()[2].getIcon(), "Third node has a wrong icon");346 },347 testIconChange: function() {348 // change the icon values349 this.__model.setIcon("AFFE");350 this.__a.setIcon("ICON A");351 this.__b.setIcon("ICON B");352 this.__c.setIcon("ICON C");353 // test the new icon values354 this.assertEquals("AFFE", this.__tree.getRoot().getIcon(), "Root node has a wrong icon");355 this.assertEquals("ICON A", this.__tree.getRoot().getChildren()[0].getIcon(), "First node has a wrong icon");356 this.assertEquals("ICON B", this.__tree.getRoot().getChildren()[1].getIcon(), "Second node has a wrong icon");357 this.assertEquals("ICON C", this.__tree.getRoot().getChildren()[2].getIcon(), "Third node has a wrong icon");358 },359 testSelection: function() {360 // open the tree so that the selection can be done361 this.__tree.getRoot().setOpen(true);362 // select the first object363 this.__tree.addToSelection(this.__tree.getRoot().getChildren()[0]);364 // test the selection365 this.assertEquals(this.__a, this.__controller.getSelection().getItem(0), "Selection does not work.");366 // test for the length367 this.assertEquals(1, this.__controller.getSelection().length, "Selection length is wrong.");368 // select the second object369 this.__tree.addToSelection(this.__tree.getRoot().getChildren()[1]);370 // test the selection371 this.assertEquals(this.__b, this.__controller.getSelection().getItem(0), "Selection does not work.");372 // test for the length373 this.assertEquals(1, this.__controller.getSelection().length, "Selection length is wrong.");374 },375 testSelectionBackMultiple: function() {376 // open the tree so that the selection can be done377 this.__tree.getRoot().setOpen(true);378 // select the second and third object379 this.__tree.setSelectionMode("multi");380 // add the some elements to the selection381 this.__controller.getSelection().push(this.__a);382 this.__controller.getSelection().push(this.__b);383 // test the selection384 this.assertEquals(this.__a, this.__controller.getSelection().getItem(0), "Add to selection does not work.");385 this.assertEquals(this.__b, this.__controller.getSelection().getItem(1), "Add to selection does not work.");386 },387 testSelectionAfterDelete: function() {388 // open the tree so that the selection can be done389 this.__tree.getRoot().setOpen(true);390 // add c to the selection391 this.__controller.getSelection().push(this.__c);392 // remove the c node393 this.__model.getChildren().splice(2, 1);394 // check if the selection is empty395 this.assertEquals(0, this.__controller.getSelection().length, "Remove from selection does not work!");396 // add b to the selection397 this.__controller.getSelection().push(this.__b);398 // remove the first element of the controller 'this.__a'399 this.__model.getChildren().shift();400 // check if the selected item in the list is "b"401 this.assertTrue(this.__controller.getSelection().contains(this.__b), "Selection array wrong!");402 this.assertEquals("b", this.__tree.getSelection()[0].getLabel(), "Remove from selection does not work!");403 },404 testSelectInvisible: function() {405 // add c to the selection406 this.__controller.getSelection().push(this.__c);407 // check if the selection worked408 this.assertEquals(1, this.__controller.getSelection().length, "Adding of an non visible element should not work.");409 },410 testLabelOptions: function() {411 // create the options412 var options = {413 converter: function(data, model) {414 return data + model.getName2();415 }416 };417 // create the controller418 this.__controller = new qx.data.controller.Tree(this.__model, this.__tree, "children", "name");419 this.__controller.setLabelOptions(options);420 // test the converter421 this.assertEquals("rootroot2", this.__tree.getRoot().getLabel(), "Root node has a wrong name");422 this.assertEquals("aa2", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");423 this.assertEquals("bb2", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");424 this.assertEquals("cc2", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");425 },426 testIconOptions: function() {427 // create the options428 var options = {429 converter: function(data, model) {430 if (data != null) {431 return data + model.getName();432 }433 return null;434 }435 };436 // create the controller437 this.__controller = new qx.data.controller.Tree(this.__model, this.__tree, "children", "name");438 this.__controller.setIconPath("icon");439 this.__controller.setIconOptions(options);440 // test the converter441 this.assertNull(this.__tree.getRoot().getIcon(), "Root node has a wrong icon");442 this.assertEquals("icon aa", this.__tree.getRoot().getChildren()[0].getIcon(), "First node has a wrong icon");443 this.assertEquals("icon bb", this.__tree.getRoot().getChildren()[1].getIcon(), "Second node has a wrong icon");444 this.assertEquals("icon cc", this.__tree.getRoot().getChildren()[2].getIcon(), "Third node has a wrong icon");445 },446 testItemWithoutChildren: function() {447 // create new Object448 qx.Class.define("qx.test.TreeEndNode",449 {450 extend : qx.core.Object,451 properties :452 {453 name : {454 check : "String",455 init : "root",456 event : "changeName"457 },458 icon : {459 check : "String",460 event : "changeIcon",461 nullable : true462 }463 }464 });465 var endNode = new qx.test.TreeEndNode();466 endNode.setName("ENDE");467 this.__model.getChildren().push(endNode);468 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");469 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");470 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");471 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");472 this.assertEquals("ENDE", this.__tree.getRoot().getChildren()[3].getLabel(), "Fourth node has a wrong name");473 },474 testSetLateModel: function() {475 // create the controller476 this.__controller = new qx.data.controller.Tree(null, this.__tree, "children", "name");477 this.__controller.setModel(this.__model);478 // check the initial Labels479 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");480 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");481 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");482 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");483 },484 testSetLateTarget: function() {485 // create the controller486 this.__controller = new qx.data.controller.Tree(this.__model, null, "children", "name");487 this.__controller.setTarget(this.__tree);488 // check the initial Labels489 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");490 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");491 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");492 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");493 },494 testSetLateTargetAndModel: function() {495 this.__controller = new qx.data.controller.Tree(null, null, "children", "name");496 this.__controller.setTarget(this.__tree);497 this.__controller.setModel(this.__model);498 // check the initial Labels499 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");500 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");501 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");502 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");503 // redo the test and set the modeln and target in different order504 this.__controller = new qx.data.controller.Tree(null, null, "children", "name");505 this.__controller.setModel(this.__model);506 this.__controller.setTarget(this.__tree);507 // check the initial Labels508 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");509 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");510 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");511 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");512 },513 testSetLateChildPath: function() {514 this.__controller = new qx.data.controller.Tree(this.__model, this.__tree, null, "name");515 this.__controller.setChildPath("children");516 // check the initial Labels517 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");518 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");519 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");520 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");521 },522 testSetLateLabelPath: function() {523 this.__controller = new qx.data.controller.Tree(this.__model, this.__tree, "children");524 this.__controller.setLabelPath("name");525 // check the initial Labels526 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");527 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");528 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");529 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");530 },531 testSetLateAll: function() {532 this.__controller = new qx.data.controller.Tree();533 // set the needed properties534 this.__controller.setLabelPath("name");535 this.__controller.setChildPath("children");536 this.__controller.setModel(this.__model);537 this.__controller.setTarget(this.__tree);538 // check the initial Labels539 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");540 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");541 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");542 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");543 },544 testDelegateConfigure: function() {545 // create the delegate546 var delegate = new qx.core.Object();547 delegate.configureItem = function(item) {548 item.setUserData("a", true);549 };550 this.__controller.setDelegate(delegate);551 // check the initial Labels552 this.assertTrue(this.__tree.getRoot().getUserData("a"), "Delegation not working.");553 this.assertTrue(this.__tree.getRoot().getChildren()[0].getUserData("a"), "Delegation not working.");554 this.assertTrue(this.__tree.getRoot().getChildren()[1].getUserData("a"), "Delegation not working.");555 this.assertTrue(this.__tree.getRoot().getChildren()[2].getUserData("a"), "Delegation not working.");556 },557 testDelegateConfigureLate : function()558 {559 // clear up the setup560 this.__controller.setModel(null);561 var controller = new qx.data.controller.Tree(null, this.__tree, "children", "name");562 var delegate = {563 configureItem: function(item) {564 item.setUserData("a", true);565 }566 };567 controller.setDelegate(delegate);568 controller.setModel(this.__model);569 // check the initial Labels570 this.assertTrue(this.__tree.getRoot().getUserData("a"), "Delegation not working.");571 this.assertTrue(this.__tree.getRoot().getChildren()[0].getUserData("a"), "Delegation not working.");572 this.assertTrue(this.__tree.getRoot().getChildren()[1].getUserData("a"), "Delegation not working.");573 this.assertTrue(this.__tree.getRoot().getChildren()[2].getUserData("a"), "Delegation not working.");574 },575 testDelegateCreateLate: function () {576 var delegate = {577 createItem : function() {578 var folder = new qx.ui.tree.TreeFolder();579 folder.setUserData("my", true);580 return folder;581 }582 };583 this.__controller.setDelegate(delegate);584 // check the initial Labels585 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");586 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");587 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");588 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");589 // check if the folders are the self created folders590 this.assertTrue(this.__tree.getRoot().getUserData("my"), "Default folders found.");591 this.assertTrue(this.__tree.getRoot().getChildren()[0].getUserData("my"), "Default folders found.");592 this.assertTrue(this.__tree.getRoot().getChildren()[1].getUserData("my"), "Default folders found.");593 this.assertTrue(this.__tree.getRoot().getChildren()[2].getUserData("my"), "Default folders found.");594 },595 testDelegateCreateFirst: function () {596 this.__controller = new qx.data.controller.Tree();597 var delegate = {598 createItem : function() {599 var folder = new qx.ui.tree.TreeFolder();600 folder.setUserData("my", true);601 return folder;602 }603 };604 var tree = new qx.ui.tree.Tree();605 this.__controller.setDelegate(delegate);606 this.__controller.setChildPath("children");607 this.__controller.setLabelPath("name");608 this.__controller.setModel(this.__model);609 this.__controller.setTarget(tree);610 // check the initial Labels611 this.assertEquals("root", tree.getRoot().getLabel(), "Root node has a wrong name");612 this.assertEquals("a", tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");613 this.assertEquals("b", tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");614 this.assertEquals("c", tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");615 // check if the folders are the self created folders616 this.assertTrue(tree.getRoot().getUserData("my"), "Default folders found.");617 this.assertTrue(tree.getRoot().getChildren()[0].getUserData("my"), "Default folders found.");618 this.assertTrue(tree.getRoot().getChildren()[1].getUserData("my"), "Default folders found.");619 this.assertTrue(tree.getRoot().getChildren()[2].getUserData("my"), "Default folders found.");620 tree.destroy();621 },622 testDelegateBindLate: function () {623 var delegate = {624 bindItem : function(controller, item, id) {625 controller.bindDefaultProperties(item, id);626 controller.bindProperty("color", "textColor", null, item, id);627 }628 };629 this.__controller.setDelegate(delegate);630 // check the initial Labels631 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");632 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");633 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");634 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");635 // check the names636 this.assertEquals("green", this.__tree.getRoot().getTextColor(), "Root node has a wrong name");637 this.assertEquals("red", this.__tree.getRoot().getChildren()[0].getTextColor(), "First node has a wrong name");638 this.assertEquals("blue", this.__tree.getRoot().getChildren()[1].getTextColor(), "Second node has a wrong name");639 this.assertEquals("white", this.__tree.getRoot().getChildren()[2].getTextColor(), "Third node has a wrong name");640 this.__model.setColor("black");641 this.assertEquals("black", this.__tree.getRoot().getTextColor(), "Root node has a wrong name");642 },643 testDelegateBindFirst: function () {644 var delegate = {645 bindItem : function(controller, item, id) {646 controller.bindDefaultProperties(item, id);647 controller.bindProperty("color", "textColor", null, item, id);648 }649 };650 var tree = new qx.ui.tree.Tree();651 this.__controller.setDelegate(delegate);652 this.__controller.setChildPath("children");653 this.__controller.setLabelPath("name");654 this.__controller.setModel(this.__model);655 this.__controller.setTarget(tree);656 // check the initial Labels657 this.assertEquals("root", tree.getRoot().getLabel(), "Root node has a wrong name");658 this.assertEquals("a", tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");659 this.assertEquals("b", tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");660 this.assertEquals("c", tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");661 // check the names662 this.assertEquals("green", tree.getRoot().getTextColor(), "Root node has a wrong name");663 this.assertEquals("red", tree.getRoot().getChildren()[0].getTextColor(), "First node has a wrong name");664 this.assertEquals("blue", tree.getRoot().getChildren()[1].getTextColor(), "Second node has a wrong name");665 this.assertEquals("white", tree.getRoot().getChildren()[2].getTextColor(), "Third node has a wrong name");666 this.__model.setColor("black");667 this.assertEquals("black", tree.getRoot().getTextColor(), "Root node has a wrong name");668 },669 testDelegateBindPropertyReverse: function () {670 var delegate = {671 bindItem : function(controller, item, id) {672 controller.bindProperty("name", "appearance", null, item, id);673 controller.bindPropertyReverse("name", "appearance", null, item, id);674 controller.bindPropertyReverse("color", "backgroundColor", null, item, id);675 }676 };677 this.__controller.setDelegate(delegate);678 // check the initial Labels679 this.assertEquals("root", this.__tree.getRoot().getAppearance(), "Root node has a wrong name");680 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getAppearance(), "First node has a wrong name");681 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getAppearance(), "Second node has a wrong name");682 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getAppearance(), "Third node has a wrong name");683 // check the reverse binding684 this.__tree.getRoot().setAppearance("ROOT");685 this.assertEquals("ROOT", this.__model.getName(), "Reverse binding not ok!");686 this.__tree.getRoot().getChildren()[0].setBackgroundColor("#123456");687 this.assertEquals("#123456", this.__a.getColor(), "Reverse binding not ok!");688 // invoke a removing and setting of the bindings with the new bindItem689 delegate.bindItem = function(controller, item, id) {690 controller.bindProperty("name", "appearance", null, item, id);691 }692 this.__controller.setDelegate(null);693 this.__controller.setDelegate(delegate);694 this.__tree.getRoot().setAppearance("123");695 this.assertEquals("ROOT", this.__model.getName(), "Removing not ok");696 this.__tree.getRoot().getChildren()[0].setBackgroundColor("#654321");697 this.assertEquals("#123456", this.__a.getColor(), "Removing not ok");698 },699 testDelegateAddItem: function() {700 var a = new qx.test.TreeNode();701 a.setName("new");702 // set a delegate703 this.__controller.setDelegate({704 createItem : function() {705 return new qx.ui.tree.TreeFolder();706 }707 });708 // slush the dispose queue709 qx.ui.core.queue.Dispose.flush();710 // add the new model711 this.__model.getChildren().push(a);712 a.dispose();713 },714 testResetModel: function() {715 this.__controller.resetModel();716 this.assertNull(this.__tree.getRoot(), "Tree is not empty.");717 },718 testChangeChildrenArray : function() {719 // create the new children array720 var children = new qx.data.Array();721 var a = new qx.test.TreeNode();722 a.setName("new");723 children.push(a);724 // change the children array725 // this.__model726 // / | \727 // this.__a this.__b this.__c728 // |729 // a730 this.__a.setChildren(children);731 // Test if the tree nodes exist732 this.assertNotUndefined(this.__tree.getRoot(), "Root node does not exist");733 this.assertNotUndefined(this.__tree.getRoot().getChildren()[0], "First node does not exist");734 this.assertNotUndefined(this.__tree.getRoot().getChildren()[0].getChildren()[0], "New node does not exist");735 // test if its the proper node736 this.assertEquals("new", this.__tree.getRoot().getChildren()[0].getChildren()[0].getLabel());737 },738 testInheritedChildren : function()739 {740 qx.Class.define("qx.test.MyTreeNode", {741 extend : qx.test.TreeNode742 });743 // init (copy of setUp)744 this.__tree = new qx.ui.tree.Tree();745 // create a model746 // this.__model747 // / | \748 // this.__a this.__b this.__c749 this.__model = new qx.test.MyTreeNode();750 this.__a = new qx.test.MyTreeNode();751 this.__a.set({752 name: "a",753 name2: "a2",754 icon: "icon a",755 icon2: "icon a2",756 color: "red"757 });758 this.__b = new qx.test.MyTreeNode();759 this.__b.set({760 name: "b",761 name2: "b2",762 icon: "icon b",763 icon2: "icon b2",764 color: "blue"765 });766 this.__c = new qx.test.MyTreeNode();767 this.__c.set({768 name: "c",769 name2: "c2",770 icon: "icon c",771 icon2: "icon c2",772 color: "white"773 });774 this.__model.getChildren().push(this.__a, this.__b, this.__c);775 this.__model.getAltChildren().push(this.__c, this.__b, this.__a);776 // create the controller777 this.__controller = new qx.data.controller.Tree(this.__model, this.__tree, "children", "name");778 // check the initial Labels779 this.assertEquals("root", this.__tree.getRoot().getLabel(), "Root node has a wrong name");780 this.assertEquals("a", this.__tree.getRoot().getChildren()[0].getLabel(), "First node has a wrong name");781 this.assertEquals("b", this.__tree.getRoot().getChildren()[1].getLabel(), "Second node has a wrong name");782 this.assertEquals("c", this.__tree.getRoot().getChildren()[2].getLabel(), "Third node has a wrong name");783 },784 testRemoveEvents : function()785 {786 // BUG #3566787 var nodes = [];788 for (var i = 0; i < 50; ++i)789 {790 nodes[i] = new qx.test.TreeNode();791 if (i != 0) {792 nodes[parseInt(Math.random() * i, 10)].getChildren().push(nodes[i]);793 }794 }795 var tree = new qx.ui.tree.Tree();796 var controller = new qx.data.controller.Tree(nodes[0], tree, "children", "name");797 for (var i = 0; i < nodes.length; ++i) {798 nodes[i].getChildren().removeAll(); // THIS THROWS AN EXCEPTION ON 2ND ELEMENT...799 }800 tree.dispose();801 controller.dispose();802 for (var i = 0; i < nodes.length; ++i) {803 nodes[i].dispose();804 }805 }806 }...

Full Screen

Full Screen

ReactIncrementalScheduling-test.js

Source:ReactIncrementalScheduling-test.js Github

copy

Full Screen

...23 it('schedules and flushes animation work', () => {24 ReactNoop.performAnimationWork(() => {25 ReactNoop.render(<span prop="1" />);26 });27 expect(ReactNoop.getChildren()).toEqual([]);28 ReactNoop.flushAnimationPri();29 expect(ReactNoop.getChildren()).toEqual([span('1')]);30 });31 it('schedules and flushes animation work for many roots', () => {32 ReactNoop.performAnimationWork(() => {33 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');34 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');35 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');36 });37 expect(ReactNoop.getChildren('a')).toEqual([]);38 expect(ReactNoop.getChildren('b')).toEqual([]);39 expect(ReactNoop.getChildren('c')).toEqual([]);40 ReactNoop.flushAnimationPri();41 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);42 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);43 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);44 });45 it('flushes all scheduled animation work', () => {46 ReactNoop.performAnimationWork(() => {47 ReactNoop.render(<span prop="1" />);48 });49 ReactNoop.performAnimationWork(() => {50 ReactNoop.render(<span prop="2" />);51 });52 expect(ReactNoop.getChildren()).toEqual([]);53 ReactNoop.flushAnimationPri();54 expect(ReactNoop.getChildren()).toEqual([span('2')]);55 });56 it('flushes all scheduled animation work for many roots', () => {57 ReactNoop.performAnimationWork(() => {58 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');59 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');60 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');61 });62 ReactNoop.performAnimationWork(() => {63 ReactNoop.renderToRootWithID(<span prop="a:2" />, 'a');64 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');65 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');66 });67 expect(ReactNoop.getChildren('a')).toEqual([]);68 expect(ReactNoop.getChildren('b')).toEqual([]);69 expect(ReactNoop.getChildren('c')).toEqual([]);70 ReactNoop.flushAnimationPri();71 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);72 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);73 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);74 });75 it('schedules and flushes deferred work', () => {76 ReactNoop.render(<span prop="1" />);77 expect(ReactNoop.getChildren()).toEqual([]);78 ReactNoop.flushDeferredPri();79 expect(ReactNoop.getChildren()).toEqual([span('1')]);80 });81 it('schedules and flushes deferred work for many roots', () => {82 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');83 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');84 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');85 expect(ReactNoop.getChildren('a')).toEqual([]);86 expect(ReactNoop.getChildren('b')).toEqual([]);87 expect(ReactNoop.getChildren('c')).toEqual([]);88 ReactNoop.flushDeferredPri();89 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);90 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);91 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);92 });93 it('flushes scheduled deferred work fitting within deadline', () => {94 ReactNoop.render(<span prop="1" />);95 ReactNoop.render(<span prop="2" />);96 expect(ReactNoop.getChildren()).toEqual([]);97 ReactNoop.flushDeferredPri();98 expect(ReactNoop.getChildren()).toEqual([span('2')]);99 });100 it('flushes scheduled deferred work fitting within deadline for many roots', () => {101 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');102 ReactNoop.renderToRootWithID(<span prop="a:2" />, 'a');103 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');104 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');105 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');106 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');107 expect(ReactNoop.getChildren('a')).toEqual([]);108 expect(ReactNoop.getChildren('b')).toEqual([]);109 expect(ReactNoop.getChildren('c')).toEqual([]);110 ReactNoop.flushDeferredPri();111 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);112 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);113 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);114 });115 it('schedules more deferred work if it runs out of time', () => {116 ReactNoop.render(<span prop="1" />);117 ReactNoop.render(<span prop="2" />);118 expect(ReactNoop.getChildren()).toEqual([]);119 ReactNoop.flushDeferredPri(5);120 expect(ReactNoop.getChildren()).toEqual([]);121 ReactNoop.flushDeferredPri(10);122 expect(ReactNoop.getChildren()).toEqual([]);123 ReactNoop.flushDeferredPri(10);124 expect(ReactNoop.getChildren()).toEqual([span('2')]);125 });126 it('schedules more deferred work if it runs out of time with many roots', () => {127 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');128 ReactNoop.renderToRootWithID(<span prop="a:2" />, 'a');129 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');130 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');131 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');132 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');133 expect(ReactNoop.getChildren('a')).toEqual([]);134 expect(ReactNoop.getChildren('b')).toEqual([]);135 expect(ReactNoop.getChildren('c')).toEqual([]);136 ReactNoop.flushDeferredPri(15);137 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);138 expect(ReactNoop.getChildren('b')).toEqual([]);139 expect(ReactNoop.getChildren('c')).toEqual([]);140 ReactNoop.flushDeferredPri(15);141 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);142 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);143 expect(ReactNoop.getChildren('c')).toEqual([]);144 ReactNoop.flushDeferredPri(15);145 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);146 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);147 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);148 });149 it('flushes late animation work in a deferred callback if it wins', () => {150 // Schedule early deferred151 ReactNoop.render(<span prop="1" />);152 // Schedule late animation153 ReactNoop.performAnimationWork(() => {154 ReactNoop.render(<span prop="2" />);155 });156 expect(ReactNoop.getChildren()).toEqual([]);157 // We only scheduled deferred callback so that's what we get.158 // It will flush everything.159 ReactNoop.flushDeferredPri();160 expect(ReactNoop.getChildren()).toEqual([span('2')]);161 });162 it('flushes late animation work in a deferred callback if it wins with many roots', () => {163 // Schedule early deferred164 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');165 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');166 // Schedule late animation167 ReactNoop.performAnimationWork(() => {168 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');169 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');170 });171 expect(ReactNoop.getChildren('a')).toEqual([]);172 expect(ReactNoop.getChildren('b')).toEqual([]);173 expect(ReactNoop.getChildren('c')).toEqual([]);174 // We only scheduled deferred callback so that's what we get.175 // It will flush everything.176 ReactNoop.flushDeferredPri();177 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);178 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);179 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);180 });181 it('flushes late animation work in an animation callback if it wins', () => {182 // Schedule early deferred183 ReactNoop.render(<span prop="1" />);184 // Schedule late animation185 ReactNoop.performAnimationWork(() => {186 ReactNoop.render(<span prop="2" />);187 });188 expect(ReactNoop.getChildren()).toEqual([]);189 // Flushing animation should have flushed the animation.190 ReactNoop.flushAnimationPri();191 expect(ReactNoop.getChildren()).toEqual([span('2')]);192 });193 it('flushes late animation work in an animation callback if it wins with many roots', () => {194 // Schedule early deferred195 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');196 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');197 // Schedule late animation198 ReactNoop.performAnimationWork(() => {199 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');200 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');201 });202 expect(ReactNoop.getChildren('a')).toEqual([]);203 expect(ReactNoop.getChildren('b')).toEqual([]);204 expect(ReactNoop.getChildren('c')).toEqual([]);205 // Flushing animation should have flushed the animation.206 ReactNoop.flushAnimationPri();207 expect(ReactNoop.getChildren('a')).toEqual([]);208 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);209 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);210 ReactNoop.flushDeferredPri();211 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);212 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);213 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);214 });215 it('flushes all work in a deferred callback if it wins', () => {216 // Schedule early animation217 ReactNoop.performAnimationWork(() => {218 ReactNoop.render(<span prop="1" />);219 });220 // Schedule late deferred221 ReactNoop.render(<span prop="2" />);222 expect(ReactNoop.getChildren()).toEqual([]);223 // Flushing deferred should have flushed both early animation and late deferred work that invalidated it.224 // This is not a common case, as animation should generally be flushed before deferred work.225 ReactNoop.flushDeferredPri();226 expect(ReactNoop.getChildren()).toEqual([span('2')]);227 });228 it('flushes all work in a deferred callback if it wins with many roots', () => {229 // Schedule early animation230 ReactNoop.performAnimationWork(() => {231 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');232 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');233 });234 // Schedule late deferred235 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');236 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');237 expect(ReactNoop.getChildren('a')).toEqual([]);238 expect(ReactNoop.getChildren('b')).toEqual([]);239 expect(ReactNoop.getChildren('c')).toEqual([]);240 // Flushing deferred should have flushed both early animation and late deferred work that invalidated it.241 // This is not a common case, as animation should generally be flushed before deferred work.242 ReactNoop.flushDeferredPri();243 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);244 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);245 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);246 });247 it('flushes root with late deferred work in an animation callback if it wins', () => {248 // Schedule early animation249 ReactNoop.performAnimationWork(() => {250 ReactNoop.render(<span prop="1" />);251 });252 // Schedule late deferred253 ReactNoop.render(<span prop="2" />);254 expect(ReactNoop.getChildren()).toEqual([]);255 // Flushing animation work flushes everything on this root.256 ReactNoop.flushAnimationPri();257 expect(ReactNoop.getChildren()).toEqual([span('2')]);258 });259 it('flushes all roots with animation work in an animation callback if it wins', () => {260 // Schedule early animation261 ReactNoop.performAnimationWork(() => {262 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');263 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');264 });265 // Schedule late deferred266 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');267 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');268 expect(ReactNoop.getChildren('a')).toEqual([]);269 expect(ReactNoop.getChildren('b')).toEqual([]);270 expect(ReactNoop.getChildren('c')).toEqual([]);271 // Flushing animation work flushes all roots with animation work.272 ReactNoop.flushAnimationPri();273 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);274 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);275 expect(ReactNoop.getChildren('c')).toEqual([]);276 // Flushing deferred work flushes the root with only deferred work.277 ReactNoop.flushDeferredPri();278 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);279 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);280 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);281 });282 it('splits deferred work on multiple roots', () => {283 // Schedule one root284 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');285 ReactNoop.flushDeferredPri(15);286 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);287 // Schedule two roots288 ReactNoop.renderToRootWithID(<span prop="a:2" />, 'a');289 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');290 // First scheduled one gets processed first291 ReactNoop.flushDeferredPri(15);292 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);293 expect(ReactNoop.getChildren('b')).toEqual([]);294 expect(ReactNoop.getChildren('c')).toEqual(null);295 // Then the second one gets processed296 ReactNoop.flushDeferredPri(15);297 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);298 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);299 expect(ReactNoop.getChildren('c')).toEqual(null);300 // Schedule three roots301 ReactNoop.renderToRootWithID(<span prop="a:3" />, 'a');302 ReactNoop.renderToRootWithID(<span prop="b:3" />, 'b');303 ReactNoop.renderToRootWithID(<span prop="c:3" />, 'c');304 // They get processed in the order they were scheduled305 ReactNoop.flushDeferredPri(15);306 expect(ReactNoop.getChildren('a')).toEqual([span('a:3')]);307 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);308 expect(ReactNoop.getChildren('c')).toEqual([]);309 ReactNoop.flushDeferredPri(15);310 expect(ReactNoop.getChildren('a')).toEqual([span('a:3')]);311 expect(ReactNoop.getChildren('b')).toEqual([span('b:3')]);312 expect(ReactNoop.getChildren('c')).toEqual([]);313 ReactNoop.flushDeferredPri(15);314 expect(ReactNoop.getChildren('a')).toEqual([span('a:3')]);315 expect(ReactNoop.getChildren('b')).toEqual([span('b:3')]);316 expect(ReactNoop.getChildren('c')).toEqual([span('c:3')]);317 // Schedule one root many times318 ReactNoop.renderToRootWithID(<span prop="a:4" />, 'a');319 ReactNoop.renderToRootWithID(<span prop="a:5" />, 'a');320 ReactNoop.renderToRootWithID(<span prop="a:6" />, 'a');321 ReactNoop.flushDeferredPri(15);322 expect(ReactNoop.getChildren('a')).toEqual([span('a:6')]);323 });324 it('works on deferred roots in the order they were scheduled', () => {325 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');326 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');327 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');328 ReactNoop.flush();329 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);330 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);331 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);332 // Schedule deferred work in the reverse order333 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');334 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');335 // Ensure it starts in the order it was scheduled336 ReactNoop.flushDeferredPri(15);337 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);338 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);339 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);340 // Schedule last bit of work, it will get processed the last341 ReactNoop.renderToRootWithID(<span prop="a:2" />, 'a');342 // Keep performing work in the order it was scheduled343 ReactNoop.flushDeferredPri(15);344 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);345 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);346 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);347 ReactNoop.flushDeferredPri(15);348 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);349 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);350 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);351 });352 it('handles interleaved deferred and animation work', () => {353 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');354 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');355 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');356 ReactNoop.flush();357 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);358 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);359 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);360 // Schedule both deferred and animation work361 ReactNoop.renderToRootWithID(<span prop="a:2" />, 'a');362 ReactNoop.performAnimationWork(() => {363 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');364 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');365 });366 // We're flushing deferred work367 // Still, roots with animation work are handled first368 ReactNoop.flushDeferredPri(15);369 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);370 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);371 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);372 ReactNoop.flushDeferredPri(15);373 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);374 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);375 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);376 // More deferred and animation work just got scheduled!377 ReactNoop.renderToRootWithID(<span prop="c:3" />, 'c');378 ReactNoop.performAnimationWork(() => {379 ReactNoop.renderToRootWithID(<span prop="b:3" />, 'b');380 });381 // Animation is still handled first382 ReactNoop.flushDeferredPri(15);383 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);384 expect(ReactNoop.getChildren('b')).toEqual([span('b:3')]);385 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);386 // Finally we handle deferred root in the order it was scheduled387 ReactNoop.flushDeferredPri(15);388 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);389 expect(ReactNoop.getChildren('b')).toEqual([span('b:3')]);390 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);391 ReactNoop.flushDeferredPri(15);392 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);393 expect(ReactNoop.getChildren('b')).toEqual([span('b:3')]);394 expect(ReactNoop.getChildren('c')).toEqual([span('c:3')]);395 });396 it('performs animation work in animation callback', () => {397 class Foo extends React.Component {398 componentDidMount() {399 // Animation work that will get performed during animation callback400 ReactNoop.performAnimationWork(() => {401 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');402 });403 }404 render() {405 return <span prop="a:1" />;406 }407 }408 // Schedule animation work409 ReactNoop.performAnimationWork(() => {410 ReactNoop.renderToRootWithID(<Foo />, 'a');411 });412 // Flushing animation work should flush animation work scheduled inside it413 ReactNoop.flushAnimationPri();414 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);415 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);416 });417 it('schedules deferred work in animation callback', () => {418 class Foo extends React.Component {419 componentDidMount() {420 // Deferred work that will get scheduled during animation callback421 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');422 }423 render() {424 return <span prop="a:1" />;425 }426 }427 // Schedule animation work428 ReactNoop.performAnimationWork(() => {429 ReactNoop.renderToRootWithID(<Foo />, 'a');430 });431 // Flushing animation work should not flush the deferred work432 ReactNoop.flushAnimationPri();433 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);434 expect(ReactNoop.getChildren('b')).toEqual([]);435 // Flush the deferred work436 ReactNoop.flushDeferredPri();437 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);438 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);439 });440 it('schedules deferred work and performs animation work in animation callback', () => {441 let hasScheduled = false;442 class Foo extends React.Component {443 componentDidMount() {444 // Deferred work that will get scheduled during animation callback445 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');446 // Animation work that will get performed during animation callback447 ReactNoop.performAnimationWork(() => {448 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');449 });450 // Deferred work that will get scheduled during animation callback451 ReactNoop.renderToRootWithID(<span prop="d:1" />, 'd');452 hasScheduled = true;453 }454 render() {455 return <span prop="a:1" />;456 }457 }458 // Schedule animation work459 ReactNoop.performAnimationWork(() => {460 ReactNoop.renderToRootWithID(<Foo />, 'a');461 });462 // Flushing animation work should flush animation work scheduled inside it463 ReactNoop.flushAnimationPri();464 expect(hasScheduled).toBe(true);465 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);466 expect(ReactNoop.getChildren('b')).toEqual([]);467 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);468 expect(ReactNoop.getChildren('d')).toEqual([]);469 // Flush the deferred work470 ReactNoop.flushDeferredPri();471 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);472 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);473 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);474 expect(ReactNoop.getChildren('d')).toEqual([span('d:1')]);475 });476 it('performs animation work and schedules deferred work in animation callback', () => {477 let hasScheduled = false;478 class Foo extends React.Component {479 componentDidMount() {480 // Animation work that will get performed during animation callback481 ReactNoop.performAnimationWork(() => {482 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');483 });484 // Deferred work that will get scheduled during animation callback485 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');486 // Animation work that will get performed during animation callback487 ReactNoop.performAnimationWork(() => {488 ReactNoop.renderToRootWithID(<span prop="d:1" />, 'd');489 });490 hasScheduled = true;491 }492 render() {493 return <span prop="a:1" />;494 }495 }496 // Schedule animation work497 ReactNoop.performAnimationWork(() => {498 ReactNoop.renderToRootWithID(<Foo />, 'a');499 });500 // Flushing animation work should flush animation work scheduled inside it501 ReactNoop.flushAnimationPri();502 expect(hasScheduled).toBe(true);503 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);504 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);505 expect(ReactNoop.getChildren('c')).toEqual([]);506 expect(ReactNoop.getChildren('d')).toEqual([span('d:1')]);507 // Flush the deferred work508 ReactNoop.flushDeferredPri();509 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);510 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);511 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);512 expect(ReactNoop.getChildren('d')).toEqual([span('d:1')]);513 });514 it('performs deferred work in deferred callback if it has time', () => {515 class Foo extends React.Component {516 componentDidMount() {517 // Deferred work that will get performed during deferred callback518 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');519 }520 render() {521 return <span prop="a:1" />;522 }523 }524 // Schedule deferred work525 ReactNoop.renderToRootWithID(<Foo />, 'a');526 // Flushing deferred work should flush deferred work scheduled inside it527 ReactNoop.flushDeferredPri();528 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);529 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);530 });531 it('schedules deferred work in deferred callback if it runs out of time', () => {532 let hasScheduled = false;533 class Foo extends React.Component {534 componentDidMount() {535 // Deferred work that will get scheduled during deferred callback536 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');537 hasScheduled = true;538 }539 render() {540 return <span prop="a:1" />;541 }542 }543 // Schedule deferred work544 ReactNoop.renderToRootWithID(<Foo />, 'a');545 // Flush just enough deferred work to schedule more deferred work546 ReactNoop.flushDeferredPri(20);547 expect(hasScheduled).toBe(true);548 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);549 expect(ReactNoop.getChildren('b')).toEqual([]);550 // Flush the rest of the deferred work551 ReactNoop.flushDeferredPri(15);552 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);553 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);554 });555 it('performs animated work in deferred callback if it has time', () => {556 class Foo extends React.Component {557 componentDidMount() {558 // Animated work that will get performed during deferred callback559 ReactNoop.performAnimationWork(() => {560 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');561 });562 }563 render() {564 return <span prop="a:1" />;565 }566 }567 // Schedule deferred work568 ReactNoop.renderToRootWithID(<Foo />, 'a');569 // Flushing deferred work should flush animated work scheduled inside it570 ReactNoop.flushDeferredPri();571 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);572 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);573 });574 it('performs animated work and deferred work in deferred callback if it has time', () => {575 class Foo extends React.Component {576 componentDidMount() {577 // Deferred work that will get performed during deferred callback578 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');579 // Animation work that will get performed during deferred callback580 ReactNoop.performAnimationWork(() => {581 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');582 });583 // Deferred work that will get performed during deferred callback584 ReactNoop.renderToRootWithID(<span prop="d:1" />, 'd');585 }586 render() {587 return <span prop="a:1" />;588 }589 }590 // Schedule deferred work591 ReactNoop.renderToRootWithID(<Foo />, 'a');592 // Flushing deferred work should flush both deferred and animated work scheduled inside it593 ReactNoop.flushDeferredPri();594 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);595 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);596 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);597 expect(ReactNoop.getChildren('d')).toEqual([span('d:1')]);598 });599 it('performs deferred and animated work work in deferred callback if it has time', () => {600 class Foo extends React.Component {601 componentDidMount() {602 // Animation work that will get performed during deferred callback603 ReactNoop.performAnimationWork(() => {604 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');605 });606 // Deferred work that will get performed during deferred callback607 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');608 // Animation work that will get performed during deferred callback609 ReactNoop.performAnimationWork(() => {610 ReactNoop.renderToRootWithID(<span prop="d:1" />, 'd');611 });612 }613 render() {614 return <span prop="a:1" />;615 }616 }617 // Schedule deferred work618 ReactNoop.renderToRootWithID(<Foo />, 'a');619 // Flushing deferred work should flush both deferred and animated work scheduled inside it620 ReactNoop.flushDeferredPri();621 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);622 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);623 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);624 expect(ReactNoop.getChildren('d')).toEqual([span('d:1')]);625 });626 it('schedules animated work in deferred callback if it runs out of time', () => {627 let hasScheduled = false;628 class Foo extends React.Component {629 componentDidMount() {630 // Animated work that will get scheduled during deferred callback631 ReactNoop.performAnimationWork(() => {632 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');633 });634 hasScheduled = true;635 }636 render() {637 return <span prop="a:1" />;638 }639 }640 // Schedule deferred work641 ReactNoop.renderToRootWithID(<Foo />, 'a');642 // Flush just enough deferred work to schedule animated work643 ReactNoop.flushDeferredPri(20);644 expect(hasScheduled).toBe(true);645 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);646 expect(ReactNoop.getChildren('b')).toEqual([]);647 // Flush the rest of work in an animated callback.648 ReactNoop.flushAnimationPri();649 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);650 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);651 });652 it('schedules animated work and deferred work in deferred callback if it runs out of time', () => {653 let isScheduled = false;654 class Foo extends React.Component {655 componentDidMount() {656 // Deferred work that will get performed during deferred callback657 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');658 // Animation work that will get performed during deferred callback659 ReactNoop.performAnimationWork(() => {660 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');661 });662 // Deferred work that will get performed during deferred callback663 ReactNoop.renderToRootWithID(<span prop="d:1" />, 'd');664 isScheduled = true;665 }666 render() {667 return <span prop="a:1" />;668 }669 }670 // Schedule deferred work671 ReactNoop.renderToRootWithID(<Foo />, 'a');672 // Flushing deferred work should schedule both deferred and animated work673 ReactNoop.flushDeferredPri(20);674 expect(isScheduled).toBe(true);675 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);676 expect(ReactNoop.getChildren('b')).toEqual([]);677 expect(ReactNoop.getChildren('c')).toEqual([]);678 expect(ReactNoop.getChildren('d')).toEqual([]);679 // Flush the rest of the work680 ReactNoop.flushDeferredPri();681 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);682 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);683 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);684 expect(ReactNoop.getChildren('d')).toEqual([span('d:1')]);685 });686 it('schedules deferred work and animated work in deferred callback if it runs out of time', () => {687 let isScheduled = false;688 class Foo extends React.Component {689 componentDidMount() {690 // Animation work that will get performed during deferred callback691 ReactNoop.performAnimationWork(() => {692 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');693 });694 // Deferred work that will get performed during deferred callback695 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');696 // Animation work that will get performed during deferred callback697 ReactNoop.performAnimationWork(() => {698 ReactNoop.renderToRootWithID(<span prop="d:1" />, 'd');699 });700 isScheduled = true;701 }702 render() {703 return <span prop="a:1" />;704 }705 }706 // Schedule deferred work707 ReactNoop.renderToRootWithID(<Foo />, 'a');708 // Flushing deferred work should schedule both deferred and animated work709 ReactNoop.flushDeferredPri(20);710 expect(isScheduled).toBe(true);711 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);712 expect(ReactNoop.getChildren('b')).toEqual([]);713 expect(ReactNoop.getChildren('c')).toEqual([]);714 expect(ReactNoop.getChildren('d')).toEqual([]);715 // Flush the rest of the work716 ReactNoop.flushDeferredPri();717 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);718 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);719 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);720 expect(ReactNoop.getChildren('d')).toEqual([span('d:1')]);721 });...

Full Screen

Full Screen

ReactIncrementalScheduling-test.internal.js

Source:ReactIncrementalScheduling-test.internal.js Github

copy

Full Screen

...23 return {type: 'span', children: [], prop, hidden: false};24 }25 it('schedules and flushes deferred work', () => {26 ReactNoop.render(<span prop="1" />);27 expect(ReactNoop.getChildren()).toEqual([]);28 ReactNoop.flushDeferredPri();29 expect(ReactNoop.getChildren()).toEqual([span('1')]);30 });31 it('searches for work on other roots once the current root completes', () => {32 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');33 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');34 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');35 ReactNoop.flush();36 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);37 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);38 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);39 });40 it('schedules top-level updates in order of priority', () => {41 // Initial render.42 ReactNoop.render(<span prop={1} />);43 ReactNoop.flush();44 expect(ReactNoop.getChildren()).toEqual([span(1)]);45 ReactNoop.batchedUpdates(() => {46 ReactNoop.render(<span prop={5} />);47 ReactNoop.flushSync(() => {48 ReactNoop.render(<span prop={2} />);49 ReactNoop.render(<span prop={3} />);50 ReactNoop.render(<span prop={4} />);51 });52 });53 // The sync updates flush first.54 expect(ReactNoop.getChildren()).toEqual([span(4)]);55 // The terminal value should be the last update that was scheduled,56 // regardless of priority. In this case, that's the last sync update.57 ReactNoop.flush();58 expect(ReactNoop.getChildren()).toEqual([span(4)]);59 });60 it('schedules top-level updates with same priority in order of insertion', () => {61 // Initial render.62 ReactNoop.render(<span prop={1} />);63 ReactNoop.flush();64 expect(ReactNoop.getChildren()).toEqual([span(1)]);65 ReactNoop.render(<span prop={2} />);66 ReactNoop.render(<span prop={3} />);67 ReactNoop.render(<span prop={4} />);68 ReactNoop.render(<span prop={5} />);69 ReactNoop.flush();70 expect(ReactNoop.getChildren()).toEqual([span(5)]);71 });72 it('works on deferred roots in the order they were scheduled', () => {73 ReactNoop.renderToRootWithID(<span prop="a:1" />, 'a');74 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');75 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');76 ReactNoop.flush();77 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);78 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);79 expect(ReactNoop.getChildren('c')).toEqual([span('c:1')]);80 // Schedule deferred work in the reverse order81 ReactNoop.renderToRootWithID(<span prop="c:2" />, 'c');82 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');83 // Ensure it starts in the order it was scheduled84 ReactNoop.flushDeferredPri(15 + 5);85 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);86 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);87 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);88 // Schedule last bit of work, it will get processed the last89 ReactNoop.renderToRootWithID(<span prop="a:2" />, 'a');90 // Keep performing work in the order it was scheduled91 ReactNoop.flushDeferredPri(15 + 5);92 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);93 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);94 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);95 ReactNoop.flushDeferredPri(15 + 5);96 expect(ReactNoop.getChildren('a')).toEqual([span('a:2')]);97 expect(ReactNoop.getChildren('b')).toEqual([span('b:2')]);98 expect(ReactNoop.getChildren('c')).toEqual([span('c:2')]);99 });100 it('schedules sync updates when inside componentDidMount/Update', () => {101 let instance;102 let ops = [];103 class Foo extends React.Component {104 state = {tick: 0};105 componentDidMount() {106 ops.push('componentDidMount (before setState): ' + this.state.tick);107 this.setState({tick: 1});108 // We're in a batch. Update hasn't flushed yet.109 ops.push('componentDidMount (after setState): ' + this.state.tick);110 }111 componentDidUpdate() {112 ops.push('componentDidUpdate: ' + this.state.tick);113 if (this.state.tick === 2) {114 ops.push('componentDidUpdate (before setState): ' + this.state.tick);115 this.setState({tick: 3});116 ops.push('componentDidUpdate (after setState): ' + this.state.tick);117 // We're in a batch. Update hasn't flushed yet.118 }119 }120 render() {121 ops.push('render: ' + this.state.tick);122 instance = this;123 return <span prop={this.state.tick} />;124 }125 }126 ReactNoop.render(<Foo />);127 ReactNoop.flushDeferredPri(20 + 5);128 expect(ops).toEqual([129 'render: 0',130 'componentDidMount (before setState): 0',131 'componentDidMount (after setState): 0',132 // If the setState inside componentDidMount were deferred, there would be133 // no more ops. Because it has Task priority, we get these ops, too:134 'render: 1',135 'componentDidUpdate: 1',136 ]);137 ops = [];138 instance.setState({tick: 2});139 ReactNoop.flushDeferredPri(20 + 5);140 expect(ops).toEqual([141 'render: 2',142 'componentDidUpdate: 2',143 'componentDidUpdate (before setState): 2',144 'componentDidUpdate (after setState): 2',145 // If the setState inside componentDidUpdate were deferred, there would be146 // no more ops. Because it has Task priority, we get these ops, too:147 'render: 3',148 'componentDidUpdate: 3',149 ]);150 });151 it('can opt-in to async scheduling inside componentDidMount/Update', () => {152 let instance;153 class Foo extends React.Component {154 state = {tick: 0};155 componentDidMount() {156 ReactNoop.deferredUpdates(() => {157 ReactNoop.yield(158 'componentDidMount (before setState): ' + this.state.tick,159 );160 this.setState({tick: 1});161 ReactNoop.yield(162 'componentDidMount (after setState): ' + this.state.tick,163 );164 });165 }166 componentDidUpdate() {167 ReactNoop.deferredUpdates(() => {168 ReactNoop.yield('componentDidUpdate: ' + this.state.tick);169 if (this.state.tick === 2) {170 ReactNoop.yield(171 'componentDidUpdate (before setState): ' + this.state.tick,172 );173 this.setState({tick: 3});174 ReactNoop.yield(175 'componentDidUpdate (after setState): ' + this.state.tick,176 );177 }178 });179 }180 render() {181 ReactNoop.yield('render: ' + this.state.tick);182 instance = this;183 return <span prop={this.state.tick} />;184 }185 }186 ReactNoop.flushSync(() => {187 ReactNoop.render(<Foo />);188 });189 // The cDM update should not have flushed yet because it has async priority.190 expect(ReactNoop.getChildren()).toEqual([span(0)]);191 // Now flush the cDM update.192 ReactNoop.clearYields();193 expect(ReactNoop.flush()).toEqual(['render: 1', 'componentDidUpdate: 1']);194 expect(ReactNoop.getChildren()).toEqual([span(1)]);195 // Increment the tick to 2. This will trigger an update inside cDU. Flush196 // the first update without flushing the second one.197 instance.setState({tick: 2});198 ReactNoop.flushThrough([199 'render: 2',200 'componentDidUpdate: 2',201 'componentDidUpdate (before setState): 2',202 'componentDidUpdate (after setState): 2',203 ]);204 expect(ReactNoop.getChildren()).toEqual([span(2)]);205 // Now flush the cDU update.206 expect(ReactNoop.flush()).toEqual(['render: 3', 'componentDidUpdate: 3']);207 expect(ReactNoop.getChildren()).toEqual([span(3)]);208 });209 it('performs Task work even after time runs out', () => {210 class Foo extends React.Component {211 state = {step: 1};212 componentDidMount() {213 this.setState({step: 2}, () => {214 this.setState({step: 3}, () => {215 this.setState({step: 4}, () => {216 this.setState({step: 5});217 });218 });219 });220 }221 render() {222 return <span prop={this.state.step} />;223 }224 }225 ReactNoop.render(<Foo />);226 // This should be just enough to complete all the work, but not enough to227 // commit it.228 ReactNoop.flushDeferredPri(20);229 expect(ReactNoop.getChildren()).toEqual([]);230 // Do one more unit of work.231 ReactNoop.flushDeferredPri(10);232 // The updates should all be flushed with Task priority233 expect(ReactNoop.getChildren()).toEqual([span(5)]);234 });235 it('can opt-out of batching using unbatchedUpdates', () => {236 ReactNoop.flushSync(() => {237 ReactNoop.render(<span prop={0} />);238 expect(ReactNoop.getChildren()).toEqual([]);239 // Should not have flushed yet because we're still batching240 // unbatchedUpdates reverses the effect of batchedUpdates, so sync241 // updates are not batched242 ReactNoop.unbatchedUpdates(() => {243 ReactNoop.render(<span prop={1} />);244 expect(ReactNoop.getChildren()).toEqual([span(1)]);245 ReactNoop.render(<span prop={2} />);246 expect(ReactNoop.getChildren()).toEqual([span(2)]);247 });248 ReactNoop.render(<span prop={3} />);249 expect(ReactNoop.getChildren()).toEqual([span(2)]);250 });251 // Remaining update is now flushed252 expect(ReactNoop.getChildren()).toEqual([span(3)]);253 });254 it('nested updates are always deferred, even inside unbatchedUpdates', () => {255 let instance;256 let ops = [];257 class Foo extends React.Component {258 state = {step: 0};259 componentDidUpdate() {260 ops.push('componentDidUpdate: ' + this.state.step);261 if (this.state.step === 1) {262 ReactNoop.unbatchedUpdates(() => {263 // This is a nested state update, so it should not be264 // flushed synchronously, even though we wrapped it265 // in unbatchedUpdates.266 this.setState({step: 2});267 });268 expect(ReactNoop.getChildren()).toEqual([span(1)]);269 }270 }271 render() {272 ops.push('render: ' + this.state.step);273 instance = this;274 return <span prop={this.state.step} />;275 }276 }277 ReactNoop.render(<Foo />);278 ReactNoop.flush();279 expect(ReactNoop.getChildren()).toEqual([span(0)]);280 ReactNoop.flushSync(() => {281 instance.setState({step: 1});282 });283 expect(ReactNoop.getChildren()).toEqual([span(2)]);284 expect(ops).toEqual([285 'render: 0',286 'render: 1',287 'componentDidUpdate: 1',288 'render: 2',289 'componentDidUpdate: 2',290 ]);291 });292 it('updates do not schedule a new callback if already inside a callback', () => {293 class Foo extends React.Component {294 state = {foo: 'foo'};295 UNSAFE_componentWillReceiveProps() {296 ReactNoop.yield(297 'has callback before setState: ' + ReactNoop.hasScheduledCallback(),...

Full Screen

Full Screen

specadd.js

Source:specadd.js Github

copy

Full Screen

...76 edbx=trbx.parentNode.insertBefore(edbx, trbx);77 edbx.trbx=trbx;78 edbx = $(edbx);79 trbx = $(trbx);80 edbx.getChildren('td')[0].innerHTML=trbx.getChildren('td')[0].innerHTML;81 edbx.getChildren('td')[1].innerHTML=trbx.getChildren('td')[1].innerHTML;82 edbx.getChildren('td')[2].innerHTML=genCat(ccid);83 edbx.getChildren('td')[3].innerHTML=genSubCat(ccid,ucid);84 edbx.className=pid?'es-payed':'';85 edbx.style.display='';86 trbx.style.display='none';87 if(sfrm=document.getElementById('saveSpecFrm')) {88 sfrm.oldprof_id.value=scid;89 sfrm.paid_id.value=pid;90 }91}92var movingSpec = null;93function moveSpec(itm, dir, mode, err, new_pid) {94 cleanEdit();95 itm = $(itm);96 if(itm) {97 if(movingSpec) return;98 from_el = itm.getParent('tr');99 if(!from_el.SPARAMS) return;100 to_el = dir < 0 ? from_el.getPrevious('tr') : from_el.getNext('tr');101 movingSpec = [from_el, to_el, dir];102 xajax_moveSpec(from_el.SPARAMS[0], from_el.SPARAMS[1], dir);103 return;104 }105 if(!err && movingSpec) {106 from_el = movingSpec[0];107 to_el = movingSpec[1];108 from_paid = from_el.hasClass('es-payed') && !to_el.hasClass('es-payed');109 to_paid = !from_el.hasClass('es-payed') && to_el.hasClass('es-payed');110 if(from_paid || to_paid) {111 //ïåðåìåùåíèå ìåæäó áëîêàìè112 q = dir < 0 ? 'tr[class!=es-payed][id!=editspec_box]' : 'tr[class=es-payed][id!=editspec_box]';113 rows = from_el.getParent().getElements(q);114 rows_n = dir < 0 ? 0 : rows.length-1;115 tl = dir < 0 ? to_el.getPrevious() : to_el.getNext();116 if(from_paid) {117 prl = from_el.getElement('img[src*=prolong-on]');118 if(prl) {119 prl.set('src', prl.get('src').replace('prolong-on', 'prolong-off'));120 }121 }122 if(!rows[rows_n].SPARAMS[1] ) {123 to_el = rows[rows_n];124 if(new_pid) to_el = $('paid' + new_pid);125 to_el.inject(from_el, (dir < 0 ? 'before' : 'after'));126 to_el.getChildren('td')[1].getChildren('img').setStyle('display', 'none');127 to_el.getChildren('td')[1].getChildren('a').setStyle('display', '');128 to_el_copy = to_el.clone();129 from_el_copy = from_el.clone();130 if(!from_el.SPARAMS[1]) {131 from_el.getChildren('td')[2].set('colspan', 1);132 from_el.insertCell(3);133 to_el.deleteCell(2);134 to_el.getChildren('td')[2].set('colspan', 2);135 }136 if(!to_el.SPARAMS[1]) {137 from_el.deleteCell(2);138 from_el.getChildren('td')[2].set('colspan', 2);139 to_el.getChildren('td')[2].set('colspan', 1);140 to_el.insertCell(3);141 }142 to_el.getChildren('td')[2].set('html', from_el_copy.getChildren('td')[2].get('html'));143 from_el.getChildren('td')[2].set('html', to_el_copy.getChildren('td')[2].get('html'));144 if(from_el.SPARAMS[1] && !to_el.SPARAMS[1]) {145 to_el.getChildren('td')[3].set('html', from_el_copy.getChildren('td')[3].get('html'));146 } else if (!from_el.SPARAMS[1] && to_el.SPARAMS[1]) {147 from_el.getChildren('td')[3].set('html', to_el_copy.getChildren('td')[3].get('html'));148 } else {149 from_el.getChildren('td')[3].set('html', to_el_copy.getChildren('td')[3].get('html'));150 to_el.getChildren('td')[3].set('html', from_el_copy.getChildren('td')[3].get('html'));151 }152 if(!to_el.SPARAMS[1] || !from_el.SPARAMS[1]) {153 if(from_paid && !to_el.getPrevious().SPARAMS[1]) {154 to_el.getChildren('td')[1].getChildren('img')[0].setStyle('display', '');155 to_el.getChildren('td')[1].getChildren('a')[0].setStyle('display', 'none');156 }157 if(to_paid && !to_el.getNext().SPARAMS[1]) {158 to_el.getChildren('td')[1].getChildren('img')[1].setStyle('display', '');159 to_el.getChildren('td')[1].getChildren('a')[1].setStyle('display', 'none');160 }161 from_el.inject(from_el.getParent(), (from_paid ? 'bottom' : 'top'));162 from_el.getChildren('td')[1].getChildren('img').setStyle('display', '');163 from_el.getChildren('td')[1].getChildren('a').setStyle('display', 'none');164 }165 ts = $A(to_el.SPARAMS);166 fs = $A(from_el.SPARAMS);167 for(i = 0; i < 4; i++){168 if((from_paid || to_paid) && i == 0) continue;169 to_el.SPARAMS[i] = fs[i];170 from_el.SPARAMS[i] = ts[i];171 }172 $each(from_el.getParent().getElements('tr[id!=editspec_box] td.es-c1'), function(el, i) {173 el.set('html', (i+1) + '.');174 });175 } else {176 to_el_copy = to_el.clone();177 from_el_copy = from_el.clone();178 if(!from_el.SPARAMS[1]) {179 from_el.getChildren('td')[2].set('colspan', 1);180 from_el.insertCell(3);181 to_el.deleteCell(2);182 to_el.getChildren('td')[2].set('colspan', 2);183 }184 if(!to_el.SPARAMS[1]) {185 from_el.deleteCell(2);186 from_el.getChildren('td')[2].set('colspan', 2);187 to_el.getChildren('td')[2].set('colspan', 1);188 to_el.insertCell(3);189 }190 to_el.getChildren('td')[2].set('html', from_el_copy.getChildren('td')[2].get('html'));191 from_el.getChildren('td')[2].set('html', to_el_copy.getChildren('td')[2].get('html'));192 if(from_el.SPARAMS[1] && !to_el.SPARAMS[1]) {193 to_el.getChildren('td')[3].set('html', from_el_copy.getChildren('td')[3].get('html'));194 } else if (!from_el.SPARAMS[1] && to_el.SPARAMS[1]) {195 from_el.getChildren('td')[3].set('html', to_el_copy.getChildren('td')[3].get('html'));196 } else {197 from_el.getChildren('td')[3].set('html', to_el_copy.getChildren('td')[3].get('html'));198 to_el.getChildren('td')[3].set('html', from_el_copy.getChildren('td')[3].get('html'));199 }200 ts = $A(to_el.SPARAMS);201 fs = $A(from_el.SPARAMS);202 for(i = 0; i < 4; i++){203 if((from_paid || to_paid) && i == 0) continue;204 to_el.SPARAMS[i] = fs[i];205 from_el.SPARAMS[i] = ts[i];206 }207 }208 } else {209 //ïåðåìåùåíèå âíóòðè áëîêîâ210// from_el.inject(to_el, dir < 0 ? 'before' : 'after');211 var ts = to_el.SPARAMS;212 var fs = from_el.SPARAMS;...

Full Screen

Full Screen

game.js

Source:game.js Github

copy

Full Screen

...36 // variable elements37 this.gapple = this.physics.add.sprite(Phaser.Math.Between(50, this.game.canvas.width-100),Phaser.Math.Between(50, this.game.canvas.height-100),'gapple') 38 this.gapple.setScale(0.3)39 // Interactions40 this.physics.add.overlap(this.snake, this.body.getChildren(),die, null, this);41 this.physics.add.overlap(this.snake, this.gapple, collectGreenApple, null, this);42 this.physics.add.overlap(this.snake, this.rapple, collectRedApple, null, this);43 this.physics.add.overlap(this.snake, this.walls, die, null, this);44 this.physics.add.overlap(this.body, this.walls, die, null, this);45 }46 47 update(){ 48 // handle direction change49 if (this.cursors.left.isDown & this.snake.body.velocity.x!=this.speed) {50 this.snake.body.setVelocityY(0);51 this.snake.body.setVelocityX(-this.speed);52 } else if (this.cursors.right.isDown & this.snake.body.velocity.x!=-this.speed) {53 this.snake.body.setVelocityY(0);54 this.snake.body.setVelocityX(this.speed);55 } else if (this.cursors.up.isDown & this.snake.body.velocity.y!=this.speed) {56 this.snake.body.setVelocityY(-this.speed);57 this.snake.body.setVelocityX(0);58 } else if(this.cursors.down.isDown & this.snake.body.velocity.y!=-this.speed){59 this.snake.body.setVelocityX(0);60 this.snake.body.setVelocityY(this.speed);61 }62 // Create a "tail" efect63 if(this.neck.getChildren().length>0){ 64 Phaser.Actions.ShiftPosition(this.neck.getChildren(), this.snake.x, this.snake.y,1);65 }66 if(this.tail.length>0){67 Phaser.Actions.ShiftPosition(this.tail, this.neck.getChildren()[this.neck.getChildren().length-1].x, this.neck.getChildren()[this.neck.getChildren().length-1].y);68 }69 // borders70 if(this.game.canvas.width-9==this.snake.x || this.snake.x ==9 || this.game.canvas.height-9==this.snake.y|| this.snake.y ==9 ){71 dead = true72 }73 if(dead){74 gameOver(this);75 }76 }77}78function die(){79 dead = true80}81function gameOver (game){82 // reset dead and launche try again menu83 dead = false;84 saveScore(game.apples)85 game.scene.pause()86 game.scene.bringToTop(DIRECTORY.SCENES.MENU)87 game.scene.launch(DIRECTORY.SCENES.MENU,"died")88}89function collectRedApple (snake,rapple)90{ 91 rapple.disableBody(true, true);92 let odd = Phaser.Math.Between(0,100)93 //94 // Reduce the tail/body size by 2 for every apple95 //96 if(this.neck.getChildren().length<2){97 die()98 }else{99 if(this.body.getChildren().length>=2){100 for (let i =0; i<2 ; i++) {101 let removed = this.body.getChildren()[this.body.getChildren().length-1];102 removed.disableBody(true,true) 103 this.body.remove(this.body.getChildren()[this.body.getChildren().length-1]);104 105 }106 }else if(this.body.getChildren().length>0){107 let removed = this.body.getChildren()[this.body.getChildren().length-1];108 removed.disableBody(true,true)109 this.body.remove(this.body.getChildren()[this.body.getChildren().length-1]);110 111 removed = this.neck.getChildren()[this.neck.getChildren().length-1];112 removed.disableBody(true,true)113 this.neck.remove(this.neck.getChildren()[this.neck.getChildren().length-1]);114 }else{115 for (let i = 0; i<2 ; i++) {116 let removed = this.neck.getChildren()[this.neck.getChildren().length-1];117 removed.disableBody(true,true) 118 this.neck.remove(this.neck.getChildren()[this.neck.getChildren().length-1]); 119 }120 }121 }122 //123 // 15% chance to generate a redApple when eating124 //125 if(odd<=15){126 this.rapple = this.physics.add.sprite(Phaser.Math.Between(50, this.game.canvas.width-50),Phaser.Math.Between(50, this.game.canvas.height-50),'rapple') 127 this.rapple.setScale(0.3)128 this.physics.add.overlap(snake, this.rapple, collectRedApple, null, this);129 } 130}131function collectGreenApple (snake)132{ //133 //Apple reaction134 //135 //collectRedApple()136 this.gapple.disableBody(true, true);137 this.apples += 1;138 this.scoreText.setText('score: ' + this.apples);139 this.gapple = this.physics.add.sprite(Phaser.Math.Between(50, this.game.canvas.width-50),Phaser.Math.Between(50, this.game.canvas.height-50),'gapple') 140 this.gapple.setScale(0.3) 141 this.physics.add.overlap(snake, this.gapple, collectGreenApple, null, this);142 //143 //Add tail elements144 //145 this.tail = this.body.getChildren();146 if(this.neck.getChildren().length>(snake.width/this.speed)*100){ 147 this.body.create(148 this.neck.getChildren()[this.neck.getChildren().length-1].x, 149 this.neck.getChildren()[this.neck.getChildren().length-1].y, 'snake'); 150 }151 else{ 152 this.neck.create(snake.x, snake.y, 'snake');153 }154 //155 // Every 10 points generate a wall in a random position156 //157 let vodd = Phaser.Math.Between(0,100)158 if(this.apples%10==0){159 this.walls = this.physics.add.sprite(Phaser.Math.Between(50, this.game.canvas.width-100),Phaser.Math.Between(50, this.game.canvas.height-100),'vWall')160 if(vodd<50){161 this.walls.angle=90162 this.walls.setSize(this.walls.height,this.walls.width)163 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...52 //variable elements53 Rapple = this.physics.add.sprite(Phaser.Math.Between(0, this.game.canvas.width-100),Phaser.Math.Between(0, this.game.canvas.height-100),'rapple') 54 Gapple = this.physics.add.sprite(Phaser.Math.Between(0, this.game.canvas.width-100),Phaser.Math.Between(0, this.game.canvas.height-100),'gapple') 55 //Interactions56 this.physics.add.collider(snake, this.body.getChildren(),die, null, this);57 this.physics.add.overlap(snake, Gapple, collectGreenApple, null, this);58 this.physics.add.overlap(snake, Rapple, collectRedApple, null, this); 59}60function gameOver (game){61 menu(game);62 game.scene.pause();63}64function die(){65 dead = true66}67function collectGreenApple (snake, gapple)68{ //69 //Apple reaction70 //71 //collectRedApple()72 gapple.disableBody(true, true);73 apples += 1;74 scoreText.setText('apples: ' + apples);75 Gapple = this.physics.add.sprite(Phaser.Math.Between(0, this.game.canvas.width+1),Phaser.Math.Between(0, this.game.canvas.height+1),'gapple') 76 this.physics.add.overlap(snake, Gapple, collectGreenApple, null, this);77 //78 //Add tail elements79 //80 tail = this.body.getChildren();81 if(this.neck.getChildren().length>(snake.width/speed)*100){ 82 this.body.create(83 this.neck.getChildren()[this.neck.getChildren().length-1].x, 84 this.neck.getChildren()[this.neck.getChildren().length-1].y, 'neck'); 85 }86 else{ 87 this.neck.create(snake.x, snake.y, 'neck');88 }89 //90 // 15% chance to generate a redApple when eating91 //92 odd = Phaser.Math.Between(0,100)93 if(odd<=15){94 Rapple = this.physics.add.sprite(Phaser.Math.Between(0, this.game.canvas.width-100),Phaser.Math.Between(0, this.game.canvas.height-100),'rapple') 95 this.physics.add.overlap(snake, Rapple, collectRedApple, null, this);96 }97}98function collectRedApple (snake,rapple)99{ 100 rapple.disableBody(true, true);101 odd = Phaser.Math.Between(0,100)102 if(this.neck.getChildren().length<2){103 console.log("You died because you can't be smaller")104 die()105 }else{106 if(this.body.getChildren().length>2){107 for (let i =0; i<2 ; i++) {108 let removed = this.body.getChildren()[this.body.getChildren().length-1];109 removed.disableBody(true,true)110 this.body.remove(this.body.getChildren().length-1);111 }112 }else if(this.body.getChildren().length>0){113 let count = 0;114 for (let i = 0; i<this.body.getChildren().length-1 ; i++) {115 let removed = this.body.getChildren()[this.body.getChildren().length-1];116 removed.disableBody(true,true)117 this.body.remove(this.body.remove(this.body.getChildren().length-1));118 count++;119 }120 if(count!=2){121 let removed = this.neck.getChildren()[this.neck.getChildren().length-1];122 removed.disableBody(true,true)123 this.neck.remove(this.neck.getChildren()[this.neck.getChildren().length-1]);124 }125 }else{126 for (let i = 0; i<2 ; i++) {127 let removed = this.neck.getChildren()[this.neck.getChildren().length-1];128 removed.disableBody(true,true)129 this.neck.remove(this.neck.getChildren()[this.neck.getChildren().length-1]);130 }131 }132 }133 //134 // 15% chance to generate a redApple when eating135 //136 if(odd<=100){137 Rapple = this.physics.add.sprite(Phaser.Math.Between(0, this.game.canvas.width-100),Phaser.Math.Between(0, this.game.canvas.height-100),'rapple') 138 this.physics.add.overlap(snake, Rapple, collectRedApple, null, this);139 } 140}141function update(){ 142 143 if (cursors.left.isDown & snake.body.velocity.x!=speed) {144 snake.body.setVelocityY(0);145 snake.body.setVelocityX(-speed);146 } else if (cursors.right.isDown & snake.body.velocity.x!=-speed) {147 snake.body.setVelocityY(0);148 snake.body.setVelocityX(speed);149 } else if (cursors.up.isDown & snake.body.velocity.y!=speed) {150 snake.body.setVelocityY(-speed);151 snake.body.setVelocityX(0);152 } else if(cursors.down.isDown & snake.body.velocity.y!=-speed){153 snake.body.setVelocityX(0);154 snake.body.setVelocityY(speed);155 } 156 //Create a "tail" efect157 if(this.neck.getChildren().length>0){ 158 Phaser.Actions.ShiftPosition(this.neck.getChildren(), snake.x, snake.y,1);159 }160 if(tail.length>0){161 Phaser.Actions.ShiftPosition(tail, this.neck.getChildren()[this.neck.getChildren().length-1].x, this.neck.getChildren()[this.neck.getChildren().length-1].y);162 }163 //borders164 if(this.game.canvas.width-9==snake.x || snake.x ==9 || this.game.canvas.height-9==snake.y|| snake.y ==9 ){165 dead = true166 }167 if(dead){168 gameOver(this);169 }170}171function menu(game){172 var play = game.add.sprite(this.game.canvas.width/2,this.game.canvas.height/2,'play').setDepth(0);173 play.setScale(0.5)...

Full Screen

Full Screen

Toolbar.js

Source:Toolbar.js Github

copy

Full Screen

...28 {29 var self = this;30 // test run event31 this.assertEventFired(this.__toolbar, "run", function() {32 self.__toolbar.getChildren()[0].execute();33 }, function() {});34 // test highlithing event35 this.assertEventFired(this.__toolbar, "changeHighlight", function() {36 self.__toolbar.getChildren()[2].execute();37 }, function() {});38 // test log event39 this.assertEventFired(this.__toolbar, "changeLog", function() {40 self.__toolbar.getChildren()[5].execute();41 }, function() {});42 // test shorten event43 this.assertEventFired(this.__toolbar, "shortenUrl", function() {44 self.__toolbar.getChildren()[6].execute();45 }, function() {});46 // test api event47 this.assertEventFired(this.__toolbar, "openApi", function() {48 self.__toolbar.getChildren()[7].execute();49 }, function() {});50 // test manual event51 this.assertEventFired(this.__toolbar, "openManual", function() {52 self.__toolbar.getChildren()[8].execute();53 }, function() {});54 },55 testExampleMenu : function()56 {57 var menuButton = this.__toolbar.getChildren()[1];58 var menu = menuButton.getMenu();59 this.assertEquals(menu.getChildren()[0].getLabel(), "one");60 this.assertEquals(menu.getChildren()[1].getLabel(), "two");61 this.assertEquals(menu.getChildren()[2].getLabel(), "three");62 },63 testGistMenu : function() {64 var menuButton = this.__toolbar.getChildren()[3];65 var menu = menuButton.getMenu();66 var self = this;67 // test newGist event68 this.assertEventFired(this.__toolbar, "newGist", function() {69 menu.getChildren()[2].execute();70 }, function() {});71 // test invalid gist72 this.__toolbar.invalidGist(true, "affe");73 this.assertFalse(menu.getChildren()[0]._getChildren()[1].isValid());74 this.assertEquals("affe", menu.getChildren()[0]._getChildren()[1].getInvalidMessage());75 // test show gists76 this.__toolbar.updateGists(["one [qx]", "two"], ["eins", "zwei"], [1, 2]);77 this.assertEquals("one [qx]", menu.getChildren()[4].getLabel());78 // switch filter79 menu.getChildren()[1].setValue(false);80 this.assertEquals("two", menu.getChildren()[5].getLabel());81 // test changeGist event82 this.assertEventFired(this.__toolbar, "changeGist", function() {83 menu.getChildren()[4].execute();84 }, function(e) {85 self.assertEquals(e.getData().code, "eins");86 self.assertEquals(e.getData().name, "one [qx]");87 });88 }89 }...

Full Screen

Full Screen

ve.dm.DocumentSynchronizer.test.js

Source:ve.dm.DocumentSynchronizer.test.js Github

copy

Full Screen

...31 doc.data[ 13 ] = [ 'd', new ve.dm.AnnotationSet( doc.getStore(),32 doc.getStore().index( new ve.dm.ItalicAnnotation() ) )33 ];34 ds.pushAnnotation( new ve.Range( 10, 11 ) );35 doc.getDocumentNode().getChildren()[ 0 ].getChildren()[ 0 ].on( 'update', function () {36 firstTextNodeUpdates++;37 } );38 doc.getDocumentNode().getChildren()[ 0 ].getChildren()[ 0 ].on( 'annotation', function () {39 firstTextNodeAnnotations++;40 } );41 doc.getDocumentNode().getChildren()[ 0 ].getChildren()[ 0 ].on( 'lengthChange', function ( diff ) {42 firstTextNodeLengthChanges.push( diff );43 } );44 doc.getDocumentNode().getChildren()[ 1 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ]45 .on( 'update', function () {46 secondTextNodeUpdates++;47 } );48 doc.getDocumentNode().getChildren()[ 1 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ]49 .on( 'annotation', function () {50 secondTextNodeAnnotations++;51 } );52 doc.getDocumentNode().getChildren()[ 1 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ].getChildren()[ 0 ]53 .on( 'lengthChange', function ( diff ) {54 secondTextNodeLengthChanges.push( diff );55 } );56 ds.synchronize();57 // TODO technically this should be 1, not 2, see DocumentSynchronizer.synchronizers.resize58 assert.deepEqual( firstTextNodeUpdates, 2, 'annotation and insertion each trigger update event (1st paragraph)' );59 assert.deepEqual( firstTextNodeAnnotations, 1, 'annotation triggers annotation event (1st paragraph)' );60 assert.deepEqual( firstTextNodeLengthChanges, [ 3 ], 'insertion triggers lengthChange event (1st paragraph)' );61 assert.deepEqual( secondTextNodeUpdates, 1, 'annotation triggers update event (2nd paragraph)' );62 assert.deepEqual( secondTextNodeAnnotations, 1, 'annotation triggers annotation event (2nd paragraph)' );63 assert.deepEqual( secondTextNodeLengthChanges, [], 'lengthChange not triggered for 2nd paragraph' );...

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 page = await browser.newPage();5 const children = await page._getChildren();6 console.log(children);7 await browser.close();8})();9 Page {10 _browserContext: BrowserContext {11 },12 _pageBindings: Map {},13 _timeoutSettings: TimeoutSettings { _defaultTimeout: 30000 },14 _workers: Set {},15 _downloads: Set {},16 _routes: Set {},17 _browserListeners: {18 },19 _didCloseOrCrashPromise: Promise { <pending> },20 _didCloseOrCrashResolveCallback: [Function (anonymous)],21 _didCloseOrCrashRejectCallback: [Function (anonymous)],22 _closePromise: Promise { <pending> },23 _closeCallback: [Function (anonymous)],24 _didCloseCallback: [Function (anonymous)],25 _closedOrCrashedPromise: Promise { <pending> },26 _closedOrCrashedCallback: [Function (anonymous)],27 _popupTaskQueue: TaskQueue {28 _chain: Promise { <pending> },

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 children = await elementHandle._getChildren();7 console.log(children.length);8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const page = await browser.newPage();14 const elementHandle = await page.$('text=Get started');15 const children = await elementHandle._getChildren();16 console.log(children.length);17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch();22 const page = await browser.newPage();23 const elementHandle = await page.$('text=Get started');24 const children = await elementHandle.$$eval('*', (nodes) => nodes.length);25 console.log(children);26 await browser.close();27})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {getChildren} = require('playwright/lib/server/chromium/crPage');2const {chromium} = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const children = await getChildren(page);8 console.log(children);9 await browser.close();10})();11 {12 },13 {14 }15const children = await getChildren(page, { selector: 'body' });16console.log(children);17 {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { chromium } from "playwright";2import { getChildren } from "playwright/lib/server/dom";3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const children = await getChildren(page, "document.body");7 console.log(children);8 await browser.close();9})();10import { chromium } from "playwright";11import { getInnerText } from "playwright/lib/server/dom";12(async () => {13 const browser = await chromium.launch();14 const page = await browser.newPage();15 const innerText = await getInnerText(page, "document.body");16 console.log(innerText);17 await browser.close();18})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 const searchBar = await page.$('#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input');7 const children = await searchBar._getChildren();8 console.log(children);9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getChildren } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const children = await getChildren(page, page.mainFrame());8 console.log(children);9 await browser.close();10})();11 {12 attributes: { 'aria-label': 'Playwright' },13 },14 {15 attributes: { 'aria-label': 'GitHub' },16 },17 {18 attributes: { 'aria-label': 'Twitter' },19 },20 {21 attributes: { 'aria-label': 'YouTube' },22 },23 {24 attributes: { 'aria-label': 'Slack' },25 },26 {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getChildren } = require('playwright/lib/utils/locator');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const elements = await getChildren(page, '.gLFyf');7 console.log(elements.length);8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getChildren } = require('@playwright/test/lib/server/frames');2const { test, expect } = require('@playwright/test');3test('getChildren', async ({ page }) => {4 const children = await getChildren(page.mainFrame());5 expect(children.length).toBeGreaterThan(0);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getChildren } = require('playwright');2(async () => {3 const children = await getChildren();4 console.log(children);5})();6[ { pid: 2724, ppid: 1, name: 'node' },7 { pid: 2725, ppid: 2724, name: 'node' },8 { pid: 2726, ppid: 2724, name: 'node' },9 { pid: 2727, ppid: 2724, name: 'node' },10 { pid: 2728, ppid: 2724, name: 'node' },11 { pid: 2729, ppid: 2724, name: 'node' },12 { pid: 2730, ppid: 2724, name: 'node' },13 { pid: 2731, ppid: 2724, name: 'node' },14 { pid: 2732, ppid: 2724, name: 'node' },15 { pid: 2733, ppid: 2724, name: 'node' },16 { pid: 2734, ppid: 2724, name: 'node' },17 { pid: 2735, ppid: 2724, name: 'node' },18 { pid: 2736, ppid: 2724, name: 'node' },19 { pid: 2737, ppid: 2724, name: 'node' },20 { pid: 2738, ppid: 2724, name: 'node' },21 { pid: 2739, ppid: 2724, name: 'node' } ]22const { getChildren } = require('playwright');23(async () => {24 const children = await getChildren();25 const browserProcess = children.find((child) => child.name === 'node');26 console.log(browserProcess);27})();28{ pid: 2725, ppid:

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