Best JavaScript code snippet using playwright-internal
petriNetSoundnessChecker.js
Source:petriNetSoundnessChecker.js
1/**2 * Copyright (c) 20093 * Kai Schlichting4 *5 * Permission is hereby granted, free of charge, to any person obtaining a6 * copy of this software and associated documentation files (the "Software"),7 * to deal in the Software without restriction, including without limitation8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,9 * and/or sell copies of the Software, and to permit persons to whom the10 * Software is furnished to do so, subject to the following conditions:11 *12 * The above copyright notice and this permission notice shall be included in13 * all copies or substantial portions of the Software.14 *15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21 * DEALINGS IN THE SOFTWARE.22 **/23Ext.ns("Oryx.Plugins");2425ORYX.Plugins.PetriNetSoundnessChecker = ORYX.Plugins.AbstractPlugin.extend({2627 hideOverlays: function(){28 //TODO set in constructor!!!29 if(!this.overlayIds) 30 return;31 32 Ext.each(this.overlayIds, function(overlayId){33 this.facade.raiseEvent({34 type: ORYX.CONFIG.EVENT_OVERLAY_HIDE,35 id: overlayId36 });37 }.bind(this));38 },39 40 getChildShapesByResourceIds: function(resourceIds){41 var shapes = [];42 43 Ext.each(resourceIds, function(resourceId){44 shapes.push(this.facade.getCanvas().getChildShapeByResourceId(resourceId));45 }.bind(this));46 47 return shapes;48 },49 50 /**51 Show overlay on given shape.52 @methodOf ORYX.Plugins.AbstractPlugin.prototype53 @example54 showOverlay(55 myShape,56 { stroke: "green" },57 ORYX.Editor.graft("http://www.w3.org/2000/svg", null, ['path', {58 "title": "Click the element to execute it!",59 "stroke-width": 2.0,60 "stroke": "black",61 "d": "M0,-5 L5,0 L0,5 Z",62 "line-captions": "round"63 }])64 )65 @param {Oryx.XXX.Shape[]} shapes One shape or array of shapes the overlay should be put on66 @param {Oryx.XXX.Attributes} attributes some attributes...67 @param {Oryx.svg.node} svgNode The svg node which should be used as overlay68 @param {String} [svgNode="NW"] The svg node position where the overlay should be placed69 */70 showOverlay: function(shapes, attributes, svgNode, svgNodePosition ){71 if(!this.overlayIds){72 this.overlayIds = [];73 }74 75 if( !(shapes instanceof Array) ){76 shapes = [shapes]77 }78 79 // Define Shapes80 shapes = shapes.map(function(shape){81 var el = shape;82 if( typeof shape == "string" ){83 el = this.facade.getCanvas().getChildShapeByResourceId( shape );84 el = el || this.facade.getCanvas().getChildById( shape, true );85 }86 return el;87 }.bind(this)).compact();88 89 // Define unified id90 var overlayId = this.type + ORYX.Editor.provideId();91 this.overlayIds.push(overlayId);92 93 this.facade.raiseEvent({94 type : ORYX.CONFIG.EVENT_OVERLAY_SHOW,95 id : overlayId,96 shapes : shapes,97 attributes : attributes,98 node : svgNode,99 nodePosition: svgNodePosition || "NW"100 });101 102 },103104 // Offers the plugin functionality105 construct: function(facade){106 // Call super class constructor107 arguments.callee.$.construct.apply(this, arguments);108 109 this.facade.offer({110 'name': "Check soundness",//ORYX.I18N.BPMN2PNConverter.name,111 'functionality': this.showCheckerWindow.bind(this),112 'group': "Verification",113 'icon': ORYX.PATH + "images/checker_validation.png",114 'description': "Checks current Petri net for different soundness criteria.",115 'index': 3,116 'minShape': 0,117 'maxShape': 0118 });119 },120 121 showCheckerWindow: function(){122 var plugin = this;123 124 var CheckNode = Ext.extend(Ext.tree.TreeNode, {125 constructor: function(config) {126 if(!config.icon && !this.icon)127 config.icon = CheckNode.UNKNOWN_STATUS;128129 CheckNode.superclass.constructor.apply(this, arguments);130 131 Ext.apply(this, config);132 133 if(this.clickHandler){134 this.on('click', this.clickHandler.bind(this));135 }136 },137138 setIcon: function(status) {139 this.ui.getIconEl().src = status;140 },141 getIcon: function(status) {142 return this.ui.getIconEl().src;143 },144 reset: function(){145 plugin.hideOverlays();146 this.hideMarking();147 // Reset syntax errors148 plugin.facade.raiseEvent({type: ORYX.Plugins.SyntaxChecker.RESET_ERRORS_EVENT});149 },150 hideMarking: function(){151 if(!plugin.marking)152 return;153 154 for(place in plugin.marking){155 var placeShape = plugin.facade.getCanvas().getChildShapeByResourceId(place);156 if(placeShape)//place can be null if removed157 placeShape.setProperty("oryx-numberoftokens", 0);158 }159 // Show changes160 plugin.facade.getCanvas().update();161 162 plugin.marking = undefined;163 },164 showMarking: function(marking){165 plugin.marking = marking;166 167 for(place in marking){168 var placeShape = plugin.facade.getCanvas().getChildShapeByResourceId(place);169 placeShape.setProperty("oryx-numberoftokens", marking[place]);170 }171 // Show changes172 plugin.facade.getCanvas().update();173 },174 showErrors: function(errors){175 // Remove all old error nodes176 Ext.each(this.childNodes, function(child){177 if(child && child.itemCls === 'error')178 child.remove();179 });180 181 // Show Unknown status on child nodes182 Ext.each(this.childNodes, function(childNode){183 // Only change icon if it is in loading state (otherwise structural soundness icon would be replaced)184 if(childNode.getIcon().search(CheckNode.LOADING_STATUS) > -1){185 childNode.setIcon(CheckNode.UNKNOWN_STATUS);186 }187 });188 189 // Show errors190 Ext.each(errors, function(error){191 this.insertBefore(new CheckNode({192 icon: CheckNode.ERROR_STATUS,193 text: error,194 itemCls: 'error'195 }), this.childNodes[0]);196 }.bind(this));197 },198 showOverlayWithStep: function(shapeIds){199 Ext.each(shapeIds, function(shapeId, index){200 plugin.showOverlay(201 plugin.facade.getCanvas().getChildShapeByResourceId(shapeId), 202 {203 fill: "#FB7E02"//orange204 },205 ORYX.Editor.graft("http://www.w3.org/2000/svg", null, ['text', {206 "style": "font-size: 16px; font-weight: bold;"207 }, (index + 1)+"."]),208 "SE" //position in south east209 );210 });211 },212 showOverlay: function(shapes){213 if(shapes.length === 0)214 return;215216 if(! shapes[0] instanceof ORYX.Core.Node)217 shapes = plugin.getChildShapesByResourceIds(shapes)218 219 plugin.showOverlay(220 shapes, 221 {222 fill: "#FB7E02"//orange223 }224 );225 }226 });227 CheckNode.UNKNOWN_STATUS = ORYX.PATH + 'images/soundness_checker/' + 'asterisk_yellow.png';228 CheckNode.ERROR_STATUS = ORYX.PATH + 'images/soundness_checker/' + 'exclamation.png';229 CheckNode.OK_STATUS = ORYX.PATH + 'images/soundness_checker/' + 'accept.png';230 CheckNode.LOADING_STATUS = ORYX.PATH + 'images/soundness_checker/' + 'loading.gif';231 232 var DeadLocksNode = Ext.extend(CheckNode, {233 constructor: function(config) {234 config.qtip = '<b>Termination Criteria</b>: Makes sure that any process instance that starts in the initial state will eventually reach the final state. If any dead locks are detected, click to show one counter example.';235 236 DeadLocksNode.superclass.constructor.apply(this, arguments);237 },238 clickHandler: function(node){239 node.reset();240 241 if(this.deadLocks.length == 0) return;242 243 var deadLock = node.deadLocks[0];244 this.showOverlayWithStep(deadLock.path);245 this.showMarking(deadLock.marking);246 },247 update: function(deadLocks){248 this.deadLocks = deadLocks;249 this.setIcon(this.deadLocks.length == 0 ? CheckNode.OK_STATUS : CheckNode.ERROR_STATUS);250 this.setText('There is '+(this.deadLocks.length == 0 ? 'no' : 'a')+' path that leads to a deadlock.');251 }252 });253 254 var ImproperTerminatingsNode = Ext.extend(CheckNode, {255 constructor: function(config) {256 config.qtip = '<b>Proper Termination Criteria</b>: The final state is the only state reachable from the initial state in which there is a token in the final place. If any improper terminating states are detected, click to show one counter example.';257 258 ImproperTerminatingsNode.superclass.constructor.apply(this, arguments);259 },260 clickHandler: function(node){261 node.reset();262 263 if(node.improperTerminatings.length == 0) return;264 265 var improperTerminating = node.improperTerminatings[0];266 this.showOverlayWithStep(improperTerminating.path);267 this.showMarking(improperTerminating.marking);268 },269 update: function(improperTerminatings){270 this.improperTerminatings = improperTerminatings;271 272 this.setIcon(this.improperTerminatings.length == 0 ? CheckNode.OK_STATUS : CheckNode.ERROR_STATUS);273 this.setText('There are ' + this.improperTerminatings.length +' markings covering the final marking.');274 }275 });276 277 var DeadTransitionsNode = Ext.extend(CheckNode, {278 constructor: function(config) {279 config.qtip = '<b>No Dead Transitions Criteria</b>: Each transition can contribute to at least one process instance. Click to see all dead transitions.';280 281 DeadTransitionsNode.superclass.constructor.apply(this, arguments);282 },283 clickHandler: function(node){284 node.reset();285 286 this.showOverlay(this.deadTransitions);287 },288 update: function(deadTransitions){289 this.deadTransitions = deadTransitions;290 291 this.setIcon(this.deadTransitions.length == 0 ? CheckNode.OK_STATUS : CheckNode.ERROR_STATUS);292 this.setText('There are ' + this.deadTransitions.length +' dead transitions.');293 }294 });295 296 var NotParticipatingTransitionsNode = Ext.extend(CheckNode, {297 constructor: function(config) {298 config.qtip = '<b>Transition Participation Criteria</b>: Each transition participates in at least one process instance that starts in the initial state and reaches the final state. Click to see all transitions not participating in any process instance.';299 300 NotParticipatingTransitionsNode.superclass.constructor.apply(this, arguments);301 },302 clickHandler: function(node){303 node.reset();304 305 this.showOverlay(this.notParticipatingTransitions);306 },307 update: function(notParticipatingTransitions){308 this.notParticipatingTransitions = notParticipatingTransitions;309 310 this.setIcon(this.notParticipatingTransitions.length == 0 ? CheckNode.OK_STATUS : CheckNode.ERROR_STATUS);311 this.setText('There are ' + this.notParticipatingTransitions.length +' transitions that cannot participate in a properly terminating firing sequence.');312 }313 });314 315 this.checkerWindow = new Ext.Window({316 title: 'Soundness Checker',317 autoScroll: true,318 width: '500',319 tbar: [320 {321 text: 'Check', 322 handler: function(){323 this.checkerWindow.check();324 }.bind(this)325 },326 {327 text: 'Hide Errors', 328 handler: function(){329 this.checkerWindow.getTree().getRootNode().reset();330 }.bind(this)331 },332 '->',333 {334 text: 'Close', 335 handler: function(){336 this.checkerWindow.close();337 }.bind(this)338 }339 ],340 getTree: function(){341 return this.items.get(0);342 },343 check: function(renderAll){344 this.prepareCheck(renderAll);345 this.checkSyntax(this.checkSoundness.bind(this));346 },347 prepareCheck: function(renderAll){//call with renderAll=true if showing for the first time348 var root = this.getTree().getRootNode();349 350 root.reset();351 352 // Set loading status to all child nodes353 Ext.each(root.childNodes, function(childNode){354 if(renderAll)//this expands all nodes so they're rendered a first time355 childNode.expand(true);356 childNode.collapse(true); //collapse deeply357 childNode.setIcon(CheckNode.LOADING_STATUS);358 });359 },360 checkSyntax: function(callback){361 plugin.facade.raiseEvent({362 type: ORYX.Plugins.SyntaxChecker.CHECK_FOR_ERRORS_EVENT,363 onErrors: function(){364 Ext.Msg.alert("Syntax Check", "Some syntax errors have been found, please correct them!")365 this.turnLoadingIntoUnknownStatus();366 }.bind(this),367 onNoErrors: function(){368 callback();369 }370 });371 },372 // All child nodes with loading status get unknown status373 turnLoadingIntoUnknownStatus: function(){374 Ext.each(this.getTree().getRootNode().childNodes, function(childNode){375 // Only change icon if it is in loading state (otherwise structural soundness icon would be replaced)376 if(childNode.getIcon().search(CheckNode.LOADING_STATUS) > -1){377 childNode.setIcon(CheckNode.UNKNOWN_STATUS);378 }379 });380 },381 checkSoundness: function(){382 var root = this.getTree().getRootNode();383 384 // Check for structural soundness (no server request needed and return, if any has been found 385 if(! root.findChild("id", "structuralSound").check()){386 this.turnLoadingIntoUnknownStatus();387 return;388 }389 390 // Check other soundness criteria which needs server requests391 Ext.Ajax.request({392 url: ORYX.CONFIG.ROOT_PATH + 'checksoundness',393 method: 'POST',394 success: function(request){395 var res = Ext.decode(request.responseText);396 397 root.showErrors(res.errors);398 399 if(res.errors.length === 0){400 root.findChild("id", "sound").check(res);401 root.findChild("id", "weakSound").check(res);402 root.findChild("id", "relaxedSound").check(res);403 }404 },405 failure: function(){406 },407 params: {408 data: plugin.getSerializedDOM()409 }410 });411 412 },413 items: [new Ext.tree.TreePanel({414 useArrows: true,415 autoScroll: true,416 rootVisible: false,417 animate: true,418 containerScroll: true,419 420 root: new CheckNode({421 text: 'Checks',422 id: 'source',423 expanded: true424 }),425 listeners: {426 render: function(treePanel){427 var structuralSoundNode = new CheckNode({428 text: 'Structural Sound (Workflow Net)',429 id: 'structuralSound',430 /* Returns false when any error has been found */431 check: function(){432 this.checkInitialNode.update();433 this.checkFinalNode.update();434 this.checkConnectedNode.update(this.checkInitialNode.initialNodes, this.checkFinalNode.finalNodes);435 436 if(this.checkInitialNode.hasErrors() || this.checkFinalNode.hasErrors() || this.checkConnectedNode.hasErrors()){437 this.setIcon(CheckNode.ERROR_STATUS);438 this.expand();439 return false;440 } else {441 this.setIcon(CheckNode.OK_STATUS);442 return true;443 }444 },445 checkInitialNode: new CheckNode({446 qtip: 'There must be exactly one initial place, which is the only place without any incoming edges.',447 update: function(){448 this.initialNodes = [];449 Ext.each(plugin.facade.getCanvas().getChildShapes(), function(shape){450 if(shape.getIncomingShapes().length == 0 && shape.getStencil().id().search(/Place/) > -1){451 this.initialNodes.push(shape);452 }453 }.bind(this));454 455 this.setText(this.initialNodes.length + ' initial places found.');456 457 this.setIcon(!this.hasErrors() ? CheckNode.OK_STATUS : CheckNode.ERROR_STATUS);458 },459 clickHandler: function(node){460 node.reset();461 462 this.showOverlay(this.initialNodes);463 },464 hasErrors: function(){465 return this.initialNodes.length !== 1;466 }467 }),468 checkFinalNode: new CheckNode({469 qtip: 'There must be exactly one final place, which is the only place without any outgoing edges.',470 update: function(){471 this.finalNodes = [];472 Ext.each(plugin.facade.getCanvas().getChildShapes(), function(shape){473 if(shape.getOutgoingShapes().length == 0 && shape.getStencil().id().search(/Place/) > -1){474 this.finalNodes.push(shape);475 }476 }.bind(this));477 478 this.setText(this.finalNodes.length + ' final places found.');479 480 this.setIcon(!this.hasErrors() ? CheckNode.OK_STATUS : CheckNode.ERROR_STATUS);481 },482 clickHandler: function(node){483 node.reset();484 485 this.showOverlay(this.finalNodes);486 },487 hasErrors: function(){488 return this.finalNodes.length !== 1;489 }490 }),491 checkConnectedNode: new CheckNode({492 qtip: 'Each node in the process model is on the path from the initial node to the final node.',493 update: function(initialNodes, finalNodes){494 //Step through without semantic knowledge495 if(initialNodes.length !== 1 || finalNodes.length !== 1){496 this.setText("There must be exactly one initial and final place to perform further checks!");497 this.setIcon(CheckNode.UNKNOWN_STATUS);498 return;499 }500 501 this.notParticipatingNodes = [];502 Ext.each(plugin.facade.getCanvas().getChildShapes(), function(shape){503 if(shape instanceof ORYX.Core.Node)504 this.notParticipatingNodes.push(shape);505 }.bind(this));506 507 this.passedNodes = [];508 509 this.findNotParticipatingNodes(initialNodes[0]);510 511 this.setText(this.notParticipatingNodes.length + ' nodes that aren\'t on any path from beginning to end found.');512 513 this.setIcon(!this.hasErrors() ? CheckNode.OK_STATUS : CheckNode.ERROR_STATUS);514 },515 clickHandler: function(node){516 node.reset();517 518 this.showOverlay(this.notParticipatingNodes);519 },520 findNotParticipatingNodes: function(currentNode){521 this.passedNodes.push(currentNode);522 this.notParticipatingNodes.remove(currentNode);523 524 Ext.each(currentNode.getOutgoingShapes(), function(nextNode){525 if(!this.passedNodes.include(nextNode)){526 this.findNotParticipatingNodes(nextNode);527 };528 }.bind(this));529 },530 hasErrors: function(){531 return this.notParticipatingNodes.length !== 0;532 }533 })534 });535 structuralSoundNode.appendChild([536 structuralSoundNode.checkInitialNode,537 structuralSoundNode.checkFinalNode,538 structuralSoundNode.checkConnectedNode539 ]);540 541 var soundNode = new CheckNode({542 text: 'Sound',543 id: 'sound',544 check: function(res){545 if (res.isSound) {546 this.setIcon(CheckNode.OK_STATUS);547 }548 else {549 this.setIcon(CheckNode.ERROR_STATUS);550 this.expand();551 }552 553 this.deadTransitionsNode.update(res.deadTransitions);554 this.improperTerminatingsNode.update(res.improperTerminatings);555 this.deadLocksNode.update(res.deadLocks);556 },557 deadTransitionsNode: new DeadTransitionsNode({}),558 improperTerminatingsNode: new ImproperTerminatingsNode({}),559 deadLocksNode: new DeadLocksNode({})560 });561 soundNode.appendChild([562 soundNode.deadTransitionsNode,563 soundNode.improperTerminatingsNode,564 soundNode.deadLocksNode565 ]);566 567 var weakSoundNode = new CheckNode({568 text: 'Weak Sound',569 id: 'weakSound',570 check: function(res){571 if (res.isWeakSound) {572 this.setIcon(CheckNode.OK_STATUS);573 }574 else {575 this.setIcon(CheckNode.ERROR_STATUS);576 this.expand();577 }578579 this.improperTerminatingsNode.update(res.improperTerminatings);580 this.deadLocksNode.update(res.deadLocks);581 },582 deadTransitionsNode: new DeadTransitionsNode({}),583 improperTerminatingsNode: new ImproperTerminatingsNode({}),584 deadLocksNode: new DeadLocksNode({})585 });586 weakSoundNode.appendChild([587 weakSoundNode.improperTerminatingsNode,588 weakSoundNode.deadLocksNode589 ]);590 591 var relaxedSoundNode = new CheckNode({592 text: 'Relaxed Sound',593 id: 'relaxedSound',594 check: function(res){595 if (res.isRelaxedSound) {596 this.setIcon(CheckNode.OK_STATUS);597 }598 else {599 this.setIcon(CheckNode.ERROR_STATUS);600 this.expand();601 }602 603 this.notParticipatingTransitionsNode.update(res.notParticipatingTransitions);604 },605 notParticipatingTransitionsNode: new NotParticipatingTransitionsNode({})606 });607 relaxedSoundNode.appendChild([608 relaxedSoundNode.notParticipatingTransitionsNode609 ]);610 611 treePanel.getRootNode().appendChild([structuralSoundNode, soundNode, weakSoundNode, relaxedSoundNode]);612 613 }614 }615 })],616 listeners: {617 close: function(window){618 this.checkerWindow.getTree().getRootNode().reset();619 }.bind(this)620 }621 });622 623 this.checkerWindow.show();624 this.checkerWindow.check(true);625 }
...
grouping.js
Source:grouping.js
...13 grouping: 'data.group'14 });15 for (var i = 0; i < testSet.length; i++)16 node.appendChild(testSet[i]);17 assert(checkNode(node) === false);18 assert($values(basis.array.sort(testSet, 'data.group')), $values(node.childNodes));19 }20 },21 {22 name: 'as object with no child nodes and sorting',23 test: function(){24 var testSet = getTestSet();25 var node = new Node({26 childFactory: nodeFactory,27 grouping: {28 rule: 'data.group',29 sorting: 'data.id',30 sortingDesc: true31 }32 });33 for (var i = 0; i < testSet.length; i++)34 node.appendChild(testSet[i]);35 assert(checkNode(node) === false);36 assert($values([4, 3, 8, 1, 5, 6, 0, 2, 7, 9].map(convertToNode)), $values(node.childNodes));37 }38 },39 {40 name: 'as object with child nodes and sorting',41 test: function(){42 var testSet = getTestSet();43 var node = new Node({44 childFactory: nodeFactory,45 sorting: 'data.value',46 sortingDesc: true,47 grouping: {48 rule: 'data.group',49 sorting: 'data.id',50 sortingDesc: true51 },52 childNodes: testSet53 });54 assert(checkNode(node) === false);55 assert($values([4, 8, 3, 6, 5, 1, 9, 7, 2, 0].map(convertToNode)), $values(node.childNodes));56 }57 }58 ]59 },60 {61 name: 'update PartitionNode and order',62 test: [63 {64 name: 'simple value',65 test: function(){66 var testSet = getTestSet();67 var node = new Node({68 childFactory: nodeFactory,69 sorting: basis.getter('data.value'),70 sortingDesc: true,71 grouping: {72 rule: 'data.group',73 sorting: basis.getter('data.title').as(String),74 sortingDesc: true75 },76 childNodes: testSet77 });78 assert(checkNode(node) === false);79 assert($values([4, 8, 3, 6, 5, 1, 9, 7, 2, 0].map(convertToNode)), $values(node.childNodes));80 var groups = getGroups(node);81 for (var i = 0; i < groups.length; i++)82 groups[i].update({ title: 'group' + groups[i].data.title });83 assert(checkNode(node) === false);84 assert($values([4, 8, 3, 6, 5, 1, 9, 7, 2, 0].map(convertToNode)), $values(node.childNodes));85 groups[0].update({ title: '-1' });86 assert(checkNode(node) === false);87 assert($values([8, 3, 6, 5, 1, 9, 7, 2, 0, 4].map(convertToNode)), $values(node.childNodes));88 groups[1].update({ title: '-2' });89 assert(checkNode(node) === false);90 assert($values([6, 5, 1, 9, 7, 2, 0, 8, 3, 4].map(convertToNode)), $values(node.childNodes));91 groups[2].update({ title: '-3' });92 assert(checkNode(node) === false);93 assert($values([9, 7, 2, 0, 6, 5, 1, 8, 3, 4].map(convertToNode)), $values(node.childNodes));94 groups[3].update({ title: '-4' });95 assert(checkNode(node) === false);96 assert($values([9, 7, 2, 0, 6, 5, 1, 8, 3, 4].map(convertToNode)), $values(node.childNodes));97 }98 },99 {100 name: 'with delegate',101 test: function(){102 var groupNodes = {};103 for (var i = 1; i <= 4; i++)104 groupNodes[i] = new Node({105 data: {106 title: i107 }108 });109 // ======================================110 var node = new Node({111 childFactory: nodeFactory,112 sorting: basis.getter('data.value'),113 sortingDesc: true,114 grouping: {115 rule: basis.getter('data.group').as(groupNodes),116 sorting: basis.getter('data.title'),117 sortingDesc: true118 },119 childNodes: testSet//.filter(basis.getter('data.group >= 3'))120 });121 assert(checkNode(node) === false);122 assert(getGroups(node).length === 4);123 assert($values([4, 8, 3, 6, 5, 1, 9, 7, 2, 0].map(convertToNode)), $values(node.childNodes));124 var groups = getGroups(node);125 /*for (var i = 0; i < groups.length; i++)126 groups[i].update({ title: 'group' + i });*/127 groups[0].update({ title: -4 });128 assert(checkNode(node) === false);129 assert($values([8, 3, 6, 5, 1, 9, 7, 2, 0, 4].map(convertToNode)), $values(node.childNodes));130 groups[1].update({ title: -3 });131 assert(checkNode(node) === false);132 assert($values([6, 5, 1, 9, 7, 2, 0, 8, 3, 4].map(convertToNode)), $values(node.childNodes));133 groups[2].update({ title: -2 });134 assert(checkNode(node) === false);135 assert($values([9, 7, 2, 0, 6, 5, 1, 8, 3, 4].map(convertToNode)), $values(node.childNodes));136 groups[3].update({ title: -1 });137 assert(checkNode(node) === false);138 assert($values([9, 7, 2, 0, 6, 5, 1, 8, 3, 4].map(convertToNode)), $values(node.childNodes));139 }140 }141 ]142 },143 {144 name: 'set grouping',145 test: [146 {147 name: 'set/remove, change grouping',148 test: function(){149 var node = new Node({150 childFactory: nodeFactory,151 childNodes: getTestSet()152 });153 assert(checkNode(node) === false);154 node.setGrouping(basis.getter('data.group'));155 assert(checkNode(node) === false);156 assert(getGroups(node).length === 4);157 // change grouping158 node.setGrouping(basis.getter('data.value'));159 assert(checkNode(node) === false);160 assert(getGroups(node).length === 10);161 // drop grouping162 var order = basis.array.from(node.childNodes);163 node.setGrouping();164 assert(checkNode(node) === false);165 assert(node.grouping === null);166 assert(order, node.childNodes);167 node.setGrouping({168 rule: 'data.value',169 sorting: basis.getter('data.title')170 });171 assert(checkNode(node) === false);172 var order = basis.array.from(node.childNodes);173 // nothing changed174 node.grouping.setSorting(node.grouping.sorting);175 assert(checkNode(node) === false);176 assert(order, node.childNodes);177 // reverse order178 node.grouping.setSorting(node.grouping.sorting, true);179 assert(checkNode(node) === false);180 assert($values(order).reverse(), $values(node.childNodes));181 }182 },183 {184 name: 'set/remove grouping via setOwner',185 test: function(){186 var groupingDestroyed = false;187 var node = new Node({188 childFactory: nodeFactory,189 childNodes: getTestSet(),190 grouping: {191 autoDestroyWithNoOwner: false,192 handler: {193 destroy: function(){194 groupingDestroyed = true;195 }196 }197 }198 });199 var grouping = node.grouping;200 assert(checkNode(node) === false);201 assert(checkNode(grouping) === false);202 assert(basis.Class.isClass(node.groupingClass));203 assert(grouping instanceof node.groupingClass);204 assert(grouping.owner === node);205 grouping.setOwner();206 assert(checkNode(node) === false);207 assert(checkNode(grouping) === false);208 assert(groupingDestroyed === false);209 assert(node.grouping === null);210 }211 },212 {213 name: 'changing grouping with no alive flag should destroy old grouping',214 test: function(){215 var groupingDestroyed = false;216 var node = new Node({217 grouping: {218 handler: {219 destroy: function(){220 groupingDestroyed = true;221 }222 }223 }224 });225 var grouping = node.grouping;226 assert(checkNode(node) === false);227 assert(checkNode(grouping) === false);228 assert(basis.Class.isClass(node.groupingClass));229 assert(grouping instanceof node.groupingClass);230 assert(grouping.owner === node);231 node.setGrouping();232 assert(checkNode(node) === false);233 assert(node.grouping === null);234 assert(groupingDestroyed === true);235 }236 },237 {238 name: 'set grouping and clear childNodes',239 test: function(){240 var node = new Node({241 childFactory: nodeFactory,242 grouping: {243 rule: 'data.value'244 }245 });246 assert(checkNode(node) === false);247 node.setChildNodes(getTestSet());248 assert(checkNode(node) === false);249 node.clear();250 assert(checkNode(node) === false);251 node.setChildNodes(getTestSet());252 assert(checkNode(node) === false);253 }254 },255 {256 name: 'create with grouping and destroy grouping',257 test: function(){258 var node = new Node({259 childFactory: nodeFactory,260 grouping: {261 rule: 'data.value'262 }263 });264 var grouping = node.grouping;265 grouping.destroy();266 assert(node.grouping === null);267 assert(checkNode(node) === false);268 assert(checkDestroyedObject(grouping) === false);269 }270 },271 {272 name: 'set grouping and destroy grouping',273 test: function(){274 var node = new Node({275 childFactory: nodeFactory276 });277 node.setGrouping('data.value');278 assert(node.grouping !== null);279 var grouping = node.grouping;280 grouping.destroy();281 assert(node.grouping === null);282 assert(checkNode(node) === false);283 assert(checkDestroyedObject(grouping) === false);284 }285 }286 ]287 },288 {289 name: 'nesting grouping',290 test: [291 {292 name: 'create with nested grouping, decrease deep step by step, and increase back step by step',293 test: function(){294 var node = new Node({295 childFactory: nodeFactory,296 grouping: {297 rule: 'data.value',298 grouping: {299 rule: 'data.id % 4',300 grouping: basis.getter('data.id % 2')301 }302 },303 childNodes: getTestSet()304 });305 assert(checkNode(node) === false);306 node.grouping.grouping.setGrouping();307 assert(checkNode(node) === false);308 node.grouping.setGrouping();309 assert(checkNode(node) === false);310 node.setGrouping();311 assert(checkNode(node) === false);312 node.setGrouping('data.value');313 assert(checkNode(node) === false);314 node.grouping.setGrouping('data.id % 4');315 assert(checkNode(node) === false);316 node.grouping.grouping.setGrouping('data.id % 2');317 assert(checkNode(node) === false);318 }319 },320 {321 name: 'set childs for node with nested grouping',322 test: function(){323 var node = new Node({324 childFactory: nodeFactory,325 grouping: {326 rule: 'data.value',327 grouping: {328 rule: 'data.id % 4',329 grouping: basis.getter('data.id % 2')330 }331 }332 });333 node.setChildNodes(getTestSet());334 assert(checkNode(node) === false);335 node.clear();336 assert(checkNode(node) === false);337 node.setChildNodes(getTestSet());338 assert(checkNode(node) === false);339 node.setGrouping();340 assert(checkNode(node) === false);341 }342 },343 {344 name: 'increase deep of nested grouping step by step and reset',345 test: function(){346 var node = new Node({347 childFactory: nodeFactory,348 childNodes: getTestSet()349 });350 assert(checkNode(node) === false);351 node.setGrouping('data.value');352 assert(checkNode(node) === false);353 node.grouping.setGrouping('data.id % 4');354 assert(checkNode(node) === false);355 node.grouping.grouping.setGrouping('data.id % 2');356 assert(checkNode(node) === false);357 node.setGrouping();358 assert(checkNode(node) === false);359 }360 },361 {362 name: 'replace nested grouping by other',363 test: function(){364 var node = new Node({365 childFactory: nodeFactory,366 childNodes: getTestSet()367 });368 node.setGrouping({369 rule: 'data.value',370 grouping: {371 rule: 'data.id % 4',372 grouping: basis.getter('data.id % 2')373 }374 });375 assert(checkNode(node) === false);376 node.setGrouping('data.value');377 assert(node.grouping !== null);378 node.setGrouping({379 rule: 'data.value',380 grouping: {381 rule: 'data.id % 4',382 grouping: basis.getter('data.id % 2')383 }384 });385 assert(checkNode(node) === false);386 node.setGrouping();387 assert(checkNode(node) === false);388 }389 }390 ]391 },392 {393 name: 'setGrouping after create and update PartitionNode with delegate',394 test: function(){395 var groupNodes = {};396 for (var i = 1; i <= 4; i++)397 groupNodes[i] = new Node({398 data: {399 title: i400 }401 });402 var node = new Node({403 childFactory: nodeFactory,404 sorting: basis.getter('data.value'),405 sortingDesc: true,406 childNodes: testSet//.filter(basis.getter('data.group >= 3'))407 });408 assert(checkNode(node) === false);409 node.setGrouping({410 rule: basis.getter('data.group').as(groupNodes),411 sorting: basis.getter('data.title'),412 sortingDesc: true413 });414 assert(checkNode(node) === false);415 assert(getGroups(node).length === 4);416 assert($values([4, 8, 3, 6, 5, 1, 9, 7, 2, 0].map(convertToNode)), $values(node.childNodes));417 var groups = getGroups(node);418 /*for (var i = 0; i < groups.length; i++)419 groups[i].update({ title: 'group' + i });*/420 groups[0].update({ title: -4 });421 assert(checkNode(node) === false);422 assert($values([8, 3, 6, 5, 1, 9, 7, 2, 0, 4].map(convertToNode)), $values(node.childNodes));423 groups[1].update({ title: -3 });424 assert(checkNode(node) === false);425 assert($values([6, 5, 1, 9, 7, 2, 0, 8, 3, 4].map(convertToNode)), $values(node.childNodes));426 groups[2].update({ title: -2 });427 assert(checkNode(node) === false);428 assert($values([9, 7, 2, 0, 6, 5, 1, 8, 3, 4].map(convertToNode)), $values(node.childNodes));429 groups[3].update({ title: -1 });430 assert(checkNode(node) === false);431 assert($values([9, 7, 2, 0, 6, 5, 1, 8, 3, 4].map(convertToNode)), $values(node.childNodes));432 }433 },434 {435 name: 'setGrouping after create and update PartitionNode with delegate & subscription',436 test: function(){437 var GroupDelegateClass = Class(Node, {438 emit_subscribersChanged: function(){439 Node.prototype.emit_subscribersChanged.call(this);440 if (this.subscriberCount)441 this.update({ title: this.data.title_ });442 }443 });444 var groupNodes = {};445 for (var i = 1; i <= 4; i++)446 groupNodes[i] = new GroupDelegateClass({447 data: {448 title_: -i,449 title: i450 }451 });452 var node = new Node({453 childFactory: nodeFactory,454 sorting: basis.getter('data.value'),455 sortingDesc: true,456 groupingClass: {457 childClass: {458 active: true459 }460 },461 childNodes: testSet//.filter(basis.getter('data.group >= 3'))462 });463 assert(checkNode(node) === false);464 node.setGrouping({465 rule: basis.getter('data.group').as(groupNodes),466 sorting: basis.getter('data.title'),467 sortingDesc: true468 });469 assert(checkNode(node) === false);470 assert(getGroups(node).length === 4);471 assert($values([9, 7, 2, 0, 6, 5, 1, 8, 3, 4].map(convertToNode)), $values(node.childNodes));472 }473 },474 {475 name: 'grouping change events (issue #8)',476 test: function(){477 // preparation478 var events;479 var node = new Node({480 grouping: {},481 handler: {482 '*': function(e){483 if (events && e.type == 'groupingChanged')484 events.push(e);485 }486 }487 });488 // test489 events = [];490 node.setGrouping({});491 assert(events.length === 1);492 }493 },494 {495 name: 'using dataSource for grouping node',496 test: [497 {498 name: 'childNodes + group dataset',499 test: function(){500 var node = new Node({501 childFactory: nodeFactory,502 childNodes: getTestSet()503 });504 node.setGrouping({505 rule: 'data.groupObj',506 dataSource: groupDatasetByGroup507 });508 this.is(false, checkNode(node));509 node.setGrouping();510 this.is(false, checkNode(node));511 node.setGrouping({512 rule: 'data.groupObj',513 dataSource: groupDatasetByGroup514 });515 this.is(false, checkNode(node));516 node.grouping.setDataSource();517 this.is(false, checkNode(node));518 }519 },520 {521 name: 'childNodes + group dataset #2',522 test: function(){523 var node = new Node({524 childFactory: nodeFactory,525 childNodes: getTestSet(),526 grouping: {527 rule: 'data.groupObj'528 }529 });530 this.is(false, checkNode(node));531 node.grouping.setDataSource(groupDatasetByGroup);532 this.is(false, checkNode(node));533 node.setGrouping();534 this.is(false, checkNode(node));535 }536 },537 {538 name: 'childNodes + empty group dataset + fill/clear the dataset',539 test: function(){540 var groupDataSource = new Dataset();541 var node = new Node({542 childFactory: nodeFactory,543 childNodes: getTestSet(),544 grouping: {545 rule: 'data.groupObj',546 dataSource: groupDataSource547 }548 });549 this.is(false, checkNode(node));550 groupDataSource.add(groupDatasetByGroup.getItems());551 this.is(false, checkNode(node));552 groupDataSource.clear();553 this.is(false, checkNode(node));554 }555 },556 {557 name: 'childNodes + empty group dataset + fill/clear the dataset + destroy dataset',558 test: function(){559 var groupDataSource = new Dataset();560 var node = new Node({561 childFactory: nodeFactory,562 childNodes: getTestSet(),563 grouping: {564 rule: 'data.groupObj',565 dataSource: groupDataSource566 }567 });568 this.is(false, checkNode(node));569 groupDataSource.add(groupDatasetByGroup.getItems());570 this.is(false, checkNode(node));571 groupDataSource.destroy();572 this.is(null, node.grouping.dataSource);573 this.is(4, node.grouping.childNodes.length);574 this.is(false, checkNode(node));575 var dataset2 = new Dataset({ items: groupDatasetByGroup.getItems() });576 var itemCount = dataset2.itemCount;577 this.is(true, itemCount > 0);578 node.grouping.setDataSource(dataset2);579 this.is(dataset2, node.grouping.dataSource);580 this.is(itemCount, dataset2.itemCount);581 this.is(false, checkNode(node));582 node.clear();583 this.is(dataset2, node.grouping.dataSource);584 this.is(itemCount, dataset2.itemCount);585 this.is(0, node.childNodes.length);586 this.is(false, checkNode(node));587 }588 },589 {590 name: 'childNodes + group dataset 10',591 test: function(){592 var node = new Node({593 childFactory: nodeFactory,594 childNodes: getTestSet()595 });596 node.setGrouping({597 rule: 'data.groupObj',598 dataSource: groupDatasetByGroup10599 });600 this.is(false, checkNode(node));601 node.setGrouping();602 this.is(false, checkNode(node));603 node.setGrouping({604 rule: 'data.groupObj',605 dataSource: groupDatasetByGroup10606 });607 this.is(false, checkNode(node));608 node.grouping.setDataSource();609 this.is(false, checkNode(node));610 }611 },612 {613 name: 'group dataset + child nodes on init',614 test: function(){615 var node = new Node({616 childFactory: nodeFactory,617 childNodes: getTestSet(),618 grouping: {619 rule: 'data.groupObj',620 dataSource: groupDatasetByGroup621 }622 });623 this.is(false, checkNode(node));624 node.setGrouping();625 this.is(false, checkNode(node));626 }627 },628 {629 name: 'group dataset + child nodes after init',630 test: function(){631 var node = new Node({632 childFactory: nodeFactory,633 grouping: {634 rule: 'data.groupObj',635 dataSource: groupDatasetByGroup636 }637 });638 this.is(false, checkNode(node));639 node.setChildNodes(getTestSet());640 this.is(false, checkNode(node));641 node.setChildNodes();642 this.is(false, checkNode(node));643 }644 },645 {646 name: 'set grouping and remove grouping with nullGroup',647 test: function(){648 var node = new Node({649 childFactory: nodeFactory,650 childNodes: basis.array.create(10, basis.fn.$self),651 grouping: {652 rule: 'data.value',653 dataSource: new Dataset(),654 autoDestroyWithNoOwner: false655 }656 });657 var grouping = node.grouping;658 this.is(false, checkNode(node));659 this.is(false, checkNode(grouping));660 this.is(10, node.childNodes.length);661 this.is(10, grouping.nullGroup.nodes.length);662 node.setGrouping(null, true);663 this.is(false, checkNode(node));664 this.is(false, checkNode(grouping));665 this.is(10, node.childNodes.length);666 this.is(0, grouping.nullGroup.nodes.length);667 }668 }669 ]670 }671 ]...
node_check_model.js
Source:node_check_model.js
1/**2***çå«èç¹ç±»3***ä½ææ¥æ 2014/7/184*/5(function () {6 var Class = ZYDesign.Class;7 // çå«èç¹ç±» 继æ¿èªèç¹åºç±»8 Class.CheckNode = (function () {9 /**10 çå«èç¹ç±»11 */12 function CheckNode() {13 if (!(this instanceof CheckNode)) {14 return;15 }16 // 继æ¿èªèç¹åºç±»17 Class.NodeBase.call(this);18 // 模å¼19 this.mode = 3;20 // è¾åºå£21 this.output = new ZYDesign.Class.OutputConnector(this);22 // èæ¯é¢è²23 this.backgroundColor = "#97D700";24 // 宽度25 this.width = 150;26 // é«åº¦27 this.height = 64;28 }29 // 继æ¿èªèç¹åºç±»30 Class.inheritPrototype(Class.NodeBase, CheckNode);31 // è¾åºç¹ååä½ç½®Xåæ 32 CheckNode.prototype.outputCircleX = 150.5;33 // è¾åºç¹ååä½ç½®Xåæ 34 CheckNode.prototype.outputCircleY = 26;35 // è¾åºç¹æåXåæ 36 CheckNode.prototype.outputTextX = 138.5;37 // è¾åºç¹æåYåæ 38 CheckNode.prototype.outputTextY = 31;39 // èç¹ç±»å40 CheckNode.prototype.type = ZYDesign.Enum.NODETYPE.CHECK;41 // èç¹éç¨ç±»å42 CheckNode.prototype.commonType = ZYDesign.Enum.NODECOMMONTYPE.TERMINAL;43 // æ¥åç±»å44 CheckNode.prototype.typeInt = 9;45 // å类类å46 CheckNode.prototype.categoryType = 2;47 // ç±»åå表å段48 CheckNode.prototype.typeListKey = "checkNodes";49 // å¤å¶ä¸å¯ç¨50 CheckNode.prototype.copyDisabled = true;51 // å é¤ä¸å¯ç¨52 CheckNode.prototype.removeDisabled = true;53 // é¢è§ä¸å¯ç¨54 CheckNode.prototype.previewDisabled = true;55 // æ¹éè¾å
¥ä¸å¯ç¨56 CheckNode.prototype.optionbatchDisabled = true;57 // æ¯å¦ç¦ç¨åªä½58 CheckNode.prototype.mediaDisable = true;59 // æ¯å¦å
许ç¼è¾èç¹å60 CheckNode.prototype.nodeNameEditable = false;61 /**62 è·åè¦åæ å¿åæ¢ä¿¡æ¯63 */64 CheckNode.prototype.getWarnIconTrasform = function () {65 return "translate(130, -20)";66 }67 /**68 è·åå°èæ¯Xåæ 69 */70 CheckNode.prototype.getSmallBgX = function () {71 return 2;72 }73 /**74 è·åå°èæ¯Yåæ 75 */76 CheckNode.prototype.getSmallBgY = function () {77 return 2;78 }79 /**80 è·åå°èæ¯å®½åº¦81 */82 CheckNode.prototype.getSmallBgWidth = function () {83 return 75;84 }85 /**86 è·åå°èæ¯é«åº¦87 */88 CheckNode.prototype.getSmallBgHeight = function () {89 return 46;90 }91 /**92 è·åå°èæ¯æåXåæ 93 */94 CheckNode.prototype.getSmallBgTxtX = function () {95 return 10;96 }97 /**98 è·åå°èæ¯æåYåæ 99 */100 CheckNode.prototype.getSmallBgTxtY = function () {101 return 33;102 }103 /**104 è·åå°èæ¯æå105 */106 CheckNode.prototype.getSmallBgTxt = function () {107 return "Check";108 }109 /**110 çæè¾åºå£111 */112 CheckNode.prototype.initOutput = function () {113 // è¾åºID114 if (this.originData.output &&115 this.originData.output.uuid) {116 this.output.outputId = this.originData.output.uuid;117 }118 }119 /**120 åå§å121 @nodeData æºæ°æ®122 @x æå®çXåæ ,没ææå®å使ç¨nodeDataä¸çå¼123 @x æå®çYåæ ,没ææå®å使ç¨nodeDataä¸çå¼124 */125 CheckNode.prototype.init = function (nodeData, x, y) {126 // å
è°ç¨ç¶ç±»ååæ¹æ³127 CheckNode.base.init.call(this, nodeData, x, y);128 // çæè¾åºå£129 this.initOutput();130 }131 /**132 导åºè¯¥èç¹ä¸ºJsonæ°æ®133 @questionairId æå±é®å·ID134 @jsonHolder ç¨æ¥æ¶éæ°æ®ç对象135 */136 CheckNode.prototype.exportJson = function (questionairId, jsonHolder) {137 // è°ç¨ç¶ç±»ååæ¹æ³138 CheckNode.base.exportJson.call(this, questionairId, jsonHolder);139 // çå«èç¹çmodeæ»æ¯ä¸º0140 jsonHolder.mode = 0;141 jsonHolder.commonMode = 0;142 // çå«èç¹æè¾åºå£143 jsonHolder.output = {144 index: -1,145 uuid: this.output.outputId,146 }147 // è¾åºå表148 jsonHolder.destList = this.collectDestList();149 }150 /**151 æ ¹æ®IDæç´¢è¿æ¥ç¹152 @connectorId è¿æ¥ç¹ID153 */154 CheckNode.prototype.searchConnectorById = function (connectorId) {155 // è¾åºç¹156 if (this.output.outputId == connectorId) {157 return this.output;158 }159 return false;160 }161 /**162 çæå½åèç¹çä¸ä¸ªæ°æ®å¯æ¬å¹¶è¿å163 @jsonHolder å¯æ¬æ°æ®åå¨å¯¹è±¡164 @diffX å¯æ¬ä½ç½®Xå移é165 @diffY å¯æ¬ä½ç½®Yå移é166 */167 CheckNode.prototype.cloneNodeJson = function (jsonHolder, diffX, diffY) {168 // å
è°ç¨ç¶ç±»ååæ¹æ³å¤å¶åºæ¬ä¿¡æ¯169 CheckNode.base.cloneNodeJson.call(this, jsonHolder, diffX, diffY);170 // è¾åºå£171 jsonHolder.output = {172 text: "è¾åº",173 };174 // æ·»å å½æ°å175 jsonHolder.addFnKey = "addCheckNode";176 }177 /**178 è·åæ§å¶æé®åºåä½ç½®å移é179 */180 CheckNode.prototype.getCtrIconTransform = function () {181 var transform = "translate(-2," + (this.getBackgroundHeight()) + ")";182 return transform;183 }184 /**185 è·åèç¹çå½åç¶æ186 æä¸ä¸å ç§ç¶æ:187 free:èªç±ç¶æ,å¤ç«ç¶æ188 normal:å·²ç»å¨æ£å¸¸éè·¯ä¸,å¼å§èç¹,ç»æèç¹,çå«èç¹æ°¸è¿æ¯è¯¥ç¶æ189 random:å·²ç»è¢«éæºç»å ç¨190 loop:å·²ç»è¢«å¾ªç¯åå ç¨191 */192 CheckNode.prototype.getEngagement = function () {193 return {194 status: ZYDesign.Enum.NODESTATE.NORMAL,195 dueToNode: null196 }197 }198 /**199 æ¯å¦æä¸éçè¾å
¥å£200 */201 CheckNode.prototype.hasDeadInput = function () {202 return false;203 }204 /**205 æ¯å¦å
å«ä¸éçè¾åºå£206 */207 CheckNode.prototype.hasDeadOutput = function () {208 if (!this.output.dest) {209 return true;210 }211 return false;212 }213 return CheckNode;214 })();...
_DynamicSublayer.js
Source:_DynamicSublayer.js
1define([2 'dojo/_base/declare',3 'dojo/_base/lang',4 'dojo/_base/array',5 'dojo/on',6 'dojo/dom-class',7 'dojo/dom-style',8 'dojo/dom-attr',9 'dojo/fx',10 'dojo/html',11 'dijit/Menu',12 'dijit/MenuItem',13 'dojo/topic',14 'dijit/_WidgetBase',15 'dijit/_TemplatedMixin',16 'dojo/text!./templates/Sublayer.html',17 'dojo/i18n!./../nls/resource'18], function (19 declare,20 lang,21 array,22 on,23 domClass,24 domStyle,25 domAttr,26 fx,27 html,28 Menu,29 MenuItem,30 topic,31 WidgetBase,32 TemplatedMixin,33 sublayerTemplate,34 i18n35 ) {36 var _DynamicSublayer = declare([WidgetBase, TemplatedMixin], {37 control: null,38 sublayerInfo: null,39 menu: null,40 icons: null,41 // ^args42 templateString: sublayerTemplate,43 i18n: i18n,44 _expandClickHandler: null,45 _handlers: [],46 postCreate: function () {47 this.inherited(arguments);48 // Should the control be visible or hidden (depends on subLayerInfos)?49 if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) {50 var subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) {51 return sli.id;52 });53 if (array.indexOf(subLayerInfos, this.sublayerInfo.id) < 0) {54 domClass.add(this.domNode, 'layerControlHidden');55 }56 }57 // Should the control be visible or hidden?58 if (this.control.controlOptions.layerIds && array.indexOf(this.control.controlOptions.layerIds, this.sublayerInfo.id) < 0) {59 domClass.add(this.domNode, 'layerControlHidden');60 }61 var checkNode = this.checkNode;62 domAttr.set(checkNode, 'data-sublayer-id', this.sublayerInfo.id);63 domClass.add(checkNode, this.control.layer.id + '-layerControlSublayerCheck');64 if (array.indexOf(this.control.layer.visibleLayers, this.sublayerInfo.id) !== -1) {65 this._setSublayerCheckbox(true, checkNode);66 } else {67 this._setSublayerCheckbox(false, checkNode);68 }69 this._handlers.push(on(checkNode, 'click', lang.hitch(this, function (event) {70 // prevent click event from bubbling71 if (event.stopPropagation) {72 event.stopPropagation();73 }74 if (domAttr.get(checkNode, 'data-checked') === 'checked') {75 this._setSublayerCheckbox(false, checkNode);76 } else {77 this._setSublayerCheckbox(true, checkNode);78 }79 this.control._setVisibleLayers();80 this._checkboxScaleRange();81 })));82 html.set(this.labelNode, this.sublayerInfo.name);83 this._expandClick();84 if (this.sublayerInfo.minScale !== 0 || this.sublayerInfo.maxScale !== 0) {85 this._checkboxScaleRange();86 this._handlers.push(this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')));87 }88 //set up menu89 if (this.control.controlOptions.subLayerMenu &&90 this.control.controlOptions.subLayerMenu.length) {91 this.menu = new Menu({92 contextMenuForWindow: false,93 targetNodeIds: [this.menuClickNode],94 leftClickToOpen: true95 });96 array.forEach(this.control.controlOptions.subLayerMenu, lang.hitch(this, '_addMenuItem'));97 this.menu.startup();98 } else {99 domClass.add(this.menuClickNode, 'hidden');100 }101 },102 _addMenuItem: function (menuItem) {103 //create the menu item104 var item = new MenuItem(menuItem);105 item.set('onClick', lang.hitch(this, function () {106 topic.publish('layerControl/' + menuItem.topic, {107 layer: this.control.layer,108 subLayer: this.sublayerInfo,109 iconNode: this.iconNode,110 menuItem: item111 });112 }));113 this.menu.addChild(item);114 },115 // add on event to expandClickNode116 _expandClick: function () {117 var i = this.icons;118 this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, function () {119 var expandNode = this.expandNode,120 iconNode = this.expandIconNode;121 if (domStyle.get(expandNode, 'display') === 'none') {122 fx.wipeIn({123 node: expandNode,124 duration: 300125 }).play();126 domClass.replace(iconNode, i.collapse, i.expand);127 } else {128 fx.wipeOut({129 node: expandNode,130 duration: 300131 }).play();132 domClass.replace(iconNode, i.expand, i.collapse);133 }134 }));135 this._handlers.push(this._expandClickHandler);136 },137 // set checkbox based on layer so it's always in sync138 _setSublayerCheckbox: function (checked, checkNode) {139 checkNode = checkNode || this.checkNode;140 var i = this.icons;141 if (checked) {142 domAttr.set(checkNode, 'data-checked', 'checked');143 domClass.replace(checkNode, i.checked, i.unchecked);144 } else {145 domAttr.set(checkNode, 'data-checked', 'unchecked');146 domClass.replace(checkNode, i.unchecked, i.checked);147 }148 },149 // check scales and add/remove disabled classes from checkbox150 _checkboxScaleRange: function () {151 var node = this.checkNode,152 scale = this.control.layer.getMap().getScale(),153 min = this.sublayerInfo.minScale,154 max = this.sublayerInfo.maxScale;155 domClass.remove(node, 'layerControlCheckIconOutScale');156 if ((min !== 0 && scale > min) || (max !== 0 && scale < max)) {157 domClass.add(node, 'layerControlCheckIconOutScale');158 }159 },160 destroy: function () {161 this.inherited(arguments);162 this._handlers.forEach(function (h) {163 h.remove();164 });165 }166 });167 return _DynamicSublayer;...
CheckBox.js
Source:CheckBox.js
1///////////////////////////////////////////////////////////////////////////2// Copyright © 2014 - 2018 Esri. All Rights Reserved.3//4// Licensed under the Apache License Version 2.0 (the "License");5// you may not use this file except in compliance with the License.6// You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS,12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13// See the License for the specific language governing permissions and14// limitations under the License.15///////////////////////////////////////////////////////////////////////////16define([17 'dojo/_base/declare',18 'dijit/_WidgetBase',19 'dojo/_base/lang',20 'dojo/_base/html',21 'dojo/dom-class',22 'dojo/on',23 'dojo/Evented',24 "dojo/keys"25],26function(declare, _WidgetBase, lang, html, domClass, on, Evented, keys) {27 return declare([_WidgetBase, Evented], {28 'baseClass': 'jimu-checkbox',29 declaredClass: 'jimu.dijit.CheckBox',30 checked: false,31 status: true,32 label: "",33 postCreate: function(){34 this.checkNode = html.create('div', {35 'class': 'checkbox jimu-float-leading jimu-icon jimu-icon-checkbox'36 }, this.domNode);37 this.labelNode = html.create('div', {38 'class': 'label jimu-float-leading',39 innerHTML: this.label || ""40 }, this.domNode);41 if(this.checked){42 html.addClass(this.checkNode, 'checked');43 html.addClass(this.checkNode, 'jimu-icon-checked');44 }45 if(!this.status){46 html.addClass(this.domNode, 'jimu-state-disabled');47 html.addClass(this.checkNode, 'jimu-state-disabled');48 }49 this.own(50 on(this.checkNode, 'click', lang.hitch(this, function(){51 if(this.status){52 if(this.checked){53 this.uncheck();54 }else{55 this.check();56 }57 }58 }))59 );60 this.own(61 on(this.labelNode, 'click', lang.hitch(this, function() {62 if (this.checked && this.status) {63 this.uncheck();64 } else if (this.status) {65 this.check();66 }67 }))68 );69 this._udpateLabelClass();70 this._initSection508();71 },72 setLabel: function(label){73 this.label = label;74 this.labelNode.innerHTML = this.label;75 this.labelNode.title = this.label;76 this._udpateLabelClass();77 },78 _udpateLabelClass: function(){79 if(this.labelNode){80 if(this.labelNode.innerHTML){81 html.removeClass(this.labelNode, 'not-visible');82 }else{83 html.addClass(this.labelNode, 'not-visible');84 }85 }86 },87 _initSection508: function () {88 //with "tabindex" param89 if ("undefined" !== typeof this.tabindex) {90 html.setAttr(this.checkNode, "tabindex", this.tabindex);91 //css class92 this.own(on(this.checkNode, 'focus', lang.hitch(this, function () {93 html.addClass(this.checkNode, "dijitCheckBoxFocused");94 })));95 this.own(on(this.checkNode, 'blur', lang.hitch(this, function () {96 html.removeClass(this.checkNode, "dijitCheckBoxFocused");97 })));98 //keypress event99 this.own(on(this.checkNode, 'keypress', lang.hitch(this, function (evt) {100 var charOrCode = evt.charCode || evt.keyCode;101 if (html.hasClass(this.checkNode, "dijitCheckBoxFocused") && keys.SPACE === charOrCode) {102 if (this.status) {103 if (this.checked) {104 this.uncheck();105 } else {106 this.check();107 }108 }109 }110 })));111 }112 },113 setValue: function(value){114 if(!this.status){115 return;116 }117 if(value === true){118 this.check();119 }else{120 this.uncheck();121 }122 },123 getValue: function(){124 return this.checked;125 },126 setStatus: function(newStatus){127 newStatus = !!newStatus;128 var isStatusChanged = this.status !== newStatus;129 this.status = newStatus;130 if(this.status){131 domClass.remove(this.domNode, 'jimu-state-disabled');132 html.removeClass(this.checkNode, 'jimu-state-disabled');133 }else{134 domClass.add(this.domNode, 'jimu-state-disabled');135 html.addClass(this.checkNode, 'jimu-state-disabled');136 }137 if(isStatusChanged){138 this.emit('status-change', newStatus);139 }140 },141 getStatus: function(){142 return this.status;143 },144 check: function(notEvent){145 if(!this.status){146 return;147 }148 this.checked = true;149 html.addClass(this.checkNode, 'checked jimu-icon-checked');150 html.removeClass(this.checkNode, 'checked jimu-icon-checkbox');151 if(!notEvent){152 this.onStateChange();153 }154 },155 uncheck: function(notEvent){156 if(!this.status){157 return;158 }159 this.checked = false;160 html.removeClass(this.checkNode, 'checked');161 html.removeClass(this.checkNode, 'jimu-icon-checked');162 html.addClass(this.checkNode, 'jimu-icon-checkbox');163 if(!notEvent){164 this.onStateChange();165 }166 },167 onStateChange: function(){168 if(this.onChange && lang.isFunction(this.onChange)){169 this.onChange(this.checked);170 }171 this.emit('change', this.checked);172 },173 focus: function () {174 if (this.checkNode && this.checkNode.focus) {175 this.checkNode.focus();176 }177 }178 });...
dynamic.js
Source:dynamic.js
...8 childFactory: nodeFactory,9 childNodes: getTestSet()10 });11 node.setGrouping(basis.getter('data.group'));12 this.is(false, checkNode(node));13 node.setSorting(basis.getter('data.value'));14 this.is(false, checkNode(node));15 node.setGrouping({16 rule: 'data.group',17 sorting: basis.getter('data.id'),18 sortingDesc: true19 });20 this.is(false, checkNode(node));21 node.setGrouping();22 this.is(false, checkNode(node));23 node.setSorting(basis.getter('data.group'), true);24 this.is(false, checkNode(node));25 node.setGrouping(basis.getter('data.group'));26 this.is(false, checkNode(node));27 var order = basis.array.from(node.childNodes);28 node.setSorting();29 this.is(false, checkNode(node));30 node.setGrouping();31 this.is(false, checkNode(node));32 this.is(order, node.childNodes);33 }34 },35 {36 name: 'mixing sorting & grouping, wrong order on child group changing (issue #1)',37 test: function(){38 var node = new Node({39 childFactory: nodeFactory,40 childNodes: getTestSet(),41 sorting: 'data.value',42 grouping: 'data.group'43 });44 var child = node.firstChild;45 var orginalGroupId = child.data.group;46 child.update({ group: orginalGroupId + 1 });47 this.is(false, checkNode(node));48 child.update({ group: orginalGroupId });49 this.is(false, checkNode(node));50 ///////51 var node = new Node({52 childFactory: nodeFactory,53 sorting: 'data.value',54 grouping: {55 rule: 'data.group',56 sorting: 'data.id'57 },58 childNodes: [59 { data: { value: 2, group: 1 } },60 { data: { value: 3, group: 1 } },61 { data: { value: 3, group: 2 } },62 { data: { value: 4, group: 2 } },63 { data: { value: 1, group: 3 } },64 { data: { value: 4, group: 3 } },65 { data: { value: 5, group: 3 } },66 { data: { value: 1, group: 4 } }67 ]68 });69 var child = node.firstChild;70 child.update({ group: 2 });71 this.is(1, node.childNodes.indexOf(child));72 this.is(false, checkNode(node));73 child.update({ group: 3 });74 this.is(4, node.childNodes.indexOf(child));75 this.is(false, checkNode(node));76 child.update({ group: 4 });77 this.is(7, node.childNodes.indexOf(child));78 this.is(false, checkNode(node));79 child.update({ group: 5 });80 this.is(7, node.childNodes.indexOf(child));81 this.is(false, checkNode(node));82 child.update({ group: 1 });83 this.is(0, node.childNodes.indexOf(child));84 this.is(false, checkNode(node));85 }86 },87 {88 name: 'mixed sorting & grouping, wrong order on moving last child inside the group (issue #2)',89 test: function(){90 var node = new Node({91 childFactory: nodeFactory,92 childNodes: getTestSet(),93 sorting: 'data.value',94 grouping: 'data.group'95 });96 this.is(false, checkNode(node));97 node.lastChild.update({ value: 0 });98 this.is(false, checkNode(node));99 }100 },101 {102 name: 'partition manipulations',103 test: function(){104 var node = new Node({105 childFactory: nodeFactory,106 grouping: {107 rule: 'data.group'108 },109 childNodes: getTestSet()110 });111 this.is(false, checkNode(node));112 node.grouping.appendChild(node.grouping.firstChild);113 this.is(false, checkNode(node));114 node.grouping.appendChild(node.grouping.firstChild);115 this.is(false, checkNode(node));116 node.grouping.appendChild(node.grouping.firstChild);117 this.is(false, checkNode(node));118 node.grouping.appendChild(node.grouping.firstChild);119 this.is(false, checkNode(node));120 node.grouping.insertBefore(node.grouping.lastChild, node.grouping.firstChild);121 this.is(false, checkNode(node));122 node.grouping.insertBefore(node.grouping.lastChild, node.grouping.firstChild);123 this.is(false, checkNode(node));124 node.grouping.insertBefore(node.grouping.lastChild, node.grouping.firstChild);125 this.is(false, checkNode(node));126 node.grouping.insertBefore(node.grouping.lastChild, node.grouping.firstChild);127 this.is(false, checkNode(node));128 node.grouping.insertBefore(node.grouping.childNodes[1], node.grouping.childNodes[2]);129 this.is(false, checkNode(node));130 node.grouping.insertBefore(node.grouping.childNodes[1], node.grouping.childNodes[3]);131 this.is(false, checkNode(node));132 node.grouping.insertBefore(node.grouping.childNodes[1], node.grouping.childNodes[0]);133 this.is(false, checkNode(node));134 node.grouping.insertBefore(node.grouping.childNodes[2], node.grouping.childNodes[3]);135 this.is(false, checkNode(node));136 node.grouping.insertBefore(node.grouping.childNodes[3], node.grouping.childNodes[2]);137 this.is(false, checkNode(node));138 node.grouping.insertBefore(node.grouping.childNodes[3], node.grouping.childNodes[1]);139 this.is(false, checkNode(node));140 }141 }142 ]...
_DynamicFolder.js
Source:_DynamicFolder.js
1define([2 'dojo/_base/declare',3 'dojo/_base/lang',4 'dojo/_base/array',5 'dojo/on',6 'dojo/dom-class',7 'dojo/dom-style',8 'dojo/dom-attr',9 'dojo/fx',10 'dojo/html',11 'dijit/_WidgetBase',12 'dijit/_TemplatedMixin',13 'dojo/text!./templates/Folder.html'14], function (15 declare,16 lang,17 array,18 on,19 domClass,20 domStyle,21 domAttr,22 fx,23 html,24 WidgetBase,25 TemplatedMixin,26 folderTemplate27) {28 var _DynamicFolder = declare([WidgetBase, TemplatedMixin], {29 control: null,30 sublayerInfo: null,31 icons: null,32 // ^args33 templateString: folderTemplate,34 _expandClickHandler: null,35 _handlers: [],36 postCreate: function () {37 this.inherited(arguments);38 // Should the control be visible or hidden (depends on subLayerInfos)?39 if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) {40 var subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) {41 return sli.id;42 });43 if (array.indexOf(subLayerInfos, this.sublayerInfo.id) < 0) {44 domClass.add(this.domNode, 'layerControlHidden');45 }46 }47 // Should the control be visible or hidden?48 if (this.control.controlOptions.layerIds && array.indexOf(this.control.controlOptions.layerIds, this.sublayerInfo.id) < 0) {49 domClass.add(this.domNode, 'layerControlHidden');50 }51 var checkNode = this.checkNode;52 domAttr.set(checkNode, 'data-sublayer-id', this.sublayerInfo.id);53 domClass.add(checkNode, this.control.layer.id + '-layerControlSublayerCheck');54 if (array.indexOf(this.control.layer.visibleLayers, this.sublayerInfo.id) !== -1) {55 this._setSublayerCheckbox(true, checkNode);56 } else {57 this._setSublayerCheckbox(false, checkNode);58 }59 this._handlers.push(on(checkNode, 'click', lang.hitch(this, function (event) {60 // prevent click event from bubbling61 if (event.stopPropagation) {62 event.stopPropagation();63 }64 if (domAttr.get(checkNode, 'data-checked') === 'checked') {65 this._setSublayerCheckbox(false, checkNode);66 } else {67 this._setSublayerCheckbox(true, checkNode);68 }69 this.control._setVisibleLayers();70 this._checkboxScaleRange();71 })));72 html.set(this.labelNode, this.sublayerInfo.name);73 this._expandClick();74 if (this.sublayerInfo.minScale !== 0 || this.sublayerInfo.maxScale !== 0) {75 this._checkboxScaleRange();76 this._handlers.push(this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')));77 }78 },79 // add on event to expandClickNode80 _expandClick: function () {81 var i = this.icons;82 this._handlers.push(this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, function () {83 var expandNode = this.expandNode,84 iconNode = this.expandIconNode;85 if (domStyle.get(expandNode, 'display') === 'none') {86 fx.wipeIn({87 node: expandNode,88 duration: 30089 }).play();90 domClass.replace(iconNode, i.folderOpen, i.folder);91 } else {92 fx.wipeOut({93 node: expandNode,94 duration: 30095 }).play();96 domClass.replace(iconNode, i.folder, i.folderOpen);97 }98 })));99 },100 // set checkbox based on layer so it's always in sync101 _setSublayerCheckbox: function (checked, checkNode) {102 checkNode = checkNode || this.checkNode;103 var i = this.icons;104 if (checked) {105 domAttr.set(checkNode, 'data-checked', 'checked');106 domClass.replace(checkNode, i.checked, i.unchecked);107 } else {108 domAttr.set(checkNode, 'data-checked', 'unchecked');109 domClass.replace(checkNode, i.unchecked, i.checked);110 }111 },112 // check scales and add/remove disabled classes from checkbox113 _checkboxScaleRange: function () {114 var node = this.checkNode,115 scale = this.control.layer.getMap().getScale(),116 min = this.sublayerInfo.minScale,117 max = this.sublayerInfo.maxScale;118 domClass.remove(node, 'layerControlCheckIconOutScale');119 if ((min !== 0 && scale > min) || (max !== 0 && scale < max)) {120 domClass.add(node, 'layerControlCheckIconOutScale');121 }122 },123 destroy: function () {124 this.inherited(arguments);125 this._handlers.forEach(function (h) {126 h.remove();127 });128 }129 });130 return _DynamicFolder;...
keyed-list-renderer.spec.js
Source:keyed-list-renderer.spec.js
...33 it('should render dom nodes', () => {34 const a = { key: 'a', value: 'a' }35 const b = { key: 'b', value: 'b' }36 render(container, [a, b])37 checkNode(container.children[0], a)38 checkNode(container.children[1], b)39 })40 it('should update dom nodes', () => {41 const a = { key: 'a', value: 'a' }42 const b = { key: 'b', value: 'b' }43 render(container, [a, b])44 const a1 = { key: 'a', value: 'a1' }45 const b1 = { key: 'b', value: 'b1' }46 render(container, [a1, b1])47 checkNode(container.children[0], a1)48 checkNode(container.children[1], b1)49 })50 it('should update dom nodes (same object)', () => {51 const a = { key: 'a', value: 'a' }52 const b = { key: 'b', value: 'b' }53 render(container, [a, b])54 a.value = 'a1'55 b.value = 'b1'56 render(container, [a, b])57 checkNode(container.children[0], a)58 checkNode(container.children[1], b)59 })60 it('should re-order dom nodes', () => {61 const a = { key: 'a', value: 'a' }62 const b = { key: 'b', value: 'b' }63 render(container, [a, b])64 expect(container.children.length).to.equal(2)65 render(container, [b, a])66 expect(container.children.length).to.equal(2)67 checkNode(container.children[0], b)68 checkNode(container.children[1], a)69 })70 it('should re-order dom nodes (2)', () => {71 const a = { key: 'a', value: 'a' }72 const b = { key: 'b', value: 'b' }73 const c = { key: 'c', value: 'c' }74 const d = { key: 'd', value: 'd' }75 render(container, [a, b, c, d])76 expect(container.children.length).to.equal(4)77 render(container, [d, c, b, a])78 expect(container.children.length).to.equal(4)79 checkNode(container.children[0], d)80 checkNode(container.children[1], c)81 checkNode(container.children[2], b)82 checkNode(container.children[3], a)83 })84 it('should remove nodes', () => {85 const a = { key: 'a', value: 'a' }86 const b = { key: 'b', value: 'b' }87 const c = { key: 'c', value: 'c' }88 render(container, [a, b, c])89 expect(container.children.length).to.equal(3)90 render(container, [b])91 expect(container.children.length).to.equal(1)92 checkNode(container.children[0], b)93 })94 it('should insert nodes', () => {95 const a = { key: 'a', value: 'a' }96 const b = { key: 'b', value: 'b' }97 const c = { key: 'c', value: 'c' }98 render(container, [a])99 expect(container.children.length).to.equal(1)100 render(container, [a, c])101 expect(container.children.length).to.equal(2)102 checkNode(container.children[0], a)103 checkNode(container.children[1], c)104 105 render(container, [a, b, c])106 expect(container.children.length).to.equal(3)107 checkNode(container.children[0], a)108 checkNode(container.children[1], b)109 checkNode(container.children[2], c)110 })111 it('should empty nodes', () => {112 const a = { key: 'a', value: 'a' }113 const b = { key: 'b', value: 'b' }114 const c = { key: 'c', value: 'c' }115 render(container, [a, b, c])116 expect(container.children.length).to.equal(3)117 render(container, [])118 expect(container.children.length).to.equal(0)119 })120})121function checkNode(node, { value, key }) {122 expect(node.getAttribute('key')).to.equal(key)123 expect(node.textContent).to.equal(value)...
Using AI Code Generation
1const { chromium } = require('playwright');2const { checkNode } = require('playwright/lib/internal/frames');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const element = await page.$('div.user-agent');7 const userAgent = await page.evaluate(element => element.textContent, element);8 console.log(userAgent);9 await browser.close();10})();11const { chromium } = require('playwright');12const { checkNode } = require('playwright/lib/internal/frames');13(async () => {14 const browser = await chromium.launch();15 const page = await browser.newPage();16 const element = await page.$('div.user-agent');17 const userAgent = await page.evaluate(element => element.textContent, element);18 console.log(userAgent);19 await browser.close();20})();21const { chromium } = require('playwright');22const { checkNode } = require('playwright/lib/internal/frames');23(async () => {24 const browser = await chromium.launch();25 const page = await browser.newPage();26 const element = await page.$('div.user-agent');27 const userAgent = await page.evaluate(element => element.textContent, element);28 console.log(userAgent);29 await browser.close();30})();31const { chromium } = require('playwright');32const { checkNode } = require('playwright/lib/internal/frames');33(async () => {34 const browser = await chromium.launch();35 const page = await browser.newPage();36 const element = await page.$('div.user-agent');37 const userAgent = await page.evaluate(element => element.textContent, element);38 console.log(userAgent);39 await browser.close();40})();41const { chromium } = require('playwright');42const { checkNode } = require('playwright/lib/internal/frames');43(async () => {
Using AI Code Generation
1const { checkNode } = require('playwright/lib/protocol/chromium');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 result = await checkNode(page, 'button');8 console.log(result);9 await browser.close();10})();
Using AI Code Generation
1const { checkNode } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const page = await browser.newPage();6 await page.evaluate(() => {7 const element = document.querySelector('h1');8 const result = checkNode(element);9 console.log(result);10 });11 await browser.close();12})();13{14 {15 "webRoot": "${workspaceFolder}"16 }17}
Using AI Code Generation
1(async () => {2 const browser = await chromium.launch();3 const context = await browser.newContext();4 const page = await context.newPage();5 const node = await page.$('h1');6 const isHidden = await node._client.send('DOM.isHidden', { nodeId: node._remoteObject.nodeId });7 console.log(isHidden);8 await browser.close();9})();10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 const node = await page.$('h1');15 const isHidden = await page._delegate.checkNode(node);16 console.log(isHidden);17 await browser.close();18})();19(async () => {20 const browser = await chromium.launch();21 const context = await browser.newContext();22 const page = await context.newPage();23 const element = await page.$('h1');24 const isHidden = await page._delegate.checkElement(element);25 console.log(isHidden);26 await browser.close();27})();28(async () => {29 const browser = await chromium.launch();30 const context = await browser.newContext();31 const page = await context.newPage();32 const isHidden = await page._delegate.checkSelector('h1');33 console.log(isHidden);34 await browser.close();35})();
Using AI Code Generation
1const { checkNode } = require('playwright/lib/utils/utils');2const { firefox } = require('playwright');3(async () => {4 const browser = await firefox.launch();5 const page = await browser.newPage();6 const element = await page.$('div');7 const result = checkNode(element, 'div');8 console.log(result);9 await browser.close();10})();11## `getTestType()`12const { getTestType } = require('playwright/lib/utils/utils');13const { firefox } = require('playwright');14(async () => {15 const browser = await firefox.launch();16 const page = await browser.newPage();17 const testType = getTestType();18 console.log(testType);19 await browser.close();20})();21## `isDebugMode()`22const { isDebugMode } = require('playwright/lib/utils/utils');23const { firefox } = require('playwright');24(async () => {25 const browser = await firefox.launch();26 const page = await browser.newPage();27 const debugMode = isDebugMode();28 console.log(debugMode);29 await browser.close();30})();31## `isUnderTest()`32const { isUnderTest } = require('playwright/lib/utils/utils');33const { firefox } = require('playwright');34(async () => {35 const browser = await firefox.launch();36 const page = await browser.newPage();37 const isUnderTest = isUnderTest();38 console.log(isUnderTest);39 await browser.close();40})();
Using AI Code Generation
1const { checkNode } = require('playwright/lib/server/frames');2const { chromium } = require('playwright');3const expect = require('expect');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const input = await page.$('#searchInput');9 const label = await page.$('#search-form > fieldset > label');10 const inputName = await checkNode(input);11 const labelName = await checkNode(label);12 expect(inputName).toBe('input');13 expect(labelName).toBe('label');14 await browser.close();15})();16 ✓ should return the node name (12ms)
Using AI Code Generation
1const { checkNode } = require('playwright/lib/server/inspector/domSnapshot');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 let node = await page.$('input[name="q"]');7 let result = await checkNode(page, node);8 console.log(result);9 await browser.close();10})();11{12 {13 {14 {15 {16 {17 {18 {
Using AI Code Generation
1const { checkNode } = require('playwright/lib/server/domSnapshot/domSnapshotAgent');2const { checkNode } = require('playwright/lib/server/domSnapshot/domSnapshotAgent');3const domNode = {4 attributes: {5 },6 {7 },8 {9 attributes: {10 },11 {12 },13 },14 {15 },16};17const queryObject = {18};19const result = checkNode(domNode, queryObject);20console.log(result);21{22 node: {23 attributes: {24 },25 {26 },27 },28}29### checkNode(domNode, queryObject)
Using AI Code Generation
1const { checkNode } = require('playwright/lib/utils/utils');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const node = await page.$('div');5 const result = checkNode(node);6 console.log(result);7});8PASS test.js (1s)9 ✓ test (1s)10 1 passed (1s)
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const node = await page.checkNode('text=Docs');7 console.log(node);8 await browser.close();9})();10const playwright = require('playwright');11(async () => {12 const browser = await playwright.chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 const node = await page.checkNode('text=Docs');16 console.log(node);17 await browser.close();18})();19const playwright = require('playwright');20(async () => {21 const browser = await playwright.chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 const node = await page.checkNode('text=Docs');25 console.log(node);26 await browser.close();27})();28const playwright = require('playwright');29(async () => {30 const browser = await playwright.chromium.launch();31 const context = await browser.newContext();32 const page = await context.newPage();33 const node = await page.checkNode('text=Docs');34 console.log(node);35 await browser.close();36})();37const playwright = require('playwright');38(async () => {39 const browser = await playwright.chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 const node = await page.checkNode('text43test('test', async ({ page }) => {44 const node = await page.$('div');45 const result = checkNode(node);46 console.log(result);47});48PASS test.js (1s)49 ✓ test (1s)50 1 passed (1s)
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const node = await page.checkNode('text=Docs');7 console.log(node);8 await browser.close();9})();10const playwright = require('playwright');11(async () => {12 const browser = await playwright.chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 const node = await page.checkNode('text=Docs');16 console.log(node);17 await browser.close();18})();19const playwright = require('playwright');20(async () => {21 const browser = await playwright.chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 const node = await page.checkNode('text=Docs');25 console.log(node);26 await browser.close();27})();28const playwright = require('playwright');29(async () => {30 const browser = await playwright.chromium.launch();31 const context = await browser.newContext();32 const page = await context.newPage();33 const node = await page.checkNode('text=Docs');34 console.log(node);35 await browser.close();36})();37const playwright = require('playwright');38(async () => {39 const browser = await playwright.chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 const node = await page.checkNode('text
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.
Get 100 minutes of automation test minutes FREE!!