How to use commandBuilder method in storybook-root

Best JavaScript code snippet using storybook-root

index.js

Source:index.js Github

copy

Full Screen

1'use strict';2function Parser() {}3var lcomand = {words : [], comand:''};4//builds commands for AI5var CommandBuilder = {6//common properties7 isSettingsArea : false,8 isGivenArea : false,9 isTestArea : true,10 waitInterval : 2000,11 given : '',12//test commands13 clickOn : function(element, selector){14 var command = '';15 if (element === "button"){16 command = CommandBuilder.eventsEmitter.buttonEvent("click", selector) + '.then(function () {';17 }else{18 command = CommandBuilder.eventsEmitter.elementEvent(element, selector, "click") + '.then(function () {';19 }20 return command;21 },22 doubleClickOn : function(element, selector){23 var command = '';24 if (element === "button"){25 command = CommandBuilder.eventsEmitter.buttonEvent("doubleClick", selector) + '.then(function () {';26 }else{27 command = CommandBuilder.eventsEmitter.elementEvent(element, selector, "doubleClick") + '.then(function () {';28 }29 return command;30 },31 fillWith : function(selector, value){32 var command = CommandBuilder.formsAction.fillWithValue(value,selector,"id") + '.then(function () {';33 return command;34 },35 shouldBe : function(value1, value2){36 var command = 'driver.wait( function(){if(' + value1 + '!==' + value2 + ') {'+ CommandBuilder.emitError('Values not match. Expected: \" + ' + value1 + ' + \" Got: \" + '+ value2 + '+\"')+ ' return false;} return true;}).then(function(){';37 return command;38 },39 waitFor : function(timeout){40 var command = CommandBuilder.timeManager.sleep(timeout);41 return command;42 },43 moveMouseTo : function(element){44 var command = '';45 command = CommandBuilder.findElementBy.Text(element)+'.then(function(el){ if(el) driver.mouseMove(el);})' + '.then(function () {';46 return command;47 },48 focusOn : function(element){49 var command = '';50 command = CommandBuilder.findElementBy.Text(element) + '.then(function (el) { if(el) driver.move(el); }).then(function () {';51 return command;52 },53 submit : function(element, selector){54 var command = '';55 command = CommandBuilder.eventsEmitter.elementEvent("submit", selector, "value") + '.then(function () {';56 return command;57 },58 focusOn : function(elementId){59 var command = CommandBuilder.moveMouseTo(elementId);60 return command;61 },62 pressKey : function(key){63 //var command = 'driver.findElement(self.By.xpath("//body")).then(function(el){ if (el) el.sendKeys(\''+key+'\');}).then(function(){';64 var command = 'driver.keyDown('+ key +').then(driver.sleep(500)).then(function(){';65 return command;66 },67 radiogroupSelect : function(name, value){68 var command = CommandBuilder.findElementBy.Text(name) + '.then(function(el){ if(el) el.click(); driver.sleep(500);' +69 CommandBuilder.findElementBy.Value(value)+ '.then(function(el){ if(el) el.click()}); }).then(function(){';70 return command;71 },72 selectFromDropdown : function(name, value){73 var command = '';74 command = CommandBuilder.findElementBy.Text(name) + '.then(function(el) { if(el) el.click(); driver.sleep(500);' +75 CommandBuilder.findElementBy.Value(value) + '.then(function(el) { if(el) el.click(); });}).then( function(){';76 return command;77 },78 propertyShouldBe : function(element, propertyName, expectedValue){79 var assertion = 'if(value !== \''+ expectedValue +'\'){'+CommandBuilder.emitError('Unexpected property '+ propertyName +' on element with id '+ element + '. Expected: ' + expectedValue +' Got \"+value+\"')+'}';80 var command = CommandBuilder.findElementBy.Id(element) +81 '.getAttribute(\''+propertyName+'\').then(function(value) {if(value){' + assertion + '}else{' + CommandBuilder.cssPropertyShouldBe(element, propertyName, expectedValue) + ';} }).then(function () {';82 return command;83 },84 cssPropertyShouldBe : function(element, propertyName, expectedValue){85 var assertion = 'if(value !== \''+ expectedValue +'\'){'+ CommandBuilder.emitError('Unexpected css property '+ propertyName +' on element with id '+ element + '. Expected: ' + expectedValue + ' Got \"+value+\"') +'}';86 var command = CommandBuilder.findElementBy.Id(element) +87 '.getCssValue(\''+propertyName+'\').then(function(value) {if(value) ' + assertion + ' })';88 return command;89 },90 waitOnResponse : function(time){91 var command = CommandBuilder.timeManager.waitUntilAjaxComplete(time);92 return command;93 },94 checkRegex : function(element, regex){95 var regexp = new RegExp(regex);96 var assertion = 'if(' + regexp + '.test(value)!==true){'+ CommandBuilder.emitError('regexp '+ regexp + ' test() returned false') +'}';97 var command = CommandBuilder.findElementBy.Id(element) + '.getAttribute(\'value\')' +98 '.then(function(value){ if(value) '+ assertion +' }).then(function(){'99 return command;100 },101 elementWithId : function(Id){102 var command = CommandBuilder.findElementBy.Id(Id);103 return command;104 },105//internal objects for forming commands106 elementsChecker : {107 titleShouldBe : function(value){108 return 'driver.getTitle().then(function(title) { if(title !== ' + '\''+value+'\'' +')' + CommandBuilder.emitError('Titles mismatch! Expected: \''+ value +'\''+ ' Got \"+title+\"') + ' }).then(function(){ ';109 },110 pageShouldContains : function(value){111 return CommandBuilder.findElementBy.Text(value)+'.then(function (el) { if(!el) '+ CommandBuilder.emitError('Page not contains ' + value) +'}).then(function(){';112 }113 },114 eventsEmitter : {115 buttonEvent : function(eventType, buttonText){116 return CommandBuilder.findElementBy.ButtonText(buttonText)+ CommandBuilder.eventsEmitter.emitEvent(eventType);117 },118 elementEvent : function(eventType, value, selector){119 if (selector === "id")120 return CommandBuilder.findElementBy.Id(value) + CommandBuilder.eventsEmitter.emitEvent(eventType);121 if (selector === "text")122 return CommandBuilder.findElementBy.Text(value) + CommandBuilder.eventsEmitter.emitEvent(eventType);123 if (selector === "name")124 return CommandBuilder.findElementBy.Name(value) + CommandBuilder.eventsEmitter.emitEvent(eventType);125 if (selector === "value")126 return CommandBuilder.findElementBy.Value(value) + CommandBuilder.eventsEmitter.emitEvent(eventType);127 },128 emitEvent : function(eventType,parameter){129 var command = '';130 var parameters = '';131 if (parameter){132 parameters = parameter;133 }134 return '.then(function(el){ if(el) el.' + eventType +'('+parameters+'); }).then(function () {';135 }136 },137 findElementBy : {138 Id : function(value){139 return 'driver.findElement(self.By.xpath("//*[@id=\''+value+'\''+']"))';140 },141 Name : function(value){142 return 'driver.findElement(self.By.name(\''+value+'\'))';143 },144 Text : function(value){145 return 'driver.findElement(self.By.xpath("//*[text()=\''+value+'\']"))';146 },147 Placeholder : function(value){148 return 'driver.findElement(self.By.xpath("//*[@placeholder=\''+value+'\']"))'149 },150 ButtonText : function(value){151 return 'driver.findElement(self.By.xpath("//button[text()=\''+value+'\']"))';152 },153 Value : function(value){154 return 'driver.findElement(self.By.xpath("//*[@value=\''+value+'\']"))';155 }156 },157 formsAction : {158 fillWithValue : function (value, propertyValue, selector){159 if (selector === "Id"){160 return CommandBuilder.findElementBy.Id(propertyValue)+'.then(function(el){ if(el) el' + CommandBuilder.sendKeys(value);161 }162 if (selector === "placeholder"){163 return CommandBuilder.findElementBy.Placeholder(propertyValue)+'.then(function(el){ if(el) el' + CommandBuilder.sendKeys(value);164 }165 }166 },167 timeManager : {168 sleep : function(value){169 return 'driver.sleep('+value+'*1000).then(function(){ ';170 },171 wait : function(value){172 return 'driver.sleep('+value+').then(function(){';173 },174 actionUntilTitleIs : function(action, condition){175 return 'driver.' + action + '(self.until.titleIs("' + condition + '"), 1000).then(function(){ ';176 },177 waitUntilAjaxComplete : function(timeout){178 return 'driver.wait(driver.executeScript("return jQuery.active == 0"), ' + timeout + ').then(function () {';179 }180 },181 sendKeys : function(keys){182 return '.sendKeys('+'\''+keys+'\''+');';183 },184 getValueAndCompare : function(keys){185 return '.getAttribute(\'value\').then(function(value){ if(value !==\''+keys+'\') '+ CommandBuilder.emitError('Attribute mismatch. Expected: ' + keys+ ' Got \"+value+\"') +'}).then(null, function(e){return callback(true, e.stack)})';186 },187 emitError : function(message){188 return 'throw new self.error.WebDriverError("' + message + '");';189 },190 setIndex : function(index){191 return 'index = ' + index + ';';192 },193 endpoint : function(inputData, assertOutputData){194 if(inputData.requestBody) inputData.requestBody = ',' + inputData.requestBody;195 else inputData.requestBody = '';196 var responseOps = '';197 if(assertOutputData.statusCode){198 responseOps += 'if(res.response.statusCode !== '+assertOutputData.statusCode+'){'+ CommandBuilder.emitError('Unexpected status code in response. Expected: ' + assertOutputData.statusCode+ ' Got \"+res.response.statusCode+\"') +'}';199 }200 if(assertOutputData.contentType){201 responseOps += 'if(res.response.rawHeaders.indexOf(\''+assertOutputData.contentType+'\') < 0){'+ CommandBuilder.emitError('Unexpected content-type in response. Expected: ' + assertOutputData.contentType+' Got \"+res.response.rawHeaders+\"') +'}';202 }203 if(assertOutputData.responseJSON){204 responseOps += 'if(!scope._.isEqual(res.body,'+assertOutputData.responseJSON+')){'+ CommandBuilder.emitError('Unexpected data in response. Expected: ' + assertOutputData.responseJSON+ ' Got \"+res.body+\"') +'}';205 }206 if(assertOutputData.dataProperty){207 responseOps += 'if(res.body.' + assertOutputData.dataProperty.name + ' !== ' + assertOutputData.dataProperty.value + '){'+ CommandBuilder.emitError('Unexpected \''+ assertOutputData.dataProperty.name +'\' property value in response data. Expected: ' + assertOutputData.dataProperty.value + ' Got \"+res.body.'+assertOutputData.dataProperty.name+'+\"') +'}'208 }209 if(assertOutputData.saveVar){210 var variable = assertOutputData.saveVar;211 if(variable.indexOf("[") === 0 && variable.indexOf("]") === 2){212 responseOps += 'saved = {'+ assertOutputData.saveVar.slice(4, assertOutputData.saveVar.length) + ' : res.body' + assertOutputData.saveVar + '};';213 }else{214 if(variable === 'ALL_BODY'){215 responseOps += 'saved = res.body;';216 }else{217 responseOps += 'saved = {'+ assertOutputData.saveVar + ' : res.body.' + assertOutputData.saveVar + '};'218 }219 }220 }221 return 'driver.wait(scope.chakram.'+ inputData.requestType +'('+222 inputData.address + inputData.requestBody + ').then(function(res){'+223 responseOps +224 '}), 5000).then(function(){';225 },226//search command keywords in current line <input.words> and if founded, return this command227 findElement : function(input, currentRow){228 var count = 0; //var for calculating words in human command229 var found = false; //found command indicator230 var words = input.words; //input human command231 var comand = input.comand; //output AI command232 //keywords in human language233 var controls = ['move', 'mouse', 'focus', 'press'];234 var assertion = ['css-property','property', 'should','check'];235 var events = ['click', 'doubleclick', 'change', 'blur', 'contextmenu', 'keydown', 'keypress', 'keyup', 'mouseenter', 'mousedown',236 'mouseUp', 'mouseleave', 'mouseover', 'mouseMove', 'scroll', 'select', 'submit', 'hover', 'ready', 'resize'];237 var elements = ['name', 'id', 'title', 'page', 'radiogroup', 'dropdown'];238 var forms = ['fill'];239 var time = ['wait'];240 var endpoint = ['endpoint', 'data', 'dataProperty', 'response', 'status','content-type', 'return', 'save',241 'get', 'post', 'put', 'patch', 'delete'];242 //search commands by defined keywords243 //detecting #Settings block244 if(words[0] === '#Settings' && !CommandBuilder.isSettingsArea){245 CommandBuilder.isSettingsArea = true;246 CommandBuilder.isGivenArea = false;247 CommandBuilder.isTestArea = false;248 found = true;249 }250 //detecting configuration for #Settings251 if(time.indexOf(words[0]) > -1 && CommandBuilder.isSettingsArea){252 if(words[5] === 's') CommandBuilder.waitInterval = parseFloat(words[4])*1000;253 else if(words[5] === 'ms') CommandBuilder.waitInterval = words[4];254 else if(words[5] === 'min') CommandBuilder.waitInterval = parseFloat(words[4])*1000*60;255 else CommandBuilder.waitInterval = words[4];256 found = true;257 }258 //detecting #Given block259 if(words[0] === '#Given'){260 CommandBuilder.isSettingsArea = false;261 CommandBuilder.isGivenArea = true;262 CommandBuilder.isTestArea = false;263 found = true;264 }265 //detecting variable definition for #Given266 if(words[1] === 'is' && CommandBuilder.isGivenArea){267 CommandBuilder.given += 'var ' + words[0] + ' = ' + words[2] + ';';268 found = true;269 }270 //detecting #Test block271 if(words[0] === "#Test"){272 CommandBuilder.isTestArea = true;273 CommandBuilder.isGivenArea = false;274 CommandBuilder.isSettingsArea = false;275 found = true;276 }277 //detecting test commands278 if(assertion.indexOf(words[2]) > -1){279 if(words[2] === 'property'){280 comand += CommandBuilder.propertyShouldBe(words[0], words[1], words[5]) + CommandBuilder.setIndex(currentRow);281 }282 count += words.length;283 found = true;284 }285 if(assertion.indexOf(words[1]) > -1){286 if (words[1] === 'should' && elements.indexOf(words[0]) === -1){287 comand += CommandBuilder.shouldBe(words[0], words[3]) + CommandBuilder.setIndex(currentRow);288 }else{289 if(words[1] === 'check'){290 comand += CommandBuilder.checkRegex(words[0],words[3]) + CommandBuilder.setIndex(currentRow);291 }292 }293 count += words.length;294 found = true;295 }296 if(controls.indexOf(words[0]) > -1) {297 if(words[0] === 'move'){298 comand += CommandBuilder.moveMouseTo(words[3]) + CommandBuilder.setIndex(currentRow);299 }300 else if(words[0] === 'focus'){301 comand += CommandBuilder.focusOn(words[2]) + CommandBuilder.setIndex(currentRow);302 }else if(words[0] === 'press'){303 comand += CommandBuilder.pressKey(words[2]) + CommandBuilder.setIndex(currentRow);304 }305 count += words.length;306 found = true;307 }308 if(elements.indexOf(words[0]) > -1) {309 if(words[0] === 'submit'){310 comand += CommandBuilder.findElementBy.Id(word[4]) + CommandBuilder.emitEvent(words[0]) + CommandBuilder.setIndex(currentRow);311 }312 else if(words[0] === 'title') {313 if(words[1] === 'should')314 if(words[2] === 'be'){315 comand+= CommandBuilder.elementsChecker.titleShouldBe(words[3]) + CommandBuilder.setIndex(currentRow);316 }317 }318 else if(words[0] === 'page') {319 if(words[1] === 'should') {320 if(words[2] === 'contains') {321 comand+= CommandBuilder.elementsChecker.pageShouldContains(words[3]) + CommandBuilder.setIndex(currentRow);322 }323 }324 }325 else if(words[0] === 'dropdown'){326 comand += CommandBuilder.selectFromDropdown(words[1], words[3]) + CommandBuilder.setIndex(currentRow);327 }328 else if(words[0] === 'radiogroup'){329 comand += CommandBuilder.radiogroupSelect(words[1], words[3]) + CommandBuilder.setIndex(currentRow);330 }331 else {332 comand+= CommandBuilder.elementsChecker.findElementBy.Value(words[0]) + CommandBuilder.setIndex(currentRow);333 }334 count += words.length;335 found = true;336 }337 if(events.indexOf(words[0]) > -1) {338 if(words[1] === 'button'){339 comand += CommandBuilder.eventsEmitter.buttonEvent(words[0], words[2]) + CommandBuilder.setIndex(currentRow);340 //count+=3;341 } else if(words[1] === 'element'){342 if (words[2] === 'with'){343 if(words[3] === 'id'){344 comand += CommandBuilder.eventsEmitter.elementEvent(words[0], words[4], "id") + CommandBuilder.setIndex(currentRow);345 }346 if(words[3] === 'text'){347 comand += CommandBuilder.eventsEmitter.elementEvent(words[0], words[4], "text") + CommandBuilder.setIndex(currentRow);348 }349 if(words[3] === 'name'){350 comand += CommandBuilder.eventsEmitter.elementEvent(words[0], words[4], "name") + CommandBuilder.setIndex(currentRow);351 }352 if(words[3] === 'value'){353 comand += CommandBuilder.eventsEmitter.elementEvent(words[0], words[4], "text") + CommandBuilder.setIndex(currentRow);354 }355 }356 } else {357 comand += CommandBuilder.eventsEmitter.elementEvent(words[0],words[1],"text") + CommandBuilder.setIndex(currentRow);358 }359 count += words.length;360 found = true;361 }362 if(forms.indexOf(words[0]) > -1) {363 if(words[1] === 'element'){364 if (words[2] === 'with') {365 if(words[3] === 'id') {366 comand += CommandBuilder.formsAction.fillWithValue(words[5], words[4],"Id") + CommandBuilder.setIndex(currentRow);367 }368 if(words[3] === 'placeholder') {369 comand += CommandBuilder.formsAction.fillWithValue(words[5], words[4],"placeholder") + CommandBuilder.setIndex(currentRow);370 }371 }372 } else {373 comand+= CommandBuilder.formsAction.fillWithValue(words[2],words[1],"placeholder") + CommandBuilder.setIndex(currentRow)374 }375 count += words.length;376 found = true;377 }378 if(time.indexOf(words[0]) > -1 && CommandBuilder.isTestArea) {379 switch(words.length){380 case(2):381 comand+= CommandBuilder.timeManager.sleep(words[1]) + CommandBuilder.setIndex(currentRow);382 break;383 case(3):384 if(words[2] === 'ms') comand += CommandBuilder.timeManager.wait(words[1]) + CommandBuilder.setIndex(currentRow);385 if(words[2] === 's') comand += CommandBuilder.timeManager.wait(words[1]*1000) + CommandBuilder.setIndex(currentRow);386 if(words[2] === 'min') comand += CommandBuilder.timeManager.wait(words[1]*1000*60) + CommandBuilder.setIndex(currentRow);387 else comand += CommandBuilder.timeManager.wait(words[1]*1000) + CommandBuilder.setIndex(currentRow);388 break;389 case(4):390 comand += CommandBuilder.waitOnResponse(words[3]) + CommandBuilder.setIndex(currentRow);391 break;392 default:393 comand+= CommandBuilder.timeManager.actionUntilTitleIs(words[0], words[4]) + CommandBuilder.setIndex(currentRow);394 break;395 }396 count += words.length;397 found = true;398 }399 if(endpoint.indexOf(words[0]) > -1) {400 var expectedJSON, expectedContentType, expectedStatus, expectedProperty, saveVar,401 index,402 requestBody;403 if(words[3] === 'should' && words[4] === 'return'){404 index = 5; // after this word we specify expected values from response only405 }406 if(words[3] === 'data'){407 requestBody = words[4];408 if(words[5] === 'should' && words[6] === 'return') index = 7;409 }410 while(index < words.length){ //parse expected response411 if(words[index] === 'data') expectedJSON = words[index+1];412 if(words[index] === 'dataProperty') expectedProperty = {413 name : words[index+1],414 value : words[index+2]415 }416 if(words[index] === 'status') expectedStatus = words[index+1];417 if(words[index] === 'content-type') expectedContentType = words[index+1];418 if(words[index] === 'save') saveVar = words[index+1];419 index++;420 }421 var request = {422 requestType : words[0],423 address : words[2],424 requestBody : requestBody425 }426 var expectedResponse = {427 statusCode : expectedStatus,428 responseJSON : expectedJSON,429 contentType : expectedContentType,430 dataProperty : expectedProperty,431 saveVar : saveVar432 }433 comand += CommandBuilder.endpoint(request, expectedResponse) + CommandBuilder.setIndex(currentRow);434 count += words.length;435 }436 var result = {437 comand: comand,438 words: words,439 count: count,440 found: found,441 row : currentRow442 };443 return result;444 },445 findByParam : function(input, currentRow){446 var result = CommandBuilder.findElement(input, currentRow);447 if(result.found){448 switch (result.words[2]) {449 case 'set':450 result.comand+= CommandBuilder.sendKeys(result.words[3]);451 result.count+=2;452 break;453 case 'get':454 result.comand+= CommandBuilder.getValueAndCompare(result.words[3]);455 result.count+=2;456 break;457 default:458 input.words = [];459 break;460 }461 }462 //check if words are correctly counted463 if (result.count==input.words.length) {464 input.words = [];465 }466 else{467 input.words = input.words.slice(result.count);468 }469 //add a separator \n for current command470 if(result.comand){471 input.comand = result.comand+'\n';472 }473 },474 //launch command search475 createComand : function(argument, currentRow) {476 while (argument.words.length!=0) {477 CommandBuilder.findByParam(argument, currentRow);478 }479 },480 //add closing brackets and timeout for all AI commands and return this commands481 finalize : function(command){482 var length = command.split(/\n/).length;483 for(var i = 0; i < length-1; i++) {484 command += ' }, function(err){ scope.callback(true, err, index); driver.sleep('+ CommandBuilder.waitInterval +'); return driver.quit() }) \n ';485 }486 return command;487 }488}489//parser initialize490Parser.prototype.start = function(str, callback) {491 CommandBuilder.waitInterval = 2000;492 CommandBuilder.given = '';493 lcomand.comand = '';494 var comands = str.split('\n');//every human command must be in single line495 for (var i = 0; i < comands.length; i++) {496 var lwords = comands[i].match(/(?:[^\s"]+|"[^"]*")+/g);497 if (!lwords) {498 continue;499 }500 //remove spaces and "501 for (var j = 0; j < lwords.length; j++) {502 lwords[j]=lwords[j].trim();503 if(lwords[j][0] == '\"' && lwords[j][lwords[j].length - 1] == '\"'){504 lwords[j] = lwords[j].substring(1, lwords[j].length - 1);505 }506 }507 if(lwords.length!=0){508 lcomand.words = lwords;509 CommandBuilder.createComand(lcomand, i + 2);//currentRow needs increment, because loop starting from 0510 }511 }512 //forming command from input513 if(lcomand.comand){514 var res = 'var self = scope.wd; var saved; var index = 1;\n' + CommandBuilder.given +'\n'+ CommandBuilder.finalize(lcomand.comand);515 callback(null, res);516 }517 else {518 callback('Error');519 }520};...

Full Screen

Full Screen

command.ts

Source:command.ts Github

copy

Full Screen

...40 },41 header: defaultHeader(uuid),42});43export const alwaysDay = (lock?: boolean) =>44 commandBuilder(`alwaysday ${lock || ''}`);45export const clear = (player?: Target | TargetSelector, itemName?: Block | Item, dataValue?: number, maxCount?: number) =>46 commandBuilder(`clear ${player || ''} ${itemName || ''} ${dataValue === undefined ? '' : dataValue} ${maxCount === undefined ? '' : maxCount}`);47export const clone = (begin: Position, end: Position, destination: Position, maskMode?: MaskMode, cloneMode?: CloneMode, tileName?: Block, dataValue?: number) =>48 commandBuilder(`clone ${begin} ${end} ${destination} ${maskMode || ''} ${cloneMode || ''} ${tileName || ''} ${dataValue === undefined ? '' : dataValue}`);49export const connect = (serverUri: string) =>50 wsServer(serverUri)51export const dayLock = (lock?: boolean) =>52 alwaysDay(lock);53export const deOp = (player: Target | TargetSelector) =>54 commandBuilder(`deop ${player}`);55export const difficulty = (difficulty: Difficulty) =>56 commandBuilder(`difficulty ${difficulty}`);57export const effect = (player: Target | TargetSelector, effect: Effect, seconds?: number, amplifier?: number, hideParticles?: boolean) =>58 commandBuilder(`effect ${player} ${effect} ${seconds === undefined ? '' : seconds} ${amplifier === undefined ? '' : amplifier} ${hideParticles || ''}`);59export const enchant = (player: Target | TargetSelector, enchantment: Enchant, level?: number) =>60 commandBuilder(`enchant ${player} ${enchantment} ${level === undefined ? '' : level}`);61// executeは後で実装する62export const fill = (from: Position, to: Position, tileName: Block | string, dataValue?: number, oldBlockHandling?: OldBlockHandling, replaceTileName?: Block | string, replaceDataValue?: number) =>63 commandBuilder(`fill ${from} ${to} ${tileName} ${dataValue === undefined ? '' : dataValue} ${oldBlockHandling || ''} ${replaceTileName || ''} ${replaceDataValue || ''}`);64// functionは後で実装する65export const gameMode = (gameMode: GameMode, player?: Target | TargetSelector) =>66 commandBuilder(`gamemode ${gameMode} ${player || ''}`);67export const gameRule = (rule: Rule | string, value?: boolean | number) =>68 commandBuilder(`gamerule ${rule} ${value || ''}`);69export const give = (player: Target | TargetSelector, itemName: Block | Item, amount?: number, dataValue?: number) =>70 commandBuilder(`give ${player} ${itemName} ${amount === undefined ? '' : amount} ${dataValue === undefined ? '' : dataValue}`);71export const help = (command?: Commands, page?: number) =>72 commandBuilder(`help ${command || ''} ${page === undefined ? '' : page}`);73export const kill = (target?: Target | TargetSelector) =>74 commandBuilder(`kill ${target || ''}`);75export const list = (details?: ListDetails) =>76 commandBuilder(`list ${details || ''}`);77export const locate = (feature: Feature) =>78 commandBuilder(`locate ${feature}`);79export const me = (message: string) =>80 commandBuilder(`me ${message}`);81export const mixer = (mixerControl: MixerControl, sceneNameOrVersionID: string | number, commonCode?: string) =>82 commandBuilder(`mixer ${mixerControl} ${sceneNameOrVersionID} ${commonCode || ''}`);83export const mobEvent = (eventName: MobEvent, on?: boolean) =>84 commandBuilder(`mobevent ${eventName} ${on || ''}`);85export const msg = (target: Target | TargetSelector, message: string) =>86 tell(target, message);87export const op = (player: Target | TargetSelector) =>88 commandBuilder(`op ${player}`);89export const particle = (particle: Particle, position: Position, length: Position, speed: number, count?: number, mode?: ParticleMode, player?: Target | TargetSelector) =>90 commandBuilder(`particle ${particle} ${position} ${length} ${speed} ${count === undefined ? '' : count} ${mode || ''} ${player || ''}`);91export const playSound = (sound: string, player?: Target | TargetSelector, position?: Position, volume?: number, pitch?: number, minimumVolume?: number) =>92 commandBuilder(`playsound ${sound} ${player || ''} ${player || ''} ${position || ''} ${volume === undefined ? '' : volume} ${pitch === undefined ? '' : pitch} ${minimumVolume === undefined ? '' : minimumVolume}`);93export const reload = () =>94 commandBuilder(`reload`);95export const replaceItem = (replaceItemType: ReplaceItemType, positionOrTarget: Position | Target | TargetSelector, slotType: SlotType | CustomSlotType, slotId: number, itemName: Block | Item, amount?: number, dataValue?: number) =>96 commandBuilder(`replaceitem ${replaceItemType} ${positionOrTarget} ${slotType} ${slotId} ${itemName} ${amount || ''} ${dataValue === undefined ? '' : dataValue}`);97export const say = (message: string) =>98 commandBuilder(`say ${message}`);99// scoreboardは後で実装する100export const setBlock = (position: Position, tileName: Block | string, tileData?: number, oldBlockHandling?: OldBlockHandling) =>101 commandBuilder(`setblock ${position} ${tileName} ${tileData === undefined ? '' : tileData} ${oldBlockHandling || ''}`);102export const setMaxPlayers = (maxPlayers: number) =>103 commandBuilder(`setmaxplayers ${maxPlayers}`);104export const setWorldSpawn = (spawnPoint: Position) =>105 commandBuilder(`setworldspawn ${spawnPoint}`);106export const spawnPoint = (player?: Target | TargetSelector, spawnPoint?: Position) =>107 commandBuilder(`spawnpoint ${player || ''} ${spawnPoint || ''}`);108export const spreadPlayers = (x: number | string, z: number | string, spreadDistance: number, maxRange: number, victim: Target | TargetSelector) =>109 commandBuilder(`spreadplayers ${x} ${z} ${spreadDistance} ${maxRange} ${victim}`);110export const stopSound = (player: Target | TargetSelector, sound?: string) =>111 commandBuilder(`stopsound ${player} ${sound || ''}`);112export const summon = (entityType: EntityType | string, spawnPos?: Position) =>113 commandBuilder(`summon ${entityType} ${spawnPos || ''}`);114export const tag = (targets: Target | TargetSelector, tagType: TagType, name?: string) =>115 commandBuilder(`tag ${targets} ${tagType} ${name || ''}`);116export const teleport = (destination: Target | TargetSelector | Position, yRot?: Rotation, xRot?: Rotation) =>117 commandBuilder(`teleport ${destination} ${yRot || ''} ${xRot || ''}`);118export const tell = (target: Target | TargetSelector, message: string) =>119 commandBuilder(`tell ${target} ${message}`);120export const tellRaw = (player: Target | TargetSelector, rawJsonMessage: {} | string) =>121 commandBuilder(`tellraw ${player} ${typeof rawJsonMessage === 'string' ? rawJsonMessage : JSON.stringify(rawJsonMessage)}`);122export const testFor = (victim: Target | TargetSelector) =>123 commandBuilder(`testfor ${victim}`);124export const testForBlock = (position: Position, tileName: Block | string, dataValue?: number) =>125 commandBuilder(`testforblock ${position} ${tileName} ${dataValue === undefined ? '' : dataValue}`);126export const testForBlocks = (begin: Position, end: Position, destination: Position, maskMode?: MaskMode) =>127 commandBuilder(`testforblocks ${begin} ${end} ${destination} ${maskMode || ''}`);128// tickingareaは後で実装する129export const time = (timeCommand: TimeCommand, amountOrTime: number | Time) =>130 commandBuilder(`time ${timeCommand} ${amountOrTime}`);131export const title = (player: Target | TargetSelector, titleCommand: TitleCommand, titleText: string) =>132 commandBuilder(`title ${player} ${titleCommand} ${titleText}`);133export const toggleDownFall = () =>134 commandBuilder(`toggledownfall`);135export const tp = (destination: Target | TargetSelector | Position, yRot?: Rotation, xRot?: Rotation) =>136 commandBuilder(`tp ${destination} ${yRot || ''} ${xRot || ''}`);137export const transferServer = (server: string, port: number) =>138 commandBuilder(`transferserver ${server} ${port}`);139export const w = (target: Target | TargetSelector, message: string) =>140 tell(target, message);141export const weather = (weatherType: WeatherType, duration?: number) =>142 commandBuilder(`weather ${weatherType} ${duration === undefined ? '' : duration}`);143export const wsServer = (serverUri: string) =>144 commandBuilder(`wsserver ${serverUri}`);145export const xp = (amount: number, player?: Target | TargetSelector) =>146 commandBuilder(`xp ${amount} ${player || ''}`);147// WebSocket限定関数148export const agentMove = (direction: Direction | string) =>149 commandBuilder(`agent move ${direction}`);150export const agentTurn = (turnDirection: TurnDirection) =>151 commandBuilder(`agent turn ${turnDirection}`);152export const agentAttack = (direction: Direction) =>153 commandBuilder(`agent attack ${direction}`);154export const agentDestroy = (direction: Direction) =>155 commandBuilder(`agent destroy ${direction}`);156export const agentDrop = (slotNum: number, quantity: number, direction: Direction) =>157 commandBuilder(`agent drop ${slotNum} ${quantity} ${direction}`);158export const agentDropAll = (direction: Direction) =>159 commandBuilder(`agent dropall ${direction}`);160export const agentInspect = (direction: Direction) =>161 commandBuilder(`agent inspect ${direction}`);162export const agentInspectData = (direction: Direction) =>163 commandBuilder(`agent inspectdata ${direction}`);164export const agentDetect = (direction: Direction) =>165 commandBuilder(`agent detect ${direction}`);166export const agentDetectRedStone = (direction: Direction) =>167 commandBuilder(`agent detectredstone ${direction}`);168export const agentTransfer = (srcSlotNum: number, quantity: number, dstSlotNum: number) =>169 commandBuilder(`agent drop ${srcSlotNum} ${quantity} ${dstSlotNum}`);170export const agentCreate = (uuid: string) =>171 commandBuilder('agent create', uuid);172export const agentTp = (destination?: Target | TargetSelector | Position, yRot?: DirectionNsew | number, xRot?: DirectionNsew | number) =>173 commandBuilder(`agent tp ${destination || ''} ${yRot || ''} ${xRot || ''}`);174export const agentCollect = (item: Block | Item) =>175 commandBuilder(`agent collect ${item}`);176export const agentTill = (direction: Direction) =>177 commandBuilder(`agent till ${direction}`);178export const agentPlace = (slotNum: number, direction: Direction) =>179 commandBuilder(`agent place ${slotNum} ${direction}`);180export const agentGetItemCount = (slotNum: number) =>181 commandBuilder(`agent getitemcount ${slotNum}`);182export const agentGetItemSpace = (slotNum: number) =>183 commandBuilder(`agent getitemspace ${slotNum}`);184export const agentGetItemDetail = (slotNum: number) =>185 commandBuilder(`agent getitemdetail ${slotNum}`);186export const agentGetPosition = () =>187 commandBuilder(`agent getposition}`);188export const agentSetItem = (slotNum: number, item: Item | Block | string, count: number, dataValue?: number) =>189 commandBuilder(`agent setitem ${slotNum} ${item} ${count} ${dataValue || ''}`);190export const closeWebSocket = () =>191 commandBuilder('closewebsocket');192export const enableEncryption = (key: string, iv: string) =>193 commandBuilder(`enableencryption "${key}" "${iv}"`);194export const listD = () =>195 commandBuilder('listd');196export const getEduClientInfo = () =>197 commandBuilder('geteduclientinfo');198export const queryTarget = (target: Target | TargetSelector, uuid: string) =>199 commandBuilder(`querytarget ${target}`, uuid);200// 独自関数201export const levelUp = (amount: number, player?: Target | TargetSelector) =>202 commandBuilder(`xp ${amount}L ${player || ''}`);203export const teleportVictim = (victim: Target | TargetSelector, destination: Target | TargetSelector | Position, yRot?: Rotation, xRot?: Rotation) =>204 commandBuilder(`teleport ${victim} ${destination} ${yRot || ''} ${xRot || ''}`);205export const clearTitle = (player: Target | TargetSelector) =>206 commandBuilder(`title ${player} clear`);207export const resetTitle = (player: Target | TargetSelector) =>208 commandBuilder(`title ${player} reset`);209export const setTitleTime = (player: Target | TargetSelector, fadeIn: number, stay: number, fadeOut: number) =>210 commandBuilder(`title ${player} times ${fadeIn} ${stay} ${fadeOut}`);211export const tpVictim = (victim: Target | TargetSelector, destination: Target | TargetSelector | Position, yRot?: Rotation, xRot?: Rotation) =>212 commandBuilder(`tp ${victim} ${destination} ${yRot || ''} ${xRot || ''}`);213export default {214 clear,215 clone,216 connect,217 deOp,218 difficulty,219 effect,220 enchant,221 fill,222 gameMode,223 gameRule,224 give,225 help,226 kill,...

Full Screen

Full Screen

CommandBuilder.test.ts

Source:CommandBuilder.test.ts Github

copy

Full Screen

1import 'mocha';2import { expect } from '../expect';3import CommandBuilder from '../../src/utils/CommandBuilder';4describe('CommandBuilder', () => {5 let commandBuilder: CommandBuilder;6 beforeEach(() => {7 commandBuilder = new CommandBuilder();8 });9 describe('push', () => {10 it('should push only when value is not undefined', () => {11 commandBuilder.push(undefined);12 expect((commandBuilder as any).parts).to.deep.equal([]);13 commandBuilder.push('test');14 expect((commandBuilder as any).parts).to.deep.equal([ 'test' ]);15 });16 });17 describe('pushPattern', () => {18 it('should push only when value is not undefined', () => {19 commandBuilder.pushPattern('pattern=%s', undefined);20 expect((commandBuilder as any).parts).to.deep.equal([]);21 commandBuilder.pushPattern('pattern=%s,%s', 'test');22 expect((commandBuilder as any).parts).to.deep.equal([ 'pattern=test,test' ]);23 });24 });25 describe('pushCollection', () => {26 it('should push only when values is not undefined', () => {27 commandBuilder.pushCollection(undefined);28 expect((commandBuilder as any).parts).to.deep.equal([]);29 commandBuilder.pushCollection([ 'test1', 'test2' ]);30 expect((commandBuilder as any).parts).to.deep.equal([ 'test1', 'test2' ]);31 });32 });33 describe('pushCollectionPattern', () => {34 it('should push only when values is not undefined', () => {35 commandBuilder.pushCollectionPattern('pattern=%s', undefined);36 expect((commandBuilder as any).parts).to.deep.equal([]);37 commandBuilder.pushCollectionPattern('pattern=%s,%s', [ 'test1', 'test2']);38 expect((commandBuilder as any).parts).to.deep.equal([39 'pattern=test1,test1',40 'pattern=test2,test2'41 ]);42 });43 });44 describe('build', () => {45 it('should prepare the final command based on each parts', () => {46 const command = commandBuilder47 .push('value1')48 .pushPattern('--arg=%s', 'value2')49 .pushCollection([ 'value3', 'value4' ])50 .pushCollectionPattern('--arg-n=%s', [ 'value5', 'value6' ])51 .build();52 expect(command).to.equal('value1 --arg=value2 value3 value4 --arg-n=value5 --arg-n=value6');53 });54 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const commandBuilder = require('storybook-root').commandBuilder;2const executeCommand = require('storybook-root').executeCommand;3const executeCommand = require('storybook-root').executeCommand;4const executeCommand = require('storybook-root').executeCommand;5const executeCommand = require('storybook-root').executeCommand;6const executeCommand = require('storybook-root').executeCommand;7const executeCommand = require('storybook-root').executeCommand;8const executeCommand = require('storybook-root').executeCommand;9const executeCommand = require('storybook-root').executeCommand;10const executeCommand = require('storybook-root').executeCommand;11const executeCommand = require('storybook-root').executeCommand;12const executeCommand = require('storybook-root').executeCommand;13const executeCommand = require('storybook-root').executeCommand;14const executeCommand = require('storybook-root').executeCommand;15const executeCommand = require('storybook-root').executeCommand;16const executeCommand = require('storybook-root').executeCommand;17const executeCommand = require('storybook-root').executeCommand;18const executeCommand = require('storybook-root').executeCommand;19const executeCommand = require('storybook-root').executeCommand;20const executeCommand = require('storybook-root').executeCommand;21const executeCommand = require('storybook-root').executeCommand;

Full Screen

Using AI Code Generation

copy

Full Screen

1import commandBuilder from 'storybook-root'2commandBuilder('test')3import commandBuilder from 'storybook-root'4commandBuilder('test')5import commandBuilder from 'storybook-root'6commandBuilder('test')7import commandBuilder from 'storybook-root'8commandBuilder('test')9import commandBuilder from 'storybook-root'10commandBuilder('test')11import commandBuilder from 'storybook-root'12commandBuilder('test')13import commandBuilder from 'storybook-root'14commandBuilder('test')15import commandBuilder from 'storybook-root'16commandBuilder('test')17import commandBuilder from 'storybook-root'18commandBuilder('test')19import commandBuilder from 'storybook-root'20commandBuilder('test')21import commandBuilder from 'storybook-root'22commandBuilder('test')23import commandBuilder from 'storybook-root'24commandBuilder('test')

Full Screen

Using AI Code Generation

copy

Full Screen

1import { commandBuilder } from 'storybook-root';2const command = commandBuilder('test');3command.execute();4import { commandBuilder } from './command';5export { commandBuilder };6import { Command } from 'commander';7export const commandBuilder = (name) => {8 const command = new Command(name);9 command.option('-t, --test', 'test command');10 command.action(() => {11 console.log('test command');12 });13 return command;14};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { commandBuilder } from 'storybook-root';2const command = commandBuilder();3command.add('ls');4command.add('-al');5command.add('/tmp');6command.exec();7import { commandBuilder } from 'storybook-root';8describe('Testing commandBuilder', () => {9 it('should return a string', () => {10 const command = commandBuilder();11 command.add('ls');12 command.add('-al');13 command.add('/tmp');14 const result = command.exec();15 expect(typeof result).to.equal('string');16 });17});18import { commandBuilder } from 'storybook-root';19describe('Testing commandBuilder', () => {20 it('should return a string', () => {21 const command = commandBuilder();22 command.add('ls');23 command.add('-al');24 command.add('/tmp');25 const result = command.exec();26 expect(typeof result).to.equal('string');27 });28});29import { commandBuilder } from 'storybook-root';30describe('Testing commandBuilder', () => {31 it('should return a string', () => {32 const command = commandBuilder();33 command.add('ls');34 command.add('-al');35 command.add('/tmp');36 const result = command.exec();37 expect(typeof result).to.equal('string');38 });39});40import { commandBuilder } from 'storybook-root';41describe('Testing commandBuilder', () => {42 it('should return a string', () => {43 const command = commandBuilder();44 command.add('ls');45 command.add('-al');46 command.add('/tmp');47 const result = command.exec();48 expect(typeof result).to.equal('string');49 });50});51import { commandBuilder } from 'storybook-root';52describe('Testing commandBuilder', () => {53 it('should return a string', () => {54 const command = commandBuilder();55 command.add('ls');56 command.add('-al');57 command.add('/tmp');58 const result = command.exec();59 expect(typeof result).to.equal('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { commandBuilder } = require('storybook-root');2const command = commandBuilder('node', 'test.js');3command.execute();4const { commandBuilder } = require('storybook-root');5const command = commandBuilder('node', 'test.js');6command.execute();7const { commandBuilder } = require('storybook-root');8const command = commandBuilder('node', 'test.js');9command.execute();10const { commandBuilder } = require('storybook-root');11const command = commandBuilder('node', 'test.js');12command.execute();13const { commandBuilder } = require('storybook-root');14const command = commandBuilder('node', 'test.js');15command.execute();16const { commandBuilder } = require('storybook-root');17const command = commandBuilder('node', 'test.js');18command.execute();19const { commandBuilder } = require('storybook-root');20const command = commandBuilder('node', 'test.js');21command.execute();22const { commandBuilder } = require('storybook-root');23const command = commandBuilder('node', 'test.js');24command.execute();25const { commandBuilder } = require('storybook-root');26const command = commandBuilder('node', 'test.js');27command.execute();28const { commandBuilder } = require('storybook-root');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { commandBuilder } = require('@storybook/react/dist/server/build-dev');2const commands = commandBuilder({ configDir: './config', outputDir: './storybook-static' });3console.log(commands);4const { exec } = require('child_process');5const command = commands[0];6exec(command, (err, stdout, stderr) => {7 if (err) {8 console.error(err);9 return;10 }11 console.log(stdout);12});

Full Screen

Using AI Code Generation

copy

Full Screen

1import commandBuilder from 'storybook-root-decorator'2const buildAndRunCommand = async (command, args) => {3 const commandToRun = commandBuilder(command, args)4 const result = await exec(commandToRun)5}6const runCommand = async command => {7 const result = await exec(command)8}9const getCommandOutput = async command => {10 const result = await exec(command)11}12const getCommandOutput = async command => {13 const result = await exec(command)14}15const getCommandOutput = async command => {16 const result = await exec(command)17}18const getCommandOutput = async command => {19 const result = await exec(command)20}21const getCommandOutput = async command => {22 const result = await exec(command)23}24const getCommandOutput = async command => {25 const result = await exec(command)26}27const getCommandOutput = async command => {28 const result = await exec(command)

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = require('storybook-root');2const command = root.commandBuilder('test');3root.execute(command);4root.execute(command, (err, stdout, stderr) => {5});6root.execute(command, (err, stdout, stderr) => {7}, {cwd: 'some/path'});8root.execute(command, {cwd: 'some/path'});9root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {10});11root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {12});13root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {14});15root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {16});17root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {18});19root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {20});21root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {22});23root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {24});25root.execute(command, {cwd: 'some/path'}, (err, stdout, stderr) => {26});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful