Best JavaScript code snippet using wpt
elementPorts.js
Source:elementPorts.js
...13 };14 QUnit.module('port collection operations', function() {15 QUnit.test('simple getters/setters', function(assert) {16 var shape = create();17 assert.equal(shape.getPorts().length, 0);18 var portDefinition = {19 id: 'first'20 };21 shape.addPort(portDefinition);22 assert.equal(shape.getPorts().length, 1);23 var p2 = {24 id: 'second'25 };26 var p3 = {27 id: 'third'28 };29 shape.addPorts([p2, p3]);30 assert.equal(shape.getPorts().length, 3);31 assert.equal(shape.getPorts()[0].id, 'first');32 });33 QUnit.test('initial ports', function(assert) {34 var shape = create({ items: [{ 'group': 'in' }] });35 assert.equal(shape.getPorts().length, 1);36 });37 QUnit.test('addPorts', function(assert) {38 var shape = create({ items: [{ group: 'in' }] });39 var eventOrder = ['ports:add', 'change:ports', 'change'];40 shape.on('all', function(eventName) {41 assert.equal(eventName, eventOrder.shift());42 });43 shape.addPort({ id: 'a' });44 assert.equal(shape.getPorts().length, 2);45 assert.equal(shape.getPorts()[1].id, 'a');46 assert.ok(typeof shape.getPorts()[0].id === 'string');47 });48 QUnit.test('insertPort by index', function(assert) {49 var shape = create({ items: [{ group: 'in' }] });50 var eventOrder = ['ports:add', 'change:ports', 'change'];51 shape.on('all', function(eventName) {52 assert.equal(eventName, eventOrder.shift());53 });54 shape.insertPort(0, { id: 'a' });55 assert.equal(shape.getPorts().length, 2);56 assert.equal(shape.getPorts()[0].id, 'a');57 assert.ok(typeof shape.getPorts()[1].id === 'string');58 });59 QUnit.test('insertPort by port', function(assert) {60 var shape = create({ items: [{ group: 'in' }] });61 shape.insertPort(shape.getPorts()[0], { id: 'a' });62 assert.equal(shape.getPorts().length, 2);63 assert.equal(shape.getPorts()[0].id, 'a');64 assert.ok(typeof shape.getPorts()[1].id === 'string');65 });66 QUnit.test('insertPort by id', function(assert) {67 var shape = create({ items: [{ group: 'in' }] });68 69 shape.insertPort(0, { id: 'a' });70 shape.insertPort('a', { id: 'b' });71 assert.equal(shape.getPorts().length, 3);72 assert.equal(shape.getPorts()[0].id, 'b');73 assert.equal(shape.getPorts()[1].id, 'a');74 assert.ok(typeof shape.getPorts()[2].id === 'string');75 });76 QUnit.test('remove port - by object', function(assert) {77 var shape = create({ items: [{ id: 'aaa', 'group': 'in' }, { id: 'xxx', 'group': 'in' }] });78 var eventOrder = ['ports:remove', 'change:ports', 'change'];79 shape.on('all', function(eventName) {80 assert.equal(eventName, eventOrder.shift());81 });82 shape.removePort(shape.getPort('aaa'));83 assert.equal(shape.getPorts().length, 1);84 assert.equal(shape.getPorts()[0].id, 'xxx');85 });86 QUnit.test('remove port - by id', function(assert) {87 var shape = create({ items: [{ id: 'aaa', 'group_id': 'in' }, { id: 'xxx', 'group_id': 'in' }] });88 var eventOrder = ['ports:remove', 'change:ports', 'change'];89 shape.on('all', function(eventName) {90 assert.equal(eventName, eventOrder.shift());91 });92 shape.removePort('aaa');93 assert.equal(shape.getPorts().length, 1);94 assert.equal(shape.getPorts()[0].id, 'xxx');95 });96 QUnit.test('remove port - invalid reference - should not remove any port', function(assert) {97 var shape = create({ items: [{ id: 'aaa', 'group_id': 'in' }, { id: 'xxx', 'group_id': 'in' }] });98 shape.removePort();99 assert.equal(shape.getPorts().length, 2);100 shape.removePort('non-existing-port');101 assert.equal(shape.getPorts().length, 2);102 });103 QUnit.test('removePorts', function(assert) {104 var shape = create({ items: [105 { id: 'aaa', 'group_id': 'in' },106 { id: 'bbb', 'group_id': 'in' },107 { id: 'xxx', 'group_id': 'in' }108 ] });109 var eventOrder = ['ports:remove', 'change:ports', 'change'];110 shape.on('all', function(eventName) {111 assert.equal(eventName, eventOrder.shift());112 });113 shape.removePorts([{ id: 'aaa' }, { id: 'bbb' }]);114 assert.equal(shape.getPorts().length, 1);115 assert.equal(shape.getPorts()[0].id, 'xxx');116 });117 QUnit.test('removePorts - invalid reference - should not remove them', function(assert) {118 var shape = create({ items: [119 { id: 'aaa', 'group_id': 'in' },120 { id: 'bbb', 'group_id': 'in' },121 { id: 'xxx', 'group_id': 'in' }122 ] });123 var eventOrder = ['ports:remove', 'change:ports', 'change'];124 shape.on('all', function(eventName) {125 assert.equal(eventName, eventOrder.shift());126 });127 shape.removePorts([{ id: 'aaa' }, { id: 'ddd' }]);128 assert.equal(shape.getPorts().length, 2);129 assert.equal(shape.getPorts()[0].id, 'bbb');130 assert.equal(shape.getPorts()[1].id, 'xxx');131 });132 QUnit.test('removePorts - should remove all ports when only given options', function(assert) {133 var shape = create({ items: [134 { id: 'aaa', 'group_id': 'in' },135 { id: 'bbb', 'group_id': 'in' },136 { id: 'xxx', 'group_id': 'in' }137 ] });138 var eventOrder = ['ports:remove', 'change:ports', 'change'];139 shape.on('all', function(eventName) {140 assert.equal(eventName, eventOrder.shift());141 });142 shape.removePorts();143 assert.equal(shape.getPorts().length, 0);144 });145 QUnit.test('getPortIndex', function(assert) {146 var idObject = {};147 var ports = [148 {},149 { id: 'aaa', 'group_id': 'in' },150 { id: 'xxx', 'group_id': 'in' },151 { x: 'whatever' },152 { id: '' },153 { id: 0 },154 { id: false },155 { id: true },156 { id: idObject }157 ];158 var shape = create({ items: ports });159 assert.equal(shape.getPortIndex('xxx'), 2);160 assert.equal(shape.getPortIndex(ports[1]), 1);161 assert.equal(shape.getPortIndex(), -1);162 assert.equal(shape.getPortIndex(null), -1);163 assert.equal(shape.getPortIndex(undefined), -1);164 assert.equal(shape.getPortIndex(''), 4);165 assert.equal(shape.getPortIndex(0), 5);166 assert.equal(shape.getPortIndex(false), 6);167 assert.equal(shape.getPortIndex(true), 7);168 assert.equal(shape.getPortIndex(idObject), -1);169 });170 QUnit.test('initialized with no ports', function(assert) {171 var shape = create();172 assert.equal(shape.getPorts().length, 0);173 });174 QUnit.module('ids', function() {175 QUnit.test('duplicate id', function(assert) {176 assert.throws(function() {177 create({ items: [{ 'group_id': 'in' }, { id: 'a' }, { id: 'a' }] });178 }, function(err) {179 return err.toString().indexOf('duplicities') !== -1;180 });181 });182 QUnit.test('duplicate id - add port', function(assert) {183 var shape = create({ items: [{ id: 'a' }] });184 assert.throws(function() {185 shape.addPort({ id: 'a' });186 }, function(err) {187 return err.toString().indexOf('duplicities ') !== -1;188 });189 });190 QUnit.test('duplicate id - add ports', function(assert) {191 var shape = create({ items: [{ id: 'a' }] });192 assert.throws(function() {193 shape.addPorts([{ id: 'x' }, { id: 'x' }]);194 }, function(err) {195 return err.toString().indexOf('duplicities') !== -1;196 });197 });198 QUnit.test('auto generated id', function(assert) {199 var shape = create({ items: [{ 'group': 'in' }] });200 assert.equal(shape.getPorts().length, 1);201 assert.ok(shape.getPorts()[0].id !== undefined, 'normalized on initialization');202 shape.addPort({ group: 'a' });203 assert.equal(shape.getPorts().length, 2);204 assert.ok(shape.getPorts()[1].id !== undefined);205 });206 });207 });208 QUnit.module('attributes and markup', function() {209 QUnit.test('is rendered correctly', function(assert) {210 var ports = [211 {212 id: 'fst',213 markup: '<g class="firstport"><rect/><text class="text"/></g>',214 attrs: {215 '.text': {216 fill: 'blue',217 text: 'aaa'218 }219 }220 },221 {222 id: 'snd',223 attrs: {224 'circle': {225 fill: 'red'226 }227 }228 }229 ];230 var shape = create({ items: ports });231 var shapeView = new joint.dia.ElementView({ model: shape });232 var renderPortSpy = sinon.spy(shapeView, '_createPortElement');233 shapeView.render();234 assert.ok(renderPortSpy.calledTwice);235 assert.equal(shapeView.$el.find('.joint-port').length, 2);236 var fst = shapeView.$el.find('.firstport');237 var rect = fst.find('rect');238 var text = fst.find('.text');239 assert.equal(fst.length, 1);240 assert.equal(rect.length, 1);241 assert.equal(text.length, 1);242 assert.equal(text.attr('fill'), 'blue');243 assert.equal(text.text(), 'aaa');244 var snd = shapeView.$el.find('.joint-port').eq(1);245 var sndPortShape = snd.children().eq(0);246 assert.equal(snd.length, 1);247 assert.equal(sndPortShape[0].tagName.toLowerCase(), $(shape.portMarkup)[0].tagName.toLowerCase());248 assert.equal(sndPortShape.attr('fill'), 'red');249 });250 QUnit.test('render custom port markup', function(assert) {251 var WithoutPorts = joint.dia.Element.extend({252 markup: '<g class="rotatable"><g class="scalable"><rect class="rectangle"/></g><text/></g>',253 portMarkup: '<circle class="custom-port-markup"/>',254 defaults: _.defaultsDeep({ type: 'temp' }, joint.dia.Element.prototype.defaults)255 });256 var model = new WithoutPorts();257 var shapeView = new joint.dia.ElementView({ model: model });258 model.addPorts([{ id: 'a' }, { id: 'b', markup: '<rect class="custom-rect" />' }]);259 shapeView.render();260 assert.equal(shapeView.$el.find('.joint-port').length, 2, 'port wraps');261 assert.equal(shapeView.$el.find('.custom-port-markup').length, 1);262 assert.equal(shapeView.$el.find('.custom-port-markup').prop('tagName'), 'circle');263 assert.equal(shapeView.$el.find('.custom-rect').length, 1);264 assert.equal(shapeView.$el.find('.custom-rect').prop('tagName'), 'rect');265 });266 QUnit.test('Selectors', function(assert) {267 var shape = create({268 items: [{269 markup: [{270 tagName: 'circle',271 selector: 'c',272 groupSelector: 'cr'273 }, {274 tagName: 'rect',275 selector: 'r',276 groupSelector: 'cr'277 }],278 attrs: {279 root: { rootTest: true },280 c: { circleTest: true },281 r: { rectTest: true },282 cr: { groupTest: true }283 }284 }]285 });286 var shapeView = new joint.dia.ElementView({ model: shape });287 shapeView.render();288 var rootNode = shapeView.el.querySelector('[root-test]');289 var circleNode = shapeView.el.querySelector('[circle-test]');290 var rectNode = shapeView.el.querySelector('[rect-test]');291 var group = shapeView.el.querySelectorAll('[group-test]');292 assert.ok(rootNode instanceof SVGGElement);293 assert.ok(circleNode instanceof SVGCircleElement);294 assert.ok(rectNode instanceof SVGRectElement);295 assert.equal(group.length, 2);296 assert.equal(group[0], circleNode);297 assert.equal(group[1], rectNode);298 });299 });300 QUnit.module('port update', function() {301 QUnit.test('remove port elements from DOM', function(assert) {302 var element = create();303 element.addPorts([{ id: 'a' }, { id: 'b' }]);304 var view = new joint.dia.ElementView({ model: element });305 view.render();306 assert.equal(view.vel.find('.joint-port').length, 2);307 view._removePorts();308 assert.equal(view.vel.find('.joint-port').length, 0, 'ports elements removed');309 });310 });311 QUnit.module('z - index', function(hooks) {312 QUnit.module('evaluate from definition', function(hooks) {313 QUnit.test('test name', function(assert) {314 var shape = create({315 groups: { 'a': { z: 0 }}316 });317 shape.addPorts([318 { z: 0 },319 { z: 'auto' },320 { z: undefined },321 { group: 'a' }322 ]);323 var ports = shape._portSettingsData.getPorts();324 assert.equal(ports[0].z, 0);325 assert.equal(ports[1].z, 'auto');326 assert.equal(ports[2].z, 'auto');327 assert.equal(ports[3].z, 0);328 });329 });330 QUnit.test('elements order with z-index', function(assert) {331 var data = {332 items: [333 { z: 7, id: '7' },334 { z: 6, id: '6' },335 { z: 5, id: '5' },336 { z: 4, id: '4' },337 { id: 'x' },338 { z: 3, id: '3' },339 { z: 2, id: '2' },340 { z: 1, id: '1' },341 { z: 0, id: '0-1' },342 { z: 0, id: '0-2' },343 { z: 0, id: '0-3' }344 ]345 };346 var shape = create(data);347 var view = new joint.dia.ElementView({ model: shape }).render();348 var nodes = view.$el.find('.rotatable').children();349 // var result = [];350 // _.each(nodes, function(n) {351 // result.push($(n).find('[port]').attr('port'));352 // });353 // console.log(result);354 var i = 0;355 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '0-1', 'z index 0, 0nth node');356 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '0-2');357 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '0-3');358 assert.ok(nodes.eq(i++).hasClass('scalable'));359 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '1');360 assert.equal(nodes.eq(i++)[0].tagName, 'text');361 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '2');362 assert.equal(nodes.eq(i++).find('[port]').attr('port'), 'x');363 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '3');364 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '4');365 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '5');366 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '6');367 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '7');368 });369 QUnit.test('elements order with z-index and without', function(assert) {370 var data = {371 items: [372 { id: '111' },373 { id: '1' },374 { id: '2' },375 { id: '0001' },376 { z: 20, id: 'z20' },377 { z: 30, id: 'z30' }378 ]379 };380 var shape = create(data);381 var view = new joint.dia.ElementView({ model: shape }).render();382 var nodes = view.$el.find('.rotatable').children();383 // var result = [];384 // _.each(nodes, function(n) {385 // result.push($(n).find('[port]').attr('port'));386 // });387 // console.log(result);388 var i = 0;389 assert.ok(nodes.eq(i++).hasClass('scalable'));390 assert.equal(nodes.eq(i++)[0].tagName, 'text');391 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '111');392 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '1');393 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '2');394 assert.equal(nodes.eq(i++).find('[port]').attr('port'), '0001');395 assert.equal(nodes.eq(i++).find('[port]').attr('port'), 'z20');396 assert.equal(nodes.eq(i++).find('[port]').attr('port'), 'z30');397 });398 QUnit.test('elements order - no z-index defined', function(assert) {399 var data = {400 items: [401 { id: 'a' },402 { id: 'b' },403 { id: 'c' }404 ]405 };406 var shape = create(data);407 var view = new joint.dia.ElementView({ model: shape }).render();408 var nodes = view.$el.find('.rotatable').children();409 assert.ok(nodes.eq(0).hasClass('scalable'));410 assert.equal(nodes.eq(1)[0].tagName, 'text');411 assert.equal(nodes.eq(2).find('[port]').attr('port'), 'a');412 assert.equal(nodes.eq(3).find('[port]').attr('port'), 'b');413 assert.equal(nodes.eq(4).find('[port]').attr('port'), 'c');414 });415 });416 QUnit.module('port grouping', function() {417 QUnit.test('resolve position args', function(assert) {418 var data = {419 groups: {420 'a': {421 position: {422 name: 'right',423 args: { x: 10, y: 11, angle: 12 }424 },425 label: {426 position: {427 name: 'lefts',428 args: { x: 10, y: 20, angle: 30 }429 }430 }431 }, 'b': {432 position: 'top'433 }434 },435 items: [436 {437 id: 'pa',438 args: { y: 20 },439 group: 'a'440 },441 {442 id: 'pb',443 args: { y: 20 },444 group: 'b'445 }446 ]447 };448 var shape = create(data);449 new joint.dia.ElementView({ model: shape }).render();450 var getPort = function(id) {451 return _.find(shape._portSettingsData.ports, function(p) {452 return p.id === id;453 });454 };455 assert.equal(getPort('pa').position.name, 'right');456 assert.equal(getPort('pa').position.args.y, 20);457 assert.equal(getPort('pa').position.args.x, 10);458 assert.equal(getPort('pb').position.name, 'top');459 assert.equal(getPort('pb').position.args.y, 20);460 });461 QUnit.test('resolve port labels', function(assert) {462 var data = {463 groups: {464 'a': {465 label: {466 position: {467 name: 'right',468 args: { ty: 20 }469 }470 }471 }, 'b': {}472 },473 items: [474 { id: 'pa1', group: 'a', label: { position: { name: 'top', args: { tx: 11 }}}},475 { id: 'pa2', group: 'a' },476 { id: 'pb1', group: 'b', label: { position: { args: { tx: 11 }}}},477 { id: 'pb2', group: 'b' }478 ]479 };480 var shape = create(data);481 new joint.dia.ElementView({ model: shape }).render();482 var getPort = function(id) {483 return _.find(shape._portSettingsData.ports, function(p) {484 return p.id === id;485 });486 };487 assert.equal(getPort('pa1').label.position.name, 'top', 'override group settings');488 assert.equal(getPort('pa1').label.position.args.tx, 11);489 assert.equal(getPort('pa1').label.position.args.ty, 20);490 assert.equal(getPort('pa2').label.position.name, 'right', 'gets settings from group');491 assert.equal(getPort('pb1').label.position.name, 'left', 'default settings, extra args');492 assert.equal(getPort('pb1').label.position.args.tx, 11);493 assert.equal(getPort('pb2').label.position.name, 'left', 'defaults - no settings on group, either on port label');494 });495 });496 QUnit.module('port layout', function(hooks) {497 QUnit.test('straight line layouts', function(assert) {498 var elBBox = g.rect(0, 0, 100, 100);499 var trans = joint.layout.Port.left([500 {},501 {},502 { dx: 20, dy: -15 },503 { y: 100, x: 100, angle: 45 }504 ], elBBox, {});505 var delta = trans[1].y - trans[0].y;506 assert.equal(trans[0].y + delta, trans[1].y);507 assert.equal(trans[0].x, 0);508 assert.equal(trans[0].angle, 0);509 assert.equal(trans[2].x, 20);510 assert.equal(trans[2].y, trans[1].y + delta - 15, 'offset y should be applied');511 assert.equal(trans[2].angle, 0);512 assert.equal(trans[3].angle, 45);513 assert.equal(trans[3].y, 100, 'override y position');514 assert.equal(trans[3].x, 100, 'override y position');515 });516 QUnit.test('circular layouts', function(assert) {517 var elBBox = g.rect(0, 0, 100, 100);518 var trans = joint.layout.Port.ellipseSpread([519 {},520 { dr: 3, compensateRotation: true },521 { dx: 1, dy: 2, dr: 3 },522 { x: 100, y: 101, angle: 10 }523 ], elBBox, {});524 assert.equal(Math.round(trans[1].angle), -270, 'rotation compensation applied');525 assert.equal(trans[1].x, 100 + 3, 'dr is applied');526 assert.equal(trans[1].y, 50);527 // middle bottom528 assert.equal(trans[2].x, 50 + 1, 'dx is applied');529 assert.equal(trans[2].y, 100 + 2 + 3, 'dy, dr are applied');530 assert.equal(trans[3].x, 100, 'x position overridden');531 assert.equal(trans[3].y, 101, 'y position overridden');532 assert.equal(trans[3].angle, 10, 'y position overridden');533 });534 });535 QUnit.module('getPortsPositions', function() {536 QUnit.test('ports positions can be retrieved even if element is not rendered yet', function(assert) {537 var shape = create({538 groups: {539 'a': { position: 'left' }540 },541 items: [542 { id: 'one', group: 'a' },543 { id: 'two', group: 'a' },544 { id: 'three', group: 'a' }545 ]546 }).set('size', { width: 5, height: 10 });547 var portsPositions = shape.getPortsPositions('a');548 assert.ok(portsPositions.one.y > 0);549 assert.ok(portsPositions.one.y < portsPositions.two.y);550 assert.ok(portsPositions.two.y < portsPositions.three.y);551 });552 });553 QUnit.module('getGroupPorts', function() {554 QUnit.test('return ports with given group', function(assert) {555 var shape = create({556 groups: {557 a: { position: 'left' },558 b: { position: 'right' }559 },560 items: [561 { id: 'one', group: 'a' },562 { id: 'two', group: 'b' },563 { id: 'three', group: 'b' },564 { id: 'four', group: 'b' }565 ]566 });567 var portsA = shape.getGroupPorts('a');568 var portsB = shape.getGroupPorts('b');569 assert.equal(portsA.length, 1);570 assert.equal(portsB.length, 3);571 assert.ok(portsA.every(function(port) { return port.group === 'a'; }));572 assert.ok(portsB.every(function(port) { return port.group === 'b'; }));573 });574 });575 QUnit.module('portProp', function() {576 QUnit.test('set port properties', function(assert) {577 var shape = create({578 items: [579 { id: 'one', attrs: { '.body': { fill: 'red' }}}580 ]581 });582 shape.portProp('one', 'attrs/.body/fill-opacity', 1);583 assert.equal(shape.prop('ports/items/0/attrs/.body/fill-opacity'), 1);584 shape.portProp('one', 'attrs/.body', { fill: 'newcolor' });585 assert.equal(shape.prop('ports/items/0/attrs/.body/fill'), 'newcolor');586 shape.portProp('one', 'attrs/.body', {});587 assert.equal(shape.prop('ports/items/0/attrs/.body/fill'), 'newcolor');588 shape.portProp('one', { attrs: { '.body': { fill: 'black', x: 1 }}});589 assert.equal(shape.prop('ports/items/0/attrs/.body/fill'), 'black');590 assert.equal(shape.prop('ports/items/0/attrs/.body/x'), 1);591 });592 QUnit.test('get port properties', function(assert) {593 var shape = create({594 items: [595 { id: 'one', attrs: { '.body': { fill: 'red' }}}596 ]597 });598 var prop = shape.portProp('one', 'attrs/.body');599 assert.equal(prop.fill, 'red');600 prop = shape.portProp('one');601 assert.ok(prop.id, 'red');602 });603 QUnit.test('set port props, path defined as an array', function(assert) {604 var shape = create({605 items: [606 { id: 'one' }607 ]608 });609 shape.portProp('one', ['array', 20], 'array item');610 shape.portProp('one', ['object', '20'], 'object property');611 assert.ok(_.isArray(shape.portProp('one', 'array')));612 assert.equal(shape.portProp('one', 'array')[20], 'array item');613 assert.ok(_.isPlainObject(shape.portProp('one', 'object')));614 assert.equal(shape.portProp('one', 'object/20'), 'object property');615 });616 });617 QUnit.module('event ports:add and ports:remove', function(hooks) {618 QUnit.config.testTimeout = 5000;619 QUnit.test('simple add', function(assert) {620 var shape = create({ items: [{}] });621 assert.expect(3);622 assert.equal(shape.getPorts().length, 1);623 var done = assert.async();624 shape.on('ports:add', function(cell, ports) {625 assert.equal(ports.length, 1);626 assert.equal(ports[0].id, 'a');627 done();628 });629 shape.addPort({ id: 'a' });630 });631 QUnit.test('rewrite', function(assert) {632 var shape = create({ items: [{ id: 'a' }] });633 assert.expect(5);634 assert.equal(shape.getPorts().length, 1);635 var eventAddDone = assert.async();636 var eventRemoveDone = assert.async();637 shape.on('ports:add', function(cell, ports) {638 assert.equal(ports.length, 1);639 assert.equal(ports[0].id, 'b');640 eventAddDone();641 });642 shape.on('ports:remove', function(cell, ports) {643 assert.equal(ports.length, 1);644 assert.equal(ports[0].id, 'a');645 eventRemoveDone();646 });647 shape.prop('ports/items', [{ id: 'b' }], { rewrite: true });648 });649 QUnit.test('change id', function(assert) {650 var shape = create({ items: [{ id: 'a' }] });651 assert.expect(5);652 assert.equal(shape.getPorts().length, 1);653 var eventAddDone = assert.async();654 var eventRemoveDone = assert.async();655 shape.on('ports:add', function(cell, ports) {656 assert.equal(ports.length, 1);657 assert.equal(ports[0].id, 'b');658 eventAddDone();659 });660 shape.on('ports:remove', function(cell, ports) {661 assert.equal(ports.length, 1);662 assert.equal(ports[0].id, 'a');663 eventRemoveDone();664 });665 shape.prop('ports/items/0/id', 'b');666 });667 QUnit.test('failed to add', function(assert) {668 var shape = create({ items: [{ id: 'a' }, { id: 'b' }, { id: 'c' }] });669 assert.expect(3);670 assert.equal(shape.getPorts().length, 3);671 var done = assert.async();672 shape.on('ports:remove', function(cell, ports) {673 assert.equal(ports.length, 1);674 assert.equal(ports[0].id, 'a');675 done();676 });677 shape.removePort('a');678 });679 QUnit.test('add multiple', function(assert) {680 var shape = create({ items: [{ id: 'a' }, { id: 'b' }, { id: 'c' }] });681 assert.expect(4);682 assert.equal(shape.getPorts().length, 3);683 var done = assert.async();684 shape.on('ports:add', function(cell, ports) {685 assert.equal(ports.length, 2);686 assert.equal(ports[0].id, 'x');687 assert.equal(ports[1].id, 'y');688 done();689 });690 shape.addPorts([{ id: 'x' }, { id: 'y' }]);691 });692 });...
ports-test.js
Source:ports-test.js
...41test('Ports do (almost) nothing', async t => {42 t.plan(1)43 reset()44 params = { inventory, update }45 await getPorts(params)46 t.deepEqual(params.ports, always, 'Got back internal _arc services port')47})48test('HTTP port selection', async t => {49 t.plan(8)50 let http = 333351 reset()52 inventory.inv.http = []53 params = { inventory, update }54 await getPorts(params)55 t.deepEqual(params.ports, { http, ...always }, 'Got back default HTTP port')56 let port = 123457 reset()58 inventory.inv.http = []59 inventory.inv._project.preferences.sandbox = { ports: { http: port } }60 params = { inventory, update }61 await getPorts(params)62 t.deepEqual(params.ports, { http: port, ...always }, 'Got back HTTP port from prefs.arc')63 reset()64 inventory.inv.http = []65 params = { port, inventory, update }66 await getPorts(params)67 t.deepEqual(params.ports, { http: port, ...always }, 'Got back default port API option')68 let envVar = 234569 process.env.ARC_HTTP_PORT = envVar70 params = { inventory, update }71 await getPorts(params)72 t.deepEqual(params.ports, { http: envVar, ...always }, 'Got back HTTP from ARC_HTTP_PORT env var')73 delete process.env.ARC_HTTP_PORT74 process.env.PORT = envVar75 params = { inventory, update }76 await getPorts(params)77 t.deepEqual(params.ports, { http: envVar, ...always }, 'Got back HTTP from PORT env var')78 delete process.env.PORT79 reset()80 inventory.inv.static = {}81 params = { inventory, update }82 await getPorts(params)83 t.deepEqual(params.ports, { http, ...always }, 'Got back default HTTP port for @static')84 reset()85 inventory.inv.ws = []86 params = { inventory, update }87 await getPorts(params)88 t.deepEqual(params.ports, { http, ...always }, 'Got back default HTTP port for @ws')89 try {90 await listen(t, 3333)91 reset()92 inventory.inv.http = []93 params = { inventory, update }94 await getPorts(params)95 }96 catch (err) {97 t.match(err.message, /Port 3333 \(http\) is already in use/, 'Got error: ' + err.message)98 }99 await stopListening(t)100})101test('Events port selection', async t => {102 t.plan(6)103 let events = 4444104 reset()105 inventory.inv.events = []106 params = { inventory, update }107 await getPorts(params)108 t.deepEqual(params.ports, { events, ...always }, 'Got back default events port')109 let port = 1234110 reset()111 inventory.inv.events = []112 inventory.inv._project.preferences.sandbox = { ports: { events: port } }113 params = { inventory, update }114 await getPorts(params)115 t.deepEqual(params.ports, { events: port, ...always }, 'Got back events port from prefs.arc')116 reset()117 inventory.inv.queues = []118 inventory.inv._project.preferences.sandbox = { ports: { queues: port } }119 params = { inventory, update }120 await getPorts(params)121 t.deepEqual(params.ports, { events: port, ...always }, 'Got back queues port from prefs.arc')122 reset()123 inventory.inv.queues = []124 params = { inventory, update }125 await getPorts(params)126 t.deepEqual(params.ports, { events, ...always }, 'Got back default queues port')127 await listen(t, events)128 // Automatic selection129 params = { inventory, update }130 await getPorts(params)131 t.deepEqual(params.ports, { events: 4445, ...always }, 'Automatically found port when default events port was occupied')132 // Blow up when specified133 try {134 reset()135 inventory.inv.events = []136 inventory.inv._project.preferences.sandbox = { ports: { events } }137 params = { inventory, update }138 await getPorts(params)139 }140 catch (err) {141 t.match(err.message, /Port 4444 \(events\) is already in use/, 'Got error: ' + err.message)142 }143 await stopListening(t)144})145test('Tables port selection', async t => {146 t.plan(6)147 let tables = 5555148 reset()149 inventory.inv.tables = []150 params = { inventory, update }151 await getPorts(params)152 t.deepEqual(params.ports, { tables, ...always }, 'Got back default tables port')153 reset()154 inventory.inv._project.manifest = null155 params = { inventory, update }156 await getPorts(params)157 t.deepEqual(params.ports, { tables, ...always }, 'Got back default tables port when default manifest is used')158 let port = 1234159 reset()160 inventory.inv.tables = []161 inventory.inv._project.preferences.sandbox = { ports: { tables: port } }162 params = { inventory, update }163 await getPorts(params)164 t.deepEqual(params.ports, { tables: port, ...always }, 'Got back tables port from prefs.arc')165 let envVar = 2345166 process.env.ARC_DB_EXTERNAL = true167 process.env.ARC_TABLES_PORT = envVar168 await listen(t, envVar)169 reset()170 params = { inventory, update }171 await getPorts(params)172 t.deepEqual(params.ports, { tables: envVar, ...always }, 'Got back occupied tables port for external DB')173 await stopListening(t)174 delete process.env.ARC_DB_EXTERNAL175 delete process.env.ARC_TABLES_PORT176 await listen(t, tables)177 // Automatic selection178 reset()179 inventory.inv.tables = []180 params = { inventory, update }181 await getPorts(params)182 t.deepEqual(params.ports, { tables: 5556, ...always }, 'Automatically found port when default tables port was occupied')183 // Blow up when specified184 try {185 reset()186 inventory.inv.tables = []187 inventory.inv._project.preferences.sandbox = { ports: { tables } }188 params = { inventory, update }189 await getPorts(params)190 }191 catch (err) {192 t.match(err.message, /Port 5555 \(tables\) is already in use/, 'Got error: ' + err.message)193 }194 await stopListening(t)195})196test('_arc port selection', async t => {197 t.plan(2)198 let _arc = 2222199 reset()200 params = { inventory, update }201 await getPorts(params)202 t.deepEqual(params.ports, always, 'Got back default _arc port')203 await listen(t, _arc)204 params = { inventory, update }205 await getPorts(params)206 t.deepEqual(params.ports, { _arc: 2223 }, 'Automatically found port when default _arc port was occupied')207 await stopListening(t)208})209test('Specified port conflict', async t => {210 t.plan(1)211 let http = 1234, tables = 1234212 try {213 reset()214 inventory.inv.http = []215 inventory.inv.tables = []216 inventory.inv._project.preferences.sandbox = { ports: { http, tables } }217 params = { inventory, update }218 await getPorts(params)219 }220 catch (err) {221 t.match(err.message, /Port conflict found on 1234/, 'Got error: ' + err.message)222 }...
angularapp-controller.spec.js
Source:angularapp-controller.spec.js
...160 .toHaveBeenCalled();161162 }163164 function getPorts() {165 console.log('getPorts start');166 var myTestPromise = angular.copy(promise);167 myTestPromise.getPorts.status = 'ko';168 peripheralPortsBeforeEach(myTestPromise);169 controller.getPorts();170 rootScope.$apply();171 expect(branchPeriferalServices.getPorts)172 .toHaveBeenCalled();173174 }175176 function openEbranchCatch() {177 console.log('openEbranchCatch start');178 var myTestPromise = angular.copy(promise);179 myTestPromise.openOperation.status = 'ko';180 peripheralPortsBeforeEach(myTestPromise);181 controller.getPorts();182 rootScope.$apply();183 expect(branchPeriferalServices.getPorts)184 .toHaveBeenCalled();185186 }187188 function openEbranchNoData() {189 console.log('openEbranchNoData start');190 var myTestPromise = angular.copy(promise);191 myTestPromise.RETCODE = 1;192 myTestPromise.recyclerFTPort = "";193 peripheralPortsBeforeEach(myTestPromise);194 controller.getPorts();195 rootScope.$apply();196 expect(branchPeriferalServices.getPorts)197 .toHaveBeenCalled();198199 }200201}());
...
Using AI Code Generation
1var wptool = require('wptool');2wptool.getPorts(function (err, ports) {3 if (err) {4 console.log(err);5 } else {6 console.log(ports);7 }8});9 {10 },11 {12 }13### wptool.getDevices(callback)14var wptool = require('wptool');15wptool.getDevices(function (err, devices) {16 if (err) {17 console.log(err);18 } else {19 console.log(devices);20 }21});22 {23 },24 {25 }
Using AI Code Generation
1var wptool = require('wptool');2wptool.getPorts(function(err, ports) {3 if (err) {4 console.log(err);5 } else {6 console.log(ports);7 }8});9[ { comName: 'COM1' },10 { comName: 'COM2' },11 { comName: 'COM3' },12 { comName: 'COM4' },13 { comName: 'COM5' },14 { comName: 'COM6' },15 { comName: 'COM7' },16 { comName: 'COM8' },17 { comName: 'COM9' },18 { comName: 'COM10' },19 { comName: 'COM11' },20 { comName: 'COM12' },21 { comName: 'COM13' },22 { comName: 'COM14' },23 { comName: 'COM15' },24 { comName: 'COM16' },25 { comName: 'COM17' },26 { comName: 'COM18' },27 { comName: 'COM19' },28 { comName: 'COM20' },29 { comName: 'COM21' },30 { comName: 'COM22' },31 { comName: 'COM23' },32 { comName: 'COM24' },33 { comName: 'COM25' },34 { comName: 'COM26' },35 { comName: 'COM27' },36 { comName: 'COM28' },37 { comName: 'COM29' },38 { comName: 'COM30' },39 { comName: 'COM31' },40 { comName: 'COM32' },41 { comName: 'COM33' },42 { comName: 'COM34' },43 { comName: 'COM35' },44 { comName: 'COM36' },45 { comName: 'COM37' },46 { comName: 'COM38' },47 { comName: 'COM39' },48 { comName: 'COM40' },49 { comName: 'COM41' },50 { comName: 'COM42' },51 { comName: 'COM43' },52 { comName: 'COM44' },53 { comName: 'COM45
Using AI Code Generation
1var wptools = require('wptools');2var data = wptools.getPorts();3console.log(data);4var wptools = require('wptools');5var data = wptools.getLanguages();6console.log(data);7var wptools = require('wptools');8var data = wptools.getCategories();9console.log(data);10var wptools = require('wptools');11var data = wptools.getTitles();12console.log(data);13var wptools = require('wptools');14var data = wptools.getCategoriesOf();15console.log(data);16var wptools = require('wptools');17var data = wptools.getTitlesOf();18console.log(data);19var wptools = require('wptools');20var data = wptools.getCategoriesOfTitles();21console.log(data);22var wptools = require('wptools');23var data = wptools.getTitlesOfCategories();24console.log(data);25var wptools = require('wptools');26var data = wptools.getCategoriesOfTitlesOf();27console.log(data);28var wptools = require('wptools');29var data = wptools.getTitlesOfCategoriesOf();30console.log(data);31var wptools = require('wptools');32var data = wptools.getCategoriesOfTitlesOfCategoriesOf();33console.log(data);
Using AI Code Generation
1var wptool = require('./wptool.js');2var portArray = wptool.getPorts();3console.log(portArray);4exports.getPorts = function() {5 var portArray = [];6 return portArray;7};
Using AI Code Generation
1var wptool = require('./wptool');2var ports = wptool.getPorts();3console.log(ports);4var getPorts = function() {5 var ports = [];6 return ports;7};8exports.getPorts = getPorts;9var ports = wptool.getPorts();10var wptool = require('./wptool');11var ports = wptool.getPorts();
Using AI Code Generation
1var wptools = require('wptools');2wptools.getPorts(function (ports) {3 console.log(ports);4});5var wptools = require('wptools');6wptools.getPorts(function (ports) {7 console.log(ports);8});9var wptools = require('wptools');10wptools.getPorts(function (ports) {11 console.log(ports);12});13var wptools = require('wptools');14wptools.getPorts(function (ports) {15 console.log(ports);16});17var wptools = require('wptools');18wptools.getPorts(function (ports) {19 console.log(ports);20});21var wptools = require('wptools');22wptools.getPorts(function (ports) {23 console.log(ports);24});25var wptools = require('wptools');26wptools.getPorts(function (ports) {27 console.log(ports);28});29var wptools = require('wptools');30wptools.getPorts(function (ports) {31 console.log(ports);32});
Using AI Code Generation
1var wptools = require('wptools');2wptools.getPorts(function(ports){3console.log(ports);4});5var getPorts = function(callback){6var ports = [3000, 3001, 3002];7callback(ports);8}9module.exports.getPorts = getPorts;
Using AI Code Generation
1const wptoolkit = require('wptoolkit');2const port = wptoolkit.getPorts();3console.log(port);4Output: { dev: 8080, prod: 80 }5const wptoolkit = require('wptoolkit');6const port = wptoolkit.getPorts();7console.log(port);8Output: { dev: 8080, prod: 80 }9const wptoolkit = require('wptoolkit');10const url = wptoolkit.getSiteURL();11console.log(url);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!