Best JavaScript code snippet using sinon
text.js
Source:text.js
1/**2 * @license3 * Visual Blocks Editor4 *5 * Copyright 2012 Google Inc.6 * https://blockly.googlecode.com/7 *8 * Licensed under the Apache License, Version 2.0 (the "License");9 * you may not use this file except in compliance with the License.10 * You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing, software15 * distributed under the License is distributed on an "AS IS" BASIS,16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.17 * See the License for the specific language governing permissions and18 * limitations under the License.19 */20/**21 * @fileoverview Text blocks for Blockly.22 * @author fraser@google.com (Neil Fraser)23 */24'use strict';25goog.provide('Blockly.Blocks.text');26goog.require('Blockly.Blocks');27Blockly.Blocks['text'] = {28 /**29 * Block for text value.30 * @this Blockly.Block31 */32 init: function() {33 this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);34 this.setColour(160);35 this.appendDummyInput()36 .appendField(this.newQuote_(true))37 .appendField(new Blockly.FieldTextInput(''), 'TEXT')38 .appendField(this.newQuote_(false));39 this.setOutput(true, 'String');40 this.setTooltip(Blockly.Msg.TEXT_TEXT_TOOLTIP);41 },42 /**43 * Create an image of an open or closed quote.44 * @param {boolean} open True if open quote, false if closed.45 * @return {!Blockly.FieldImage} The field image of the quote.46 * @private47 */48 newQuote_: function(open) {49 if (open == Blockly.RTL) {50 var file = 'quote1.png';51 } else {52 var file = 'quote0.png';53 }54 return new Blockly.FieldImage(Blockly.pathToBlockly + 'media/' + file,55 12, 12, '"');56 }57};58Blockly.Blocks['text_join'] = {59 /**60 * Block for creating a string made up of any number of elements of any type.61 * @this Blockly.Block62 */63 init: function() {64 this.setHelpUrl(Blockly.Msg.TEXT_JOIN_HELPURL);65 this.setColour(160);66 this.appendValueInput('ADD0')67 .appendField(Blockly.Msg.TEXT_JOIN_TITLE_CREATEWITH);68 this.appendValueInput('ADD1');69 this.setOutput(true, 'String');70 this.setMutator(new Blockly.Mutator(['text_create_join_item']));71 this.setTooltip(Blockly.Msg.TEXT_JOIN_TOOLTIP);72 this.itemCount_ = 2;73 },74 /**75 * Create XML to represent number of text inputs.76 * @return {Element} XML storage element.77 * @this Blockly.Block78 */79 mutationToDom: function() {80 var container = document.createElement('mutation');81 container.setAttribute('items', this.itemCount_);82 return container;83 },84 /**85 * Parse XML to restore the text inputs.86 * @param {!Element} xmlElement XML storage element.87 * @this Blockly.Block88 */89 domToMutation: function(xmlElement) {90 for (var x = 0; x < this.itemCount_; x++) {91 this.removeInput('ADD' + x);92 }93 this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);94 for (var x = 0; x < this.itemCount_; x++) {95 var input = this.appendValueInput('ADD' + x);96 if (x == 0) {97 input.appendField(Blockly.Msg.TEXT_JOIN_TITLE_CREATEWITH);98 }99 }100 if (this.itemCount_ == 0) {101 this.appendDummyInput('EMPTY')102 .appendField(new Blockly.FieldImage(Blockly.pathToBlockly +103 'media/quote0.png', 12, 12, '"'))104 .appendField(new Blockly.FieldImage(Blockly.pathToBlockly +105 'media/quote1.png', 12, 12, '"'));106 }107 },108 /**109 * Populate the mutator's dialog with this block's components.110 * @param {!Blockly.Workspace} workspace Mutator's workspace.111 * @return {!Blockly.Block} Root block in mutator.112 * @this Blockly.Block113 */114 decompose: function(workspace) {115 var containerBlock = Blockly.Block.obtain(workspace,116 'text_create_join_container');117 containerBlock.initSvg();118 var connection = containerBlock.getInput('STACK').connection;119 for (var x = 0; x < this.itemCount_; x++) {120 var itemBlock = Blockly.Block.obtain(workspace, 'text_create_join_item');121 itemBlock.initSvg();122 connection.connect(itemBlock.previousConnection);123 connection = itemBlock.nextConnection;124 }125 return containerBlock;126 },127 /**128 * Reconfigure this block based on the mutator dialog's components.129 * @param {!Blockly.Block} containerBlock Root block in mutator.130 * @this Blockly.Block131 */132 compose: function(containerBlock) {133 // Disconnect all input blocks and remove all inputs.134 if (this.itemCount_ == 0) {135 this.removeInput('EMPTY');136 } else {137 for (var x = this.itemCount_ - 1; x >= 0; x--) {138 this.removeInput('ADD' + x);139 }140 }141 this.itemCount_ = 0;142 // Rebuild the block's inputs.143 var itemBlock = containerBlock.getInputTargetBlock('STACK');144 while (itemBlock) {145 var input = this.appendValueInput('ADD' + this.itemCount_);146 if (this.itemCount_ == 0) {147 input.appendField(Blockly.Msg.TEXT_JOIN_TITLE_CREATEWITH);148 }149 // Reconnect any child blocks.150 if (itemBlock.valueConnection_) {151 input.connection.connect(itemBlock.valueConnection_);152 }153 this.itemCount_++;154 itemBlock = itemBlock.nextConnection &&155 itemBlock.nextConnection.targetBlock();156 }157 if (this.itemCount_ == 0) {158 this.appendDummyInput('EMPTY')159 .appendField(new Blockly.FieldImage(Blockly.pathToBlockly +160 'media/quote0.png', 12, 12, '"'))161 .appendField(new Blockly.FieldImage(Blockly.pathToBlockly +162 'media/quote1.png', 12, 12, '"'));163 }164 },165 /**166 * Store pointers to any connected child blocks.167 * @param {!Blockly.Block} containerBlock Root block in mutator.168 * @this Blockly.Block169 */170 saveConnections: function(containerBlock) {171 var itemBlock = containerBlock.getInputTargetBlock('STACK');172 var x = 0;173 while (itemBlock) {174 var input = this.getInput('ADD' + x);175 itemBlock.valueConnection_ = input && input.connection.targetConnection;176 x++;177 itemBlock = itemBlock.nextConnection &&178 itemBlock.nextConnection.targetBlock();179 }180 }181};182Blockly.Blocks['text_create_join_container'] = {183 /**184 * Mutator block for container.185 * @this Blockly.Block186 */187 init: function() {188 this.setColour(160);189 this.appendDummyInput()190 .appendField(Blockly.Msg.TEXT_CREATE_JOIN_TITLE_JOIN);191 this.appendStatementInput('STACK');192 this.setTooltip(Blockly.Msg.TEXT_CREATE_JOIN_TOOLTIP);193 this.contextMenu = false;194 }195};196Blockly.Blocks['text_create_join_item'] = {197 /**198 * Mutator block for add items.199 * @this Blockly.Block200 */201 init: function() {202 this.setColour(160);203 this.appendDummyInput()204 .appendField(Blockly.Msg.TEXT_CREATE_JOIN_ITEM_TITLE_ITEM);205 this.setPreviousStatement(true);206 this.setNextStatement(true);207 this.setTooltip(Blockly.Msg.TEXT_CREATE_JOIN_ITEM_TOOLTIP);208 this.contextMenu = false;209 }210};211Blockly.Blocks['text_append'] = {212 /**213 * Block for appending to a variable in place.214 * @this Blockly.Block215 */216 init: function() {217 this.setHelpUrl(Blockly.Msg.TEXT_APPEND_HELPURL);218 this.setColour(160);219 this.appendValueInput('TEXT')220 .appendField(Blockly.Msg.TEXT_APPEND_TO)221 .appendField(new Blockly.FieldVariable(222 Blockly.Msg.TEXT_APPEND_VARIABLE), 'VAR')223 .appendField(Blockly.Msg.TEXT_APPEND_APPENDTEXT);224 this.setPreviousStatement(true);225 this.setNextStatement(true);226 // Assign 'this' to a variable for use in the tooltip closure below.227 var thisBlock = this;228 this.setTooltip(function() {229 return Blockly.Msg.TEXT_APPEND_TOOLTIP.replace('%1',230 thisBlock.getFieldValue('VAR'));231 });232 },233 /**234 * Return all variables referenced by this block.235 * @return {!Array.<string>} List of variable names.236 * @this Blockly.Block237 */238 getVars: function() {239 return [this.getFieldValue('VAR')];240 },241 /**242 * Notification that a variable is renaming.243 * If the name matches one of this block's variables, rename it.244 * @param {string} oldName Previous name of variable.245 * @param {string} newName Renamed variable.246 * @this Blockly.Block247 */248 renameVar: function(oldName, newName) {249 if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {250 this.setFieldValue(newName, 'VAR');251 }252 }253};254Blockly.Blocks['text_length'] = {255 /**256 * Block for string length.257 * @this Blockly.Block258 */259 init: function() {260 this.setHelpUrl(Blockly.Msg.TEXT_LENGTH_HELPURL);261 this.setColour(160);262 this.interpolateMsg(Blockly.Msg.TEXT_LENGTH_TITLE,263 ['VALUE', ['String', 'Array'], Blockly.ALIGN_RIGHT],264 Blockly.ALIGN_RIGHT);265 this.setOutput(true, 'Number');266 this.setTooltip(Blockly.Msg.TEXT_LENGTH_TOOLTIP);267 }268};269Blockly.Blocks['text_isEmpty'] = {270 /**271 * Block for is the string null?272 * @this Blockly.Block273 */274 init: function() {275 this.setHelpUrl(Blockly.Msg.TEXT_ISEMPTY_HELPURL);276 this.setColour(160);277 this.interpolateMsg(Blockly.Msg.TEXT_ISEMPTY_TITLE,278 ['VALUE', ['String', 'Array'], Blockly.ALIGN_RIGHT],279 Blockly.ALIGN_RIGHT);280 this.setOutput(true, 'Boolean');281 this.setTooltip(Blockly.Msg.TEXT_ISEMPTY_TOOLTIP);282 }283};284Blockly.Blocks['text_indexOf'] = {285 /**286 * Block for finding a substring in the text.287 * @this Blockly.Block288 */289 init: function() {290 var OPERATORS =291 [[Blockly.Msg.TEXT_INDEXOF_OPERATOR_FIRST, 'FIRST'],292 [Blockly.Msg.TEXT_INDEXOF_OPERATOR_LAST, 'LAST']];293 this.setHelpUrl(Blockly.Msg.TEXT_INDEXOF_HELPURL);294 this.setColour(160);295 this.setOutput(true, 'Number');296 this.appendValueInput('VALUE')297 .setCheck('String')298 .appendField(Blockly.Msg.TEXT_INDEXOF_INPUT_INTEXT);299 this.appendValueInput('FIND')300 .setCheck('String')301 .appendField(new Blockly.FieldDropdown(OPERATORS), 'END');302 if (Blockly.Msg.TEXT_INDEXOF_TAIL) {303 this.appendDummyInput().appendField(Blockly.Msg.TEXT_INDEXOF_TAIL);304 }305 this.setInputsInline(true);306 this.setTooltip(Blockly.Msg.TEXT_INDEXOF_TOOLTIP);307 }308};309Blockly.Blocks['text_charAt'] = {310 /**311 * Block for getting a character from the string.312 * @this Blockly.Block313 */314 init: function() {315 this.WHERE_OPTIONS =316 [[Blockly.Msg.TEXT_CHARAT_FROM_START, 'FROM_START'],317 [Blockly.Msg.TEXT_CHARAT_FROM_END, 'FROM_END'],318 [Blockly.Msg.TEXT_CHARAT_FIRST, 'FIRST'],319 [Blockly.Msg.TEXT_CHARAT_LAST, 'LAST'],320 [Blockly.Msg.TEXT_CHARAT_RANDOM, 'RANDOM']];321 this.setHelpUrl(Blockly.Msg.TEXT_CHARAT_HELPURL);322 this.setColour(160);323 this.setOutput(true, 'String');324 this.appendValueInput('VALUE')325 .setCheck('String')326 .appendField(Blockly.Msg.TEXT_CHARAT_INPUT_INTEXT);327 this.appendDummyInput('AT');328 this.setInputsInline(true);329 this.updateAt_(true);330 this.setTooltip(Blockly.Msg.TEXT_CHARAT_TOOLTIP);331 },332 /**333 * Create XML to represent whether there is an 'AT' input.334 * @return {Element} XML storage element.335 * @this Blockly.Block336 */337 mutationToDom: function() {338 var container = document.createElement('mutation');339 var isAt = this.getInput('AT').type == Blockly.INPUT_VALUE;340 container.setAttribute('at', isAt);341 return container;342 },343 /**344 * Parse XML to restore the 'AT' input.345 * @param {!Element} xmlElement XML storage element.346 * @this Blockly.Block347 */348 domToMutation: function(xmlElement) {349 // Note: Until January 2013 this block did not have mutations,350 // so 'at' defaults to true.351 var isAt = (xmlElement.getAttribute('at') != 'false');352 this.updateAt_(isAt);353 },354 /**355 * Create or delete an input for the numeric index.356 * @param {boolean} isAt True if the input should exist.357 * @private358 * @this Blockly.Block359 */360 updateAt_: function(isAt) {361 // Destroy old 'AT' and 'ORDINAL' inputs.362 this.removeInput('AT');363 this.removeInput('ORDINAL', true);364 // Create either a value 'AT' input or a dummy input.365 if (isAt) {366 this.appendValueInput('AT').setCheck('Number');367 if (Blockly.Msg.ORDINAL_NUMBER_SUFFIX) {368 this.appendDummyInput('ORDINAL')369 .appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX);370 }371 } else {372 this.appendDummyInput('AT');373 }374 if (Blockly.Msg.TEXT_CHARAT_TAIL) {375 this.removeInput('TAIL', true);376 this.appendDummyInput('TAIL')377 .appendField(Blockly.Msg.TEXT_CHARAT_TAIL);378 }379 var menu = new Blockly.FieldDropdown(this.WHERE_OPTIONS, function(value) {380 var newAt = (value == 'FROM_START') || (value == 'FROM_END');381 // The 'isAt' variable is available due to this function being a closure.382 if (newAt != isAt) {383 var block = this.sourceBlock_;384 block.updateAt_(newAt);385 // This menu has been destroyed and replaced. Update the replacement.386 block.setFieldValue(value, 'WHERE');387 return null;388 }389 return undefined;390 });391 this.getInput('AT').appendField(menu, 'WHERE');392 }393};394Blockly.Blocks['text_getSubstring'] = {395 /**396 * Block for getting substring.397 * @this Blockly.Block398 */399 init: function() {400 this.WHERE_OPTIONS_1 =401 [[Blockly.Msg.TEXT_GET_SUBSTRING_START_FROM_START, 'FROM_START'],402 [Blockly.Msg.TEXT_GET_SUBSTRING_START_FROM_END, 'FROM_END'],403 [Blockly.Msg.TEXT_GET_SUBSTRING_START_FIRST, 'FIRST']];404 this.WHERE_OPTIONS_2 =405 [[Blockly.Msg.TEXT_GET_SUBSTRING_END_FROM_START, 'FROM_START'],406 [Blockly.Msg.TEXT_GET_SUBSTRING_END_FROM_END, 'FROM_END'],407 [Blockly.Msg.TEXT_GET_SUBSTRING_END_LAST, 'LAST']];408 this.setHelpUrl(Blockly.Msg.TEXT_GET_SUBSTRING_HELPURL);409 this.setColour(160);410 this.appendValueInput('STRING')411 .setCheck('String')412 .appendField(Blockly.Msg.TEXT_GET_SUBSTRING_INPUT_IN_TEXT);413 this.appendDummyInput('AT1');414 this.appendDummyInput('AT2');415 if (Blockly.Msg.TEXT_GET_SUBSTRING_TAIL) {416 this.appendDummyInput('TAIL')417 .appendField(Blockly.Msg.TEXT_GET_SUBSTRING_TAIL);418 }419 this.setInputsInline(true);420 this.setOutput(true, 'String');421 this.updateAt_(1, true);422 this.updateAt_(2, true);423 this.setTooltip(Blockly.Msg.TEXT_GET_SUBSTRING_TOOLTIP);424 },425 /**426 * Create XML to represent whether there are 'AT' inputs.427 * @return {Element} XML storage element.428 * @this Blockly.Block429 */430 mutationToDom: function() {431 var container = document.createElement('mutation');432 var isAt1 = this.getInput('AT1').type == Blockly.INPUT_VALUE;433 container.setAttribute('at1', isAt1);434 var isAt2 = this.getInput('AT2').type == Blockly.INPUT_VALUE;435 container.setAttribute('at2', isAt2);436 return container;437 },438 /**439 * Parse XML to restore the 'AT' inputs.440 * @param {!Element} xmlElement XML storage element.441 * @this Blockly.Block442 */443 domToMutation: function(xmlElement) {444 var isAt1 = (xmlElement.getAttribute('at1') == 'true');445 var isAt2 = (xmlElement.getAttribute('at2') == 'true');446 this.updateAt_(1, isAt1);447 this.updateAt_(2, isAt2);448 },449 /**450 * Create or delete an input for a numeric index.451 * This block has two such inputs, independant of each other.452 * @param {number} n Specify first or second input (1 or 2).453 * @param {boolean} isAt True if the input should exist.454 * @private455 * @this Blockly.Block456 */457 updateAt_: function(n, isAt) {458 // Create or delete an input for the numeric index.459 // Destroy old 'AT' and 'ORDINAL' inputs.460 this.removeInput('AT' + n);461 this.removeInput('ORDINAL' + n, true);462 // Create either a value 'AT' input or a dummy input.463 if (isAt) {464 this.appendValueInput('AT' + n).setCheck('Number');465 if (Blockly.Msg.ORDINAL_NUMBER_SUFFIX) {466 this.appendDummyInput('ORDINAL' + n)467 .appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX);468 }469 } else {470 this.appendDummyInput('AT' + n);471 }472 // Move tail, if present, to end of block.473 if (n == 2 && Blockly.Msg.TEXT_GET_SUBSTRING_TAIL) {474 this.removeInput('TAIL', true);475 this.appendDummyInput('TAIL')476 .appendField(Blockly.Msg.TEXT_GET_SUBSTRING_TAIL);477 }478 var menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n],479 function(value) {480 var newAt = (value == 'FROM_START') || (value == 'FROM_END');481 // The 'isAt' variable is available due to this function being a closure.482 if (newAt != isAt) {483 var block = this.sourceBlock_;484 block.updateAt_(n, newAt);485 // This menu has been destroyed and replaced. Update the replacement.486 block.setFieldValue(value, 'WHERE' + n);487 return null;488 }489 return undefined;490 });491 this.getInput('AT' + n)492 .appendField(menu, 'WHERE' + n);493 if (n == 1) {494 this.moveInputBefore('AT1', 'AT2');495 }496 }497};498Blockly.Blocks['text_changeCase'] = {499 /**500 * Block for changing capitalization.501 * @this Blockly.Block502 */503 init: function() {504 var OPERATORS =505 [[Blockly.Msg.TEXT_CHANGECASE_OPERATOR_UPPERCASE, 'UPPERCASE'],506 [Blockly.Msg.TEXT_CHANGECASE_OPERATOR_LOWERCASE, 'LOWERCASE'],507 [Blockly.Msg.TEXT_CHANGECASE_OPERATOR_TITLECASE, 'TITLECASE']];508 this.setHelpUrl(Blockly.Msg.TEXT_CHANGECASE_HELPURL);509 this.setColour(160);510 this.appendValueInput('TEXT')511 .setCheck('String')512 .appendField(new Blockly.FieldDropdown(OPERATORS), 'CASE');513 this.setOutput(true, 'String');514 this.setTooltip(Blockly.Msg.TEXT_CHANGECASE_TOOLTIP);515 }516};517Blockly.Blocks['text_trim'] = {518 /**519 * Block for trimming spaces.520 * @this Blockly.Block521 */522 init: function() {523 var OPERATORS =524 [[Blockly.Msg.TEXT_TRIM_OPERATOR_BOTH, 'BOTH'],525 [Blockly.Msg.TEXT_TRIM_OPERATOR_LEFT, 'LEFT'],526 [Blockly.Msg.TEXT_TRIM_OPERATOR_RIGHT, 'RIGHT']];527 this.setHelpUrl(Blockly.Msg.TEXT_TRIM_HELPURL);528 this.setColour(160);529 this.appendValueInput('TEXT')530 .setCheck('String')531 .appendField(new Blockly.FieldDropdown(OPERATORS), 'MODE');532 this.setOutput(true, 'String');533 this.setTooltip(Blockly.Msg.TEXT_TRIM_TOOLTIP);534 }535};536Blockly.Blocks['text_print'] = {537 /**538 * Block for print statement.539 * @this Blockly.Block540 */541 init: function() {542 this.setHelpUrl(Blockly.Msg.TEXT_PRINT_HELPURL);543 this.setColour(160);544 this.interpolateMsg(Blockly.Msg.TEXT_PRINT_TITLE,545 ['TEXT', null, Blockly.ALIGN_RIGHT],546 Blockly.ALIGN_RIGHT);547 this.setPreviousStatement(true);548 this.setNextStatement(true);549 this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);550 }551};552Blockly.Blocks['text_prompt'] = {553 /**554 * Block for prompt function (internal message).555 * @this Blockly.Block556 */557 init: function() {558 var TYPES =559 [[Blockly.Msg.TEXT_PROMPT_TYPE_TEXT, 'TEXT'],560 [Blockly.Msg.TEXT_PROMPT_TYPE_NUMBER, 'NUMBER']];561 // Assign 'this' to a variable for use in the closure below.562 var thisBlock = this;563 this.setHelpUrl(Blockly.Msg.TEXT_PROMPT_HELPURL);564 this.setColour(160);565 var dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) {566 if (newOp == 'NUMBER') {567 thisBlock.changeOutput('Number');568 } else {569 thisBlock.changeOutput('String');570 }571 });572 this.appendDummyInput()573 .appendField(dropdown, 'TYPE')574 .appendField(this.newQuote_(true))575 .appendField(new Blockly.FieldTextInput(''), 'TEXT')576 .appendField(this.newQuote_(false));577 this.setOutput(true, 'String');578 // Assign 'this' to a variable for use in the tooltip closure below.579 var thisBlock = this;580 this.setTooltip(function() {581 return (thisBlock.getFieldValue('TYPE') == 'TEXT') ?582 Blockly.Msg.TEXT_PROMPT_TOOLTIP_TEXT :583 Blockly.Msg.TEXT_PROMPT_TOOLTIP_NUMBER;584 });585 },586 newQuote_: Blockly.Blocks['text'].newQuote_587};588Blockly.Blocks['text_prompt_ext'] = {589 /**590 * Block for prompt function (external message).591 * @this Blockly.Block592 */593 init: function() {594 var TYPES =595 [[Blockly.Msg.TEXT_PROMPT_TYPE_TEXT, 'TEXT'],596 [Blockly.Msg.TEXT_PROMPT_TYPE_NUMBER, 'NUMBER']];597 // Assign 'this' to a variable for use in the closure below.598 var thisBlock = this;599 this.setHelpUrl(Blockly.Msg.TEXT_PROMPT_HELPURL);600 this.setColour(160);601 var dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) {602 if (newOp == 'NUMBER') {603 thisBlock.changeOutput('Number');604 } else {605 thisBlock.changeOutput('String');606 }607 });608 this.appendValueInput('TEXT')609 .appendField(dropdown, 'TYPE');610 this.setOutput(true, 'String');611 // Assign 'this' to a variable for use in the tooltip closure below.612 var thisBlock = this;613 this.setTooltip(function() {614 return (thisBlock.getFieldValue('TYPE') == 'TEXT') ?615 Blockly.Msg.TEXT_PROMPT_TOOLTIP_TEXT :616 Blockly.Msg.TEXT_PROMPT_TOOLTIP_NUMBER;617 });618 }...
admintext.js
Source:admintext.js
1var text=function(msg){2 if(msg.text=="id")3 {4 return adminbot.sendMessage(msg.from.id,msg.from.id);5 }6 adminmodel.findOne({chatid:msg.from.id,status:"1"}, function (err, admin) {7 // console.log(admin);8 if(admin){9 if(msg.text=='Ù
دÛرÛت کاربر'){10 userhandlerm.start(msg,admin);11 }12 if(msg.text=='Ù
دÛرÛت کاÙاÙ'){13 channelhandlerm.start(msg,admin);14 }15 if(msg.text=='Ù¾ÛاÙ
ÙØ§Û ÙبÙÛ Ú©Ø§Ø±Ø¨Ø±Ø§Ù'){16 messagehandlerm.start(msg,admin,"raededmessage");17 }18 if(msg.text=='Ù¾ÛاÙ
ÙØ§Û Ø¬Ø¯Ûد کاربراÙ'){19 messagehandlerm.start(msg,admin,"sentmessage");20 }21 else if(msg.text=='درخÙاست ÙØ§Û Ø¨Ø§Ø²'){22 adminutilm.settlemented(admin);23 }24 if(msg.text=='اÙزÙد٠ادÙ
ÛÙ'){25 adminformsm.admin(msg);26 }27 if(msg.text=='Øذ٠ادÙ
ÛÙ'){28 adminformsm.adminlist(msg,admin);29 }30 if(msg.text=='ارسا٠پÛاÙ
Ø¨Ø±Ø§Û Ú©Ø§Ø¨Ø±Ø§Ù'){31 adminformsm.messageforusers(msg,admin);32 }33 if(msg.text=='جستجÙÛ Ú©Ø§ÙاÙ'){34 adminformsm.searchchannel(msg,admin);35 }36 if(msg.text=='اÙصراÙ'){37 new admincommandsm.start(msg)38 }39 if(msg.text=='ارسا٠پÛاÙ
گرÙÙÛ'){40 adminformsm.sendmessageforcategories(msg,admin);41 }42 // else if(msg.text=='Ù¾ÛاÙ
ÙØ§Û Ú©Ø§Ø±Ø¨Ø±Ø§Ù'){43 44 // }45 // else if(msg.text=='درخÙاست ÙØ§Û Øذ٠کاربراÙ'){46 47 // }48 // else if(msg.text=='کاربرا٠Ù
سدÙد شدÙ'){49 50 // }51 // else if(msg.text=='درخÙاست ÙØ§Û Ø¨Ø§Ø²'){52 53 // }54 // else if(msg.text=='بست٠درخÙاست ÙØ§Û Ø¨Ø§Ø²'){55 56 // }57 // else if(msg.text=='اÙزÙد٠ادÙ
ÛÙ'){58 59 // }60 // else if(msg.text=='Øذ٠ادÙ
ÛÙ'){61 62 // }63 // else if(msg.text==' '){64 65 // }66 }67 else{68 return adminbot.sendMessage(msg.from.id,adminvarsm.messages.accessdenied).then(re => {})69 }70 });71}...
Using AI Code Generation
1var msg = sinon.spy();2msg.text("Hello World");3var msg = sinon.spy();4msg.text("Hello World");5var msg = sinon.spy();6msg.text("Hello World");7var msg = sinon.spy();8msg.text("Hello World");9var msg = sinon.spy();10msg.text("Hello World");11var msg = sinon.spy();12msg.text("Hello World");13var msg = sinon.spy();14msg.text("Hello World");15var msg = sinon.spy();16msg.text("Hello World");
Using AI Code Generation
1var assert = require('assert');2var sinon = require('sinon');3var greet = require('./greet');4var greet2 = require('./greet2');5var greet3 = require('./greet3');6describe('Greet', function(){7 it('should greet the person by name', function(){8 };9 };10 });11});12describe('Greet2', function(){13 it('should greet the person by name', function(){14 };15 };16 });17});18describe('Greet3', function(){19 it('should greet the person by name', function(){20 };21 };22 });23});
Using AI Code Generation
1var msg = sinon.fake();2msg.text = sinon.fake();3msg.text.withArgs("hello").returns("hello");4msg.text.withArgs("world").returns("world");5msg.send = sinon.fake();6msg.send.withArgs("hello").returns("hello");7msg.send.withArgs("world").returns("world");8msg.reply = sinon.fake();9msg.reply.withArgs("hello").returns("hello");10msg.reply.withArgs("world").returns("world");11msg.match = sinon.fake();12msg.match.withArgs("hello").returns("hello");13msg.match.withArgs("world").returns("world");14msg.random = sinon.fake();15msg.random.withArgs(["hello", "world"]).returns("hello");16msg.random.withArgs(["hello", "world"]).returns("world");17msg.finish = sinon.fake();18msg.envelope = sinon.fake();19msg.envelope.withArgs("user").returns("user");20msg.envelope.withArgs("room").returns("room");21msg.message.user = sinon.fake();22msg.message.user.withArgs("name").returns("name");23msg.message.user.withArgs("id").returns("id");24msg.message.room = sinon.fake();25msg.message.room.withArgs("name").returns("name");26msg.message.room.withArgs("id").returns("id");27msg.message.text = sinon.fake();28msg.message.text.withArgs("text").returns("text");29msg.message.user.name = sinon.fake();30msg.message.user.name.withArgs("name").returns("name");31msg.message.user.id = sinon.fake();32msg.message.user.id.withArgs("id").returns("id");33msg.message.room.name = sinon.fake();34msg.message.room.name.withArgs("name").returns("name");35msg.message.room.id = sinon.fake();
Using AI Code Generation
1console.log("test");2console.log("test2");3var sinon = require('sinon');4var expect = require('chai').expect;5var msg = require('./test');6describe('test', function() {7 it('should output "test" to the console', function() {8 var log = sinon.stub(console, 'log');9 msg.test();10 expect(log.calledWith('test')).to.be.true;11 log.restore();12 });13 it('should output "test2" to the console', function() {14 var log = sinon.stub(console, 'log');15 msg.test2();16 expect(log.calledWith('test2')).to.be.true;17 log.restore();18 });19});20var sinon = require('sinon');21var expect = require('chai').expect;22var msg = require('./test');23describe('test', function() {24 it('should output "test" to the console', function() {25 var log = sinon.stub(console, 'log');26 msg.test();27 expect(log.calledWith('test')).to.be.true;28 log.restore();29 });30 it('should output "test2" to the console', function() {31 var log = sinon.stub(console, 'log');32 msg.test2();33 expect(log.calledWith('test2')).to.be.true;34 log.restore();35 });36});37var sinon = require('sinon');38var expect = require('chai').expect;39var msg = require('./test');40describe('test', function() {41 it('should output "test" to the console', function() {42 var log = sinon.stub(console, 'log');43 msg.test();44 expect(log.calledWith('test')).to.be.true;45 log.restore();46 });47 it('should output "test2" to the console', function() {48 var log = sinon.stub(console, 'log');49 msg.test2();50 expect(log.calledWith('test2')).to.be.true;51 log.restore();52 });53});54var sinon = require('sinon');55var expect = require('chai').expect;56var msg = require('./test');57describe('test', function() {58 it('should output "test" to the console', function() {59 var log = sinon.stub(console, 'log
Using AI Code Generation
1var sinon = require('sinon');2var msg = require('../src/msg.js');3var assert = require('assert');4describe('msg', function() {5 it('should return the value of the text method of the object passed to it', function() {6 var obj = {7 text: sinon.stub().returns('Hello World!')8 };9 assert.equal(msg(obj), 'Hello World!');10 });11});12module.exports = function(obj) {13 return obj.text();14};15Now, we have a test that checks that the msg() function returns the value of the text() method of an object passed to it. The test passes and we have a good starting point for a test suite. You can run the test suite by running the following command:
Using AI Code Generation
1var expect = require('chai').expect;2var sinon = require('sinon');3var msg = require('../msg.js');4describe('msg', function() {5 it('should return the correct text', function() {6 var text = sinon.stub(msg, 'text');7 text.returns('Hello World');8 expect(msg.text()).to.equal('Hello World');9 text.restore();10 });11});
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!!