Best JavaScript code snippet using taiko
metaquerycore.spec.js
Source:metaquerycore.spec.js
1/*eslint-env node, mocha*/2/**3 * @author kecso / https://github.com/kecso4 */5var testFixture = require('../../_globals.js');6describe('meta query core', function () {7 'user strict';8 var gmeConfig = testFixture.getGmeConfig(),9 Q = testFixture.Q,10 expect = testFixture.expect,11 logger = testFixture.logger.fork('metaquerycore.spec'),12 storage,13 projectName = 'metaQueryTesting',14 core,15 rootNode,16 baseRootHash,17 gmeAuth,18 baseNodes = {19 '': null,20 '/1924875415': null,21 '/1924875415/1059131120': null,22 '/1924875415/1359805212': null,23 '/1924875415/1544821790': null,24 };25 before(function (done) {26 testFixture.clearDBAndGetGMEAuth(gmeConfig, projectName)27 .then(function (gmeAuth_) {28 gmeAuth = gmeAuth_;29 storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth);30 return storage.openDatabase();31 })32 .then(function () {33 return testFixture.importProject(storage, {34 projectSeed: 'test/common/core/metacachecore/project.webgmex',35 projectName: projectName,36 branchName: 'base',37 gmeConfig: gmeConfig,38 logger: logger39 });40 })41 .then(function (result) {42 core = result.core;43 rootNode = result.rootNode;44 baseRootHash = result.rootHash;45 })46 .nodeify(done);47 });48 after(function (done) {49 Q.allDone([50 storage.closeDatabase(),51 gmeAuth.unload()52 ])53 .nodeify(done);54 });55 beforeEach(function (done) {56 var keys = Object.keys(baseNodes),57 i;58 for (i = 0; i < keys.length; i += 1) {59 baseNodes[keys[i]] = null;60 }61 //we load all the nodes that we wish to work with62 Q.nfcall(core.loadRoot, baseRootHash)63 .then(function (root) {64 rootNode = root;65 baseNodes[''] = root;66 return Q.allDone([67 testFixture.loadNode(core, rootNode, '/1924875415'),68 testFixture.loadNode(core, rootNode, '/1924875415/1059131120'),69 testFixture.loadNode(core, rootNode, '/1924875415/1359805212'),70 testFixture.loadNode(core, rootNode, '/1924875415/1544821790')71 ]);72 })73 .then(function (results) {74 var i;75 for (i = 0; i < results.length; i += 1) {76 if (baseNodes[core.getPath(results[i])] === null) {77 baseNodes[core.getPath(results[i])] = results[i];78 }79 }80 })81 .nodeify(done);82 });83 it('should return every possible children type with basic check', function () {84 var validPaths = [85 '/367050797/1776478501',86 '/367050797/355480347',87 '/367050797/625420143',88 '/367050797/1626677559'89 ],90 parameters = {91 node: baseNodes['/1924875415'],92 children: [],93 sensitive: false,94 multiplicity: false95 },96 paths = [],97 i,98 validNodes = core.getValidChildrenMetaNodes(parameters);99 for (i = 0; i < validNodes.length; i += 1) {100 paths.push(core.getPath(validNodes[i]));101 }102 expect(paths).to.have.members(validPaths);103 });104 it('should return non-abstract children type with sensitive check', function () {105 var validPaths = [106 '/367050797/355480347',107 '/367050797/625420143',108 '/367050797/1626677559'109 ],110 parameters = {111 node: baseNodes['/1924875415'],112 children: [],113 sensitive: true,114 multiplicity: false115 },116 paths = [],117 i,118 validNodes = core.getValidChildrenMetaNodes(parameters);119 for (i = 0; i < validNodes.length; i += 1) {120 paths.push(core.getPath(validNodes[i]));121 }122 expect(paths).to.have.members(validPaths);123 });124 it('should return valid children type based on multiplicity', function () {125 var validPaths = [126 '/367050797/1626677559'127 ],128 parameters = {129 node: baseNodes['/1924875415'],130 children: [131 baseNodes['/1924875415/1059131120'],132 baseNodes['/1924875415/1359805212'],133 baseNodes['/1924875415/1544821790']134 ],135 sensitive: true,136 multiplicity: true137 },138 paths = [],139 i,140 validNodes = core.getValidChildrenMetaNodes(parameters);141 for (i = 0; i < validNodes.length; i += 1) {142 paths.push(core.getPath(validNodes[i]));143 }144 expect(paths).to.have.members(validPaths);145 });146 it('should return valid children type not based on multiplicity if children is not given', function () {147 var validPaths = [148 '/367050797/355480347',149 '/367050797/625420143',150 '/367050797/1626677559'151 ],152 parameters = {153 node: baseNodes['/1924875415'],154 children: [],155 sensitive: true,156 multiplicity: true157 },158 paths = [],159 i,160 validNodes = core.getValidChildrenMetaNodes(parameters);161 for (i = 0; i < validNodes.length; i += 1) {162 paths.push(core.getPath(validNodes[i]));163 }164 expect(paths).to.have.members(validPaths);165 });166 it('should return every valid meta child and ignore elements of rule outside of the meta', function () {167 var validPaths = [168 '/367050797/355480347',169 '/367050797/625420143',170 '/367050797/1626677559'171 ],172 parameters = {173 node: baseNodes['/1924875415'],174 children: [175 baseNodes['/1924875415/1059131120'],176 baseNodes['/1924875415/1359805212'],177 baseNodes['/1924875415/1544821790']178 ],179 sensitive: true180 },181 paths = [],182 metaNodes = core.getAllMetaNodes(baseNodes['/1924875415/1359805212']),183 i,184 validNodes;185 core.setChildMeta(metaNodes['/367050797/1626677559'], baseNodes['/1924875415/1359805212']);186 validNodes = core.getValidChildrenMetaNodes(parameters);187 for (i = 0; i < validNodes.length; i += 1) {188 paths.push(core.getPath(validNodes[i]));189 }190 expect(paths).to.have.members(validPaths);191 core.delChildMeta(metaNodes['/367050797/1626677559'], '/1924875415/1359805212');192 });193 it('should return every valid meta child and ignore elements of rule outside of the meta', function () {194 //model /367050797/1626677559195 //actual port /1924875415/1359805212196 var parameters = {197 node: baseNodes['/1924875415'],198 children: [199 baseNodes['/1924875415/1059131120'],200 baseNodes['/1924875415/1359805212'],201 baseNodes['/1924875415/1544821790']202 ],203 sensitive: true,204 multiplicity: true,205 aspect: 'oneAsp'206 },207 metaNodes = core.getAllMetaNodes(baseNodes['/1924875415/1359805212']),208 validNodes;209 core.setChildMeta(metaNodes['/367050797/1626677559'], baseNodes['/1924875415/1359805212']);210 core.setAspectMetaTarget(metaNodes['/367050797/1626677559'], 'oneAsp', baseNodes['/1924875415/1359805212']);211 validNodes = core.getValidChildrenMetaNodes(parameters);212 expect(validNodes).to.have.length(0);213 core.delChildMeta(metaNodes['/367050797/1626677559'], '/1924875415/1359805212');214 core.delAspectMeta(metaNodes['/367050797/1626677559'], 'oneAsp');215 });216 it('should return every possible member type with basic check', function () {217 var validPaths = [218 '/367050797/625420143'219 ],220 parameters = {221 node: baseNodes['/1924875415'],222 members: [],223 sensitive: false,224 multiplicity: false,225 name: 'ins'226 },227 paths = [],228 i,229 validNodes = core.getValidSetElementsMetaNodes(parameters);230 for (i = 0; i < validNodes.length; i += 1) {231 paths.push(core.getPath(validNodes[i]));232 }233 expect(paths).to.have.members(validPaths);234 });235 it('should return every possible, non-abstract member type with sensitive check', function () {236 var validPaths = [237 '/367050797/625420143'238 ],239 parameters = {240 node: baseNodes['/1924875415'],241 members: [],242 sensitive: true,243 multiplicity: false,244 name: 'ins'245 },246 paths = [],247 i,248 validNodes = core.getValidSetElementsMetaNodes(parameters);249 for (i = 0; i < validNodes.length; i += 1) {250 paths.push(core.getPath(validNodes[i]));251 }252 expect(paths).to.have.members(validPaths);253 });254 it('should return every possible member type with multiplicity check', function () {255 var validPaths = [],256 parameters = {257 node: baseNodes['/1924875415'],258 members: [259 baseNodes['/1924875415/1544821790'],260 core.getAllMetaNodes(rootNode)['/367050797/625420143']261 ],262 sensitive: true,263 multiplicity: true,264 name: 'ins'265 },266 paths = [],267 i,268 validNodes = core.getValidSetElementsMetaNodes(parameters);269 for (i = 0; i < validNodes.length; i += 1) {270 paths.push(core.getPath(validNodes[i]));271 }272 expect(paths).to.have.members(validPaths);273 });274 it('should return every possible member type despite multiplicity check if no members given', function () {275 var validPaths = [276 '/367050797/625420143'277 ],278 parameters = {279 node: baseNodes['/1924875415'],280 members: [],281 sensitive: true,282 multiplicity: true,283 name: 'ins'284 },285 paths = [],286 i,287 validNodes = core.getValidSetElementsMetaNodes(parameters);288 for (i = 0; i < validNodes.length; i += 1) {289 paths.push(core.getPath(validNodes[i]));290 }291 expect(paths).to.have.members(validPaths);292 });...
metaquerycore.js
Source:metaquerycore.js
1/*globals define*/2/*eslint-env node, browser*/3/**4 * @author kecso / https://github.com/kecso5 */6define([7 'common/core/CoreAssert'8], function (ASSERT) {9 'use strict';10 var MetaQueryCore = function (innerCore, options) {11 ASSERT(typeof options === 'object');12 ASSERT(typeof options.globConf === 'object');13 ASSERT(typeof options.logger !== 'undefined');14 var logger = options.logger,15 self = this,16 key;17 for (key in innerCore) {18 this[key] = innerCore[key];19 }20 logger.debug('initialized MetaQueryCore');21 //<editor-fold=Helper Functions>22 function sensitiveFilter(validNodes) {23 var i;24 i = validNodes.length;25 while (i--) {26 if (self.isConnection(validNodes[i]) || self.isAbstract(validNodes[i])) {27 validNodes.splice(i, 1);28 }29 }30 }31 //</editor-fold>32 //<editor-fold=Modified Methods>33 //</editor-fold>34 //<editor-fold=Added Methods>35 this.isAbstract = function (node) {36 return self.getRegistry(node, 'isAbstract') === true;37 };38 this.isConnection = function (node) {39 var validPtrNames = innerCore.getValidPointerNames(node);40 return validPtrNames.indexOf('dst') !== -1 && validPtrNames.indexOf('src') !== -1;41 };42 this.getValidChildrenMetaNodes = function (parameters) {43 var validNodes = [],44 node = parameters.node,45 metaNodes = self.getAllMetaNodes(node),46 keys = Object.keys(metaNodes || {}),47 validChildren = innerCore.getValidChildrenPaths(node),48 i, j,49 typeCounters = {},50 children = parameters.children || [],51 cache = parameters.cache || {},52 rules,53 inAspect;54 rules = innerCore.getChildrenMeta(node) || {};55 for (i = 0; i < keys.length; i += 1) {56 for (j = 0; j < validChildren.length; j += 1) {57 if (innerCore.isTypeOf(metaNodes[keys[i]], validChildren[j], cache)) {58 validNodes.push(metaNodes[keys[i]]);59 }60 }61 }62 //before every next step we check if we still have potential nodes63 if (validNodes.length === 0) {64 return validNodes;65 }66 if (parameters.sensitive === true) {67 sensitiveFilter(validNodes);68 }69 //before every next step we check if we still have potential nodes70 if (validNodes.length === 0) {71 return validNodes;72 }73 if (parameters.multiplicity === true) {74 if (rules.max && rules.max > -1 && innerCore.getChildrenRelids(node).length >= rules.max) {75 validNodes = [];76 return validNodes;77 }78 if (children.length === 0) {79 return validNodes; //we cannot check type-multiplicity without children80 }81 delete rules.max;82 delete rules.min;83 keys = Object.keys(rules);84 for (i = 0; i < children.length; i += 1) {85 for (j = 0; j < keys.length; j += 1) {86 if (innerCore.isTypeOf(children[i], keys[j])) {87 if (!typeCounters[keys[j]]) {88 typeCounters[keys[j]] = 0;89 }90 typeCounters[keys[j]] += 1;91 }92 }93 }94 i = validNodes.length;95 keys = Object.keys(typeCounters);96 while (i--) {97 for (j = 0; j < keys.length; j += 1) {98 if (rules[keys[j]].max &&99 rules[keys[j]].max > -1 &&100 rules[keys[j]].max <= typeCounters[keys[j]] &&101 innerCore.isTypeOf(validNodes[i], keys[j])) {102 validNodes.splice(i, 1); //FIXME slow, use only push instead103 break;104 }105 }106 }107 }108 //before every next step we check if we still have potential nodes109 if (validNodes.length === 0) {110 return validNodes;111 }112 if (parameters.aspect) {113 keys = innerCore.getAspectMeta(node, parameters.aspect) || [];114 i = validNodes.length;115 while (i--) {116 inAspect = false;117 for (j = 0; j < keys.length; j += 1) {118 if (innerCore.isTypeOf(validNodes[i], keys[j])) {119 inAspect = true;120 break;121 }122 }123 if (!inAspect) {124 validNodes.splice(i, 1);125 }126 }127 }128 return validNodes;129 };130 this.getValidSetElementsMetaNodes = function (parameters) {131 var validNodes = [],132 node = parameters.node,133 name = parameters.name,134 metaNodes = self.getAllMetaNodes(node),135 keys = Object.keys(metaNodes || {}),136 i, j,137 typeCounters = {},138 members = parameters.members || [],139 rules = self.getPointerMeta(node, name) || {};140 for (i = 0; i < keys.length; i += 1) {141 if (metaNodes[keys[i]] && self.isValidTargetOf(metaNodes[keys[i]], node, name)) {142 validNodes.push(metaNodes[keys[i]]);143 }144 }145 //before every next step we check if we still have potential nodes146 if (validNodes.length === 0) {147 return validNodes;148 }149 if (parameters.sensitive === true) {150 sensitiveFilter(validNodes);151 }152 //before every next step we check if we still have potential nodes153 if (validNodes.length === 0) {154 return validNodes;155 }156 if (parameters.multiplicity === true) {157 if (rules.max && rules.max > -1 && innerCore.getMemberPaths(node).length >= rules.max) {158 validNodes = [];159 return validNodes;160 }161 if (members.length === 0) {162 return validNodes; //we cannot check type-multiplicity without children163 }164 delete rules.max;165 delete rules.min;166 //we need to clear nodes that are not on the meta sheet167 // and we have to initialize the counters168 keys = Object.keys(rules);169 for (i = 0; i < keys.length; i += 1) {170 if (!metaNodes[keys[i]]) {171 delete rules[keys[i]];172 } else {173 typeCounters[keys[i]] = 0;174 }175 }176 keys = Object.keys(rules);177 for (i = 0; i < members.length; i += 1) {178 for (j = 0; j < keys.length; j += 1) {179 if (innerCore.isTypeOf(members[i], keys[j])) {180 typeCounters[keys[j]] += 1;181 }182 }183 }184 i = validNodes.length;185 keys = Object.keys(typeCounters);186 while (i--) {187 for (j = 0; j < keys.length; j += 1) {188 if (rules[keys[j]].max &&189 rules[keys[j]].max > -1 &&190 rules[keys[j]].max <= typeCounters[keys[j]] &&191 innerCore.isTypeOf(validNodes[i], keys[j])) {192 validNodes.splice(i, 1); //FIXME slow, use only push instead193 break;194 }195 }196 }197 }198 return validNodes;199 };200 //</editor-fold>201 };202 return MetaQueryCore;...
QtConnect.ts
Source:QtConnect.ts
1import QTreeBranch from "./QTreeBranch";2import QTreeNode from "./QTreeNode";3import QTreeLeaf from "./QTreeLeaf";4const searchLeft = (left: QTreeNode, right: QTreeLeaf) => {5 if (right.deleted()) {6 if (left instanceof QTreeBranch) {7 const hitted = left as QTreeBranch;8 hitted.getNodes().forEach(hittedItem => searchLeft(hittedItem, right));9 } else {10 const leaf = left as QTreeLeaf;11 /*12 * åªæ¯è¾æ¡ä»¶ï¼ä¸æ¯è¾å¼13 */14 if (leaf.isSame(right)) {15 /*16 * field,op é¨åç¸çï¼èå¼ä¸ç¸ç17 */18 leaf.saveNode(right);19 }20 }21 }22};23const updateTree = (left: QTreeBranch, right: QTreeNode) => {24 if (right instanceof QTreeBranch) {25 const hitted = right as QTreeBranch;26 hitted.getNodes().forEach(hittedItem => updateTree(left, hittedItem));27 } else {28 searchLeft(left, right as QTreeLeaf);29 }30};31const join = (left: QTreeBranch, right: QTreeBranch,32 isAnd: Boolean = false): QTreeBranch => {33 /*34 * æé æ°çæ å¤ç35 */36 const branch = new QTreeBranch({"": isAnd});37 /*38 * å é¤èç¹çæ´æ°39 */40 updateTree(left, right);41 /*42 * æ¯è¾å·¦æ åå³æ 43 */44 if (isAnd) {45 /*46 * left å right ä½¿ç¨ AND è¿æ¥ç¬¦47 * ( a AND b ) AND ( c AND d )48 * ( a AND b ) AND ( c OR d )49 * ( a OR b ) AND ( c AND d )50 * ( a OR b ) AND ( c OR d )51 */52 if (left.isAnd()) {53 left.getNodes().forEach(node => branch.addNode(node));54 } else {55 branch.addNode(left);56 }57 if (right.isAnd()) {58 right.getNodes().forEach(node => branch.addNode(node));59 } else {60 branch.addNode(right);61 }62 } else {63 /*64 * left å right ä½¿ç¨ OR è¿æ¥ç¬¦65 * ( a AND b ) OR ( c AND d )66 * ( a AND b ) OR ( c OR d )67 * ( a OR b ) OR ( c AND d )68 * ( a OR b ) OR ( c OR d )69 */70 if (left.isAnd()) {71 branch.addNode(left);72 } else {73 left.getNodes().forEach(node => branch.addNode(node));74 }75 if (right.isAnd()) {76 branch.addNode(right);77 } else {78 right.getNodes().forEach(node => branch.addNode(node));79 }80 }81 return branch;82};83const combineBranch = (content: any = {}, node: QTreeBranch, keyIfMore: any) => {84 const nodeContent = node.to();85 if (1 < node.getNodes().length &&86 /*87 * é²æ¢ nodeContent = {} èçæ88 * $x = {} çæ¥è¯¢æ¡ä»¶ï¼500 Error89 */90 0 < Object.keys(nodeContent).length) {91 /*92 * é¿åº¦å¤§äº1ï¼å³åæ ä¸å级ï¼é£ä¹å¯ç¨ keyIfMore93 */94 content[keyIfMore] = nodeContent;95 } else {96 /*97 * é¿åº¦ == 1ï¼ç´æ¥å并98 */99 Object.assign(content, nodeContent);100 }101};102const combine = (nodes: Array<QTreeNode>, _isAnd: Boolean) => {103 const content: any = {};104 const validNodes = nodes.filter(node => node.valid());105 /*106 * éå½å并å¤ç107 * 1ï¼åªæ validNodes çé¿åº¦ > 0 æ¶ä¼æ§è¡108 */109 if (0 < validNodes.length) {110 /*111 * é¿åº¦ä¸º1çå¤ç112 */113 if (1 === validNodes.length) {114 const node: QTreeNode = validNodes[0];115 if (node instanceof QTreeLeaf) {116 /*117 * å¦ææ¯å¶èç¹ï¼ç´æ¥å并118 */119 Object.assign(content, node.to())120 } else {121 combineBranch(content, node as QTreeBranch, "$0");122 }123 } else {124 content[""] = _isAnd; // è¿ç§æ
åµæå¤çæä½ç¬¦125 validNodes.forEach((node, index) => {126 if (node instanceof QTreeLeaf) {127 const merged = node.to();128 Object.assign(content, merged);129 } else {130 const key = `$${index}`;131 combineBranch(content, node as QTreeBranch, key);132 }133 });134 /*135 * 计ç®å®æåæ£æ¥136 * 1ï¼ææåèç¹ä¸º __DELETE__ 被å é¤137 * 2ï¼ä»
ä¿çäºæä½ç¬¦å·ä½138 * é²æ¢åèç¹åºç°ï¼139 * {140 * "": true141 * }142 * æ143 * {144 * "": false145 * }146 * 500 Error147 */148 if (1 === Object.keys(content).length && content.hasOwnProperty("")) {149 delete content[""];150 }151 }152 }153 return content;154};155export default {156 join,157 combine,...
Using AI Code Generation
1const { validNodes } = require('taiko');2const { openBrowser, goto, closeBrowser } = require('taiko');3(async () => {4 try {5 await openBrowser();6 console.log(await validNodes("input"));7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13const { validNodes } = require('taiko');14const { openBrowser, goto, closeBrowser } = require('taiko');15(async () => {16 try {17 await openBrowser();18 console.log(await validNodes("input", "test"));19 } catch (e) {20 console.error(e);21 } finally {22 await closeBrowser();23 }24})();25const { validNodes } = require('taiko');26const { openBrowser, goto, closeBrowser } = require('taiko');27(async () => {28 try {29 await openBrowser();30 console.log(await validNodes("input", "test", "test"));31 } catch (e) {32 console.error(e);33 } finally {34 await closeBrowser();35 }36})();37const { validNodes } = require('taiko');38const { openBrowser, goto, closeBrowser } = require('taiko');39(async () => {40 try {41 await openBrowser();42 console.log(await validNodes("input", "test", "test"));43 } catch (e) {44 console.error(e);45 } finally {46 await closeBrowser();47 }48})();
Using AI Code Generation
1import { openBrowser, goto, click, closeBrowser, write, into, button, validNodes } from 'taiko';2(async () => {3 try {4 await openBrowser({ headless: false });5 await click("Sign in");6 await write("taiko", into("Email or phone"));7 await write("taiko", into("Password"));8 await click(button("Next"));9 await click("Sign in");10 await click("Sign in");11 await write("taiko", into("Email or phone"));12 await write("taiko", into("Password"));13 await click(button("Next"));14 await click("Sign in");15 await click("Sign in");16 await write("taiko", into("Email or phone"));17 await write("taiko", into("Password"));18 await click(button("Next"));19 await click("Sign in");20 await click("Sign in");21 await write("taiko", into("Email or phone"));22 await write("taiko", into("Password"));23 await click(button("Next"));24 await click("Sign in");25 await click("Sign in");26 await write("taiko", into("Email or phone"));27 await write("taiko", into("Password"));28 await click(button("Next"));29 await click("Sign in");30 await click("Sign in");31 await write("taiko", into("Email or phone"));32 await write("taiko", into("Password"));33 await click(button("Next"));34 await click("Sign in");35 await click("Sign in");36 await write("taiko", into("Email or phone"));37 await write("taiko", into("Password"));38 await click(button("Next"));39 await click("Sign in");40 await click("Sign in");41 await write("taiko", into("Email or phone"));42 await write("taiko", into("Password"));43 await click(button("Next"));44 await click("Sign in");45 await click("Sign in");46 await write("taiko", into("Email or phone"));47 await write("taiko", into("Password"));48 await click(button("Next"));49 await click("Sign in");50 await click("Sign in");51 await write("taiko", into("Email or phone"));52 await write("taiko", into("Password"));53 await click(button("Next"));
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!!