Best JavaScript code snippet using sinon
class.cmessages.js
Source:class.cmessages.js
1/*2** Zabbix3** Copyright (C) 2001-2015 Zabbix SIA4**5** This program is free software; you can redistribute it and/or modify6** it under the terms of the GNU General Public License as published by7** the Free Software Foundation; either version 2 of the License, or8** (at your option) any later version.9**10** This program is distributed in the hope that it will be useful,11** but WITHOUT ANY WARRANTY; without even the implied warranty of12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13** GNU General Public License for more details.14**15** You should have received a copy of the GNU General Public License16** along with this program; if not, write to the Free Software17** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.18**/19var ZBX_MESSAGES = [];20// use this function to initialize Messaging system21function initMessages(args) {22 var messagesListId = ZBX_MESSAGES.length;23 ZBX_MESSAGES[messagesListId] = new CMessageList(messagesListId, args);24 return messagesListId;25}26var CMessageList = Class.create(CDebug, {27 messageListId: 0, // reference id28 updateFrequency: 60, // seconds29 timeoutFrequency: 10, // seconds30 ready: false,31 PEupdater: null, // PeriodicalExecuter object update32 PEtimeout: null, // PeriodicalExecuter object update33 lastupdate: 0, // lastupdate timestamp34 msgcounter: 0, // how many messages have been added35 pipeLength: 15, // how many messages to show36 messageList: {}, // list of received messages37 messagePipe: [], // messageid pipe line38 messageLast: {}, // last message's sourceid by caption39 effectTimeout: 1000, // effect time out40 dom: {}, // dom object links41 sounds: { // sound playback settings42 'priority': 0, // max new message priority43 'sound': null, // sound to play44 'repeat': 1, // loop sound for 1,3,5,10 .. times45 'mute': 0, // mute alarms46 'timeout': 047 },48 initialize: function($super, messagesListId, args) {49 this.messageListId = messagesListId;50 $super('CMessageList[' + messagesListId + ']');51 this.dom = {};52 this.messageList = {};53 this.messageLast = {};54 this.updateSettings();55 this.createContainer();56 addListener(this.dom.closeAll, 'click', this.closeAllMessages.bindAsEventListener(this));57 addListener(this.dom.snooze, 'click', this.stopSound.bindAsEventListener(this));58 addListener(this.dom.mute, 'click', this.mute.bindAsEventListener(this));59 jQuery(this.dom.container).draggable({60 handle: this.dom.header,61 axis: 'y',62 containment: [0, 0, 0, 1600]63 });64 },65 start: function() {66 this.stop();67 if (is_null(this.PEupdater)) {68 this.ready = true;69 this.lastupdate = 0;70 this.PEupdater = new PeriodicalExecuter(this.getServerMessages.bind(this), this.updateFrequency);71 this.getServerMessages();72 }73 if (is_null(this.PEtimeout)) {74 this.PEtimeout = new PeriodicalExecuter(this.timeoutMessages.bind(this), this.timeoutFrequency);75 this.timeoutMessages();76 }77 },78 stop: function() {79 if (!is_null(this.PEupdater)) {80 this.PEupdater.stop();81 }82 if (!is_null(this.PEtimeout)) {83 this.PEtimeout.stop();84 }85 this.PEupdater = null;86 this.PEtimeout = null;87 },88 setSettings: function(settings) {89 this.debug('setSettings');90 this.sounds.repeat = settings['sounds.repeat'];91 this.sounds.mute = settings['sounds.mute'];92 if (this.sounds.mute == 1) {93 this.dom.mute.className = 'iconmute menu_icon shadow';94 }95 if (settings.enabled != 1) {96 this.stop();97 }98 else {99 this.start();100 }101 },102 updateSettings: function() {103 this.debug('updateSettings');104 var rpcRequest = {105 'method': 'message.settings',106 'params': {},107 'onSuccess': this.setSettings.bind(this),108 'onFailure': function() {109 zbx_throw('Messages Widget: settings request failed.');110 }111 };112 new RPC.Call(rpcRequest);113 },114 addMessage: function(newMessage) {115 this.debug('addMessage');116 newMessage = newMessage || {};117 while (isset(this.msgcounter, this.messageList)) {118 this.msgcounter++;119 }120 if (this.messagePipe.length > this.pipeLength) {121 var lastMessageId = this.messagePipe.shift();122 this.closeMessage(lastMessageId);123 }124 this.messagePipe.push(this.msgcounter);125 newMessage.messageid = this.msgcounter;126 this.messageList[this.msgcounter] = new CMessage(this, newMessage);127 this.messageLast[this.messageList[this.msgcounter].caption] = {128 'caption': this.messageList[this.msgcounter].caption,129 'sourceid': this.messageList[this.msgcounter].sourceid,130 'time': this.messageList[this.msgcounter].time,131 'messageid': this.messageList[this.msgcounter].messageid132 };133 jQuery(this.dom.container).fadeTo('fast', 0.9);134 return this.messageList[this.msgcounter];135 },136 mute: function(e) {137 this.debug('mute');138 e = e || window.event;139 var icon = Event.element(e);140 var newClass = switchElementsClass(icon, 'iconmute', 'iconsound');141 if (newClass == 'iconmute') {142 var action = 'message.mute';143 this.sounds.mute = 1;144 }145 else {146 var action = 'message.unmute';147 this.sounds.mute = 0;148 }149 var rpcRequest = {150 'method': action,151 'params': {},152 'onFailure': function() {153 zbx_throw('Messages Widget: mute request failed.');154 }155 };156 new RPC.Call(rpcRequest);157 this.stopSound(e);158 },159 playSound: function(messages) {160 this.debug('playSound');161 if (this.sounds.mute != 0) {162 return true;163 }164 this.stopSound();165 this.sounds.priority = 0;166 this.sounds.sound = null;167 for (var i = 0; i < messages.length; i++) {168 var message = messages[i];169 if (message.type != 1 && message.type != 3) {170 continue;171 }172 if (message.priority >= this.sounds.priority) {173 this.sounds.priority = message.priority;174 this.sounds.sound = message.sound;175 this.sounds.timeout = message.timeout;176 }177 }178 this.ready = true;179 if (!is_null(this.sounds.sound)) {180 if (this.sounds.repeat == 1) {181 AudioList.play(this.sounds.sound);182 }183 else if (this.sounds.repeat > 1) {184 AudioList.loop(this.sounds.sound, {'seconds': this.sounds.repeat});185 }186 else {187 AudioList.loop(this.sounds.sound, {'seconds': this.sounds.timeout});188 }189 }190 },191 stopSound: function() {192 this.debug('stopSound');193 if (!is_null(this.sounds.sound)) {194 AudioList.stop(this.sounds.sound);195 }196 },197 closeMessage: function(messageid, withEffect) {198 this.debug('closeMessage', messageid);199 if (!isset(messageid, this.messageList)) {200 return true;201 }202 AudioList.stop(this.messageList[messageid].sound);203 if (withEffect) {204 this.messageList[messageid].remove();205 }206 else {207 this.messageList[messageid].close();208 }209 try {210 delete(this.messageList[messageid]);211 }212 catch(e) {213 this.messageList[messageid] = null;214 }215 this.messagePipe = [];216 for (var messageid in this.messageList) {217 this.messagePipe.push(messageid);218 }219 if (this.messagePipe.length < 1) {220 this.messagePipe = [];221 this.messageList = {};222 setTimeout(Element.hide.bind(Element, this.dom.container), this.effectTimeout);223 }224 },225 closeAllMessages: function() {226 this.debug('closeAllMessages');227 var lastMessageId = this.messagePipe.pop();228 var rpcRequest = {229 'method': 'message.closeAll',230 'params': {231 'caption': this.messageList[lastMessageId].caption,232 'sourceid': this.messageList[lastMessageId].sourceid,233 'time': this.messageList[lastMessageId].time,234 'messageid': this.messageList[lastMessageId].messageid235 },236 'onFailure': function(resp) {237 zbx_throw('Messages Widget: message request failed.');238 }239 };240 new RPC.Call(rpcRequest);241 jQuery(this.dom.container).slideUp(this.effectTimeout);242 var count = 0;243 var effect = false;244 for (var messageid in this.messageList) {245 if (empty(this.messageList[messageid])) {246 continue;247 }248 if (!effect) {249 this.closeMessage(this, messageid, effect);250 }251 else {252 setTimeout(this.closeMessage.bind(this, messageid, effect), count * this.effectTimeout * 0.5);253 }254 count++;255 }256 this.stopSound();257 },258 timeoutMessages: function() {259 this.debug('timeoutMessages');260 var now = parseInt(new Date().getTime() / 1000);261 var timeout = 0;262 for (var messageid in this.messageList) {263 if (empty(this.messageList[messageid])) {264 continue;265 }266 var msg = this.messageList[messageid];267 if ((msg.time + parseInt(msg.timeout, 10)) < now) {268 setTimeout(this.closeMessage.bind(this, messageid, true), 500 * timeout);269 timeout++;270 }271 }272 },273 getServerMessages: function() {274 this.debug('getServerMessages');275 var now = parseInt(new Date().getTime() / 1000);276 if (!this.ready || ((this.lastupdate + this.updateFrequency) > now)) {277 return true;278 }279 this.ready = false;280 var rpcRequest = {281 'method': 'message.get',282 'params': {283 'messageListId': this.messageListId,284 'messageLast': this.messageLast285 },286 'onSuccess': this.serverRespond.bind(this),287 'onFailure': function() {288 zbx_throw('Messages Widget: message request failed.');289 }290 };291 new RPC.Call(rpcRequest);292 this.lastupdate = now;293 },294 serverRespond: function(messages) {295 this.debug('serverRespond');296 for (var i = 0; i < messages.length; i++) {297 this.addMessage(messages[i]);298 }299 this.playSound(messages);300 this.ready = true;301 },302 createContainer: function() {303 this.debug('createContainer');304 this.dom.container = $('zbx_messages');305 if (!empty(this.dom.container)) {306 return false;307 }308 var doc_body = document.getElementsByTagName('body')[0];309 if (empty(doc_body)) {310 return false;311 }312 this.dom.container = document.createElement('div');313 doc_body.appendChild(this.dom.container);314 // container315 this.dom.container.setAttribute('id', 'zbx_messages');316 this.dom.container.className = 'messagecontainer';317 $(this.dom.container).hide();318 // header319 this.dom.header = document.createElement('div');320 this.dom.container.appendChild(this.dom.header);321 this.dom.header.className = 'header';322 // text323 this.dom.caption = document.createElement('h3');324 this.dom.caption.className = 'headertext move';325 this.dom.caption.appendChild(document.createTextNode(locale['S_MESSAGES']));326 this.dom.header.appendChild(this.dom.caption);327 // controls328 this.dom.controls = document.createElement('div');329 this.dom.header.appendChild(this.dom.controls);330 this.dom.controls.className = 'controls';331 // buttons list332 this.dom.controlList = new CList().node;333 this.dom.controls.appendChild(this.dom.controlList);334 this.dom.controlList.style.cssFloat = 'right';335 // snooze336 this.dom.snooze = document.createElement('div');337 this.dom.snooze.setAttribute('title', locale['S_SNOOZE']);338 this.dom.snooze.className = 'iconsnooze menu_icon shadow';339 this.dom.controlList.addItem(this.dom.snooze, 'linear');340 // mute341 this.dom.mute = document.createElement('div');342 this.dom.mute.setAttribute('title', locale['S_MUTE'] + '/' + locale['S_UNMUTE']);343 this.dom.mute.className = 'iconsound menu_icon shadow';344 this.dom.controlList.addItem(this.dom.mute, 'linear');345 // close all346 this.dom.closeAll = document.createElement('div');347 this.dom.closeAll.setAttribute('title', locale['S_CLEAR']);348 this.dom.closeAll.className = 'iconclose menu_icon shadow';349 this.dom.controlList.addItem(this.dom.closeAll, 'linear');350 // message list351 this.dom.list = new CList().node;352 this.dom.container.appendChild(this.dom.list);353 }354});355var CMessage = Class.create(CDebug, {356 list: null, // link to message list containing this message357 messageid: null, // msg id358 caption: 'unknown', // msg caption (events, actions, infos.. e.t.c.)359 sourceid: null, // caption + sourceid = identifier for server360 type: 0, // 1 - sound, 2 - text, 3 - sound & text, 4 - notdefined361 priority: 0, // msg priority ASC362 sound: null, // msg sound363 color: 'ffffff', // msg color364 time: 0, // msg time arrival365 title: 'No title', // msg header366 body: ['No text'],// msg details367 timeout: 60, // msg timeout368 dom: {}, // msg dom links369 initialize: function($super, messageList, message) {370 this.messageid = message.messageid;371 $super('CMessage[' + this.messageid + ']');372 this.dom = {};373 this.list = messageList;374 for (var key in message) {375 if (empty(message[key]) || !isset(key, this)) {376 continue;377 }378 if (key == 'time') {379 this[key] = parseInt(message[key]);380 }381 else {382 this[key] = message[key];383 }384 }385 this.createMessage();386 },387 close: function() {388 this.debug('close');389 $(this.dom.listItem).remove();390 this.dom = {};391 },392 remove: function() {393 this.debug('remove');394 jQuery(this.dom.listItem).slideUp(this.list.effectTimeout);395 jQuery(this.dom.listItem).fadeOut(this.list.effectTimeout);396 setTimeout(this.close.bind(this), this.list.effectTimeout);397 },398 createMessage: function() {399 this.debug('createMessage');400 // message401 this.dom.message = document.createElement('div');402 this.dom.message.className = 'message';403 this.dom.message.style.backgroundColor = '#' + this.color;404 // li405 this.dom.listItem = new CListItem(this.dom.message, 'listItem').node;406 $(this.list.dom.list).insert({'top': this.dom.listItem});407 // message box408 this.dom.messageBox = document.createElement('div');409 this.dom.message.appendChild(this.dom.messageBox);410 this.dom.messageBox.className = 'messagebox';411 // title412 this.dom.title = document.createElement('span');413 this.dom.messageBox.appendChild(this.dom.title);414 $(this.dom.title).update(BBCode.Parse(this.title));415 this.dom.title.className = 'title';416 // body417 if (!is_array(this.body)) {418 this.body = [this.body];419 }420 for (var i = 0; i < this.body.length; i++) {421 if (!isset(i, this.body) || empty(this.body[i])) {422 continue;423 }424 this.dom.messageBox.appendChild(document.createElement('br'));425 this.dom.body = document.createElement('span');426 this.dom.messageBox.appendChild(this.dom.body);427 $(this.dom.body).update(BBCode.Parse(this.body[i]));428 this.dom.body.className = 'body';429 }430 },431 show: function() {},432 notify: function() {}433});434var CNode = Class.create({435 node: null, // main node (ul)436 initialize: function(nodeName) {437 this.node = document.createElement(nodeName);438 return this.node;439 },440 addItem: function(item) {441 if (is_object(item)) {442 this.node.appendChild(item);443 }444 else if (is_string(item)) {445 this.node.appendChild(documect.createTextNode(item));446 }447 else {448 return true;449 }450 },451 setClass: function(className) {452 className = className || '';453 this.node.className = className;454 }455});456var CList = Class.create(CNode, {457 items: [],458 initialize: function($super, className) {459 className = className || '';460 $super('ul');461 this.setClass(this.classNames);462 Object.extend(this.node, this);463 },464 addItem: function($super, item, className) {465 className = className || '';466 if (!is_object(item, CListItem)) {467 item = new CListItem(item, className).node;468 }469 $super(item);470 this.items.push(item);471 }472});473var CListItem = Class.create(CNode, {474 items: [],475 initialize: function($super, item, className) {476 className = className || '';477 item = item || null;478 $super('li');479 this.setClass(className);480 this.addItem(item);481 },482 addItem: function($super, item) {483 $super(item);484 this.items.push(item);485 }...
HUD.js
Source:HUD.js
1 /*2 * HexGL3 * @author Thibaut 'BKcore' Despoulain <http://bkcore.com>4 * @license This work is licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported License. 5 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/.6 */7var bkcore = bkcore || {};8bkcore.hexgl = bkcore.hexgl || {};9bkcore.hexgl.HUD = function(opts)10{11 var self = this;12 this.visible = true;13 this.messageOnly = false;14 this.width = opts.width;15 this.height = opts.height;16 this.canvas = document.createElement('canvas');17 this.canvas.width = this.width;18 this.canvas.height = this.height;19 this.ctx = this.canvas.getContext('2d');20 this.ctx.textAlign = "center";21 this.bg = opts.bg;//"textures/hud/hud-bg.png";22 this.fgspeed = opts.speed;//"textures/hud/hud-fg-speed.png";23 this.fgshield = opts.shield;//"textures/hud/hud-fg-shield.png";24 this.speedFontRatio = 24;25 this.speedBarRatio = 2.91;26 this.shieldFontRatio = 64;27 this.shieldBarYRatio = 34;28 this.shieldBarWRatio = 18.3;29 this.shieldBarHRatio = 14.3;30 this.timeMarginRatio = 18;31 this.timeFontRatio = 19.2;32 this.font = opts.font || "Arial";33 this.time = "";34 this.message = "";35 this.previousMessage = "";36 this.messageTiming = 0;37 this.messagePos = 0.0;38 this.messagePosTarget = 0.0;39 this.messagePosTargetRatio = 12;40 this.messageA = 1.0;41 this.messageAS = 1.0;42 this.messageDuration = 2*60;43 this.messageDurationD = 2*60;44 this.messageDurationS = 30;45 this.messageYRatio = 34;46 this.messageFontRatio = 10;47 this.messageFontRatioStart = 6;48 this.messageFontRatioEnd = 10;49 this.messageFontLerp = 0.4;50 this.messageLerp = 0.4;51 this.messageFontAlpha = 0.8;52 this.lapMarginRatio = 14;53 this.lap = "";54 this.lapSeparator = "/";55 this.timeSeparators = ["","'", "''",""];56 this.step = 0;57 this.maxStep = 2;58};59bkcore.hexgl.HUD.prototype.resize = function(w, h)60{61 this.width = w;62 this.height = h;63 this.canvas.width = w;64 this.canvas.height = h;65}66bkcore.hexgl.HUD.prototype.display = function(msg, duration)67{68 this.messageTiming = 0;69 if(this.message != "")70 {71 this.messageA = this.messageFontAlpha;72 this.messagePos = 0.0;73 this.messagePosTarget = this.width/this.messagePosTargetRatio;74 this.previousMessage = this.message;75 }76 this.messageFontRatio = this.messageFontRatioStart;77 this.messageAS = 0.0;78 this.message = msg;79 this.messageDuration = duration == undefined ? this.messageDurationD : duration*60;80}81bkcore.hexgl.HUD.prototype.updateLap = function(current, total)82{83 this.lap = current + this.lapSeparator + total;84}85bkcore.hexgl.HUD.prototype.resetLap = function()86{87 this.lap = "";88}89bkcore.hexgl.HUD.prototype.updateTime = function(time)90{91 this.time = this.timeSeparators[0] + time.m + this.timeSeparators[1] + time.s + this.timeSeparators[2] + time.ms + this.timeSeparators[3];92}93bkcore.hexgl.HUD.prototype.resetTime = function()94{95 this.time = "";96}97bkcore.hexgl.HUD.prototype.update = function(speed, speedRatio, shield, shieldRatio)98{99 var SCREEN_WIDTH = this.width;100 var SCREEN_HEIGHT = this.height;101 var SCREEN_HW = SCREEN_WIDTH / 2;102 var SCREEN_HH = SCREEN_HEIGHT / 2;103 if(!this.visible)104 {105 this.ctx.clearRect(0 , 0 , SCREEN_WIDTH , SCREEN_HEIGHT);106 return;107 }108 var w = this.bg.width;109 var h = this.bg.height;110 var r = h/w;111 var nw = SCREEN_WIDTH;112 var nh = nw*r;113 var oh = SCREEN_HEIGHT - nh;114 var o = 0;115 //speedbar116 var ba = nh;117 var bl = SCREEN_WIDTH/this.speedBarRatio;118 var bw = bl * speedRatio;119 //shieldbar120 var sw = SCREEN_WIDTH/this.shieldBarWRatio;121 var sho = SCREEN_WIDTH/this.shieldBarHRatio;122 var sh = sho*shieldRatio;123 var sy = (SCREEN_WIDTH/this.shieldBarYRatio)+sho-sh;124 125 if(this.step == 0)126 {127 this.ctx.clearRect(0 , oh , SCREEN_WIDTH , nh);128 if(!this.messageOnly)129 {130 this.ctx.drawImage(this.bg, o, oh, nw, nh);131 this.ctx.save();132 this.ctx.beginPath();133 this.ctx.moveTo(bw+ba+SCREEN_HW, oh);134 this.ctx.lineTo(-(bw+ba)+SCREEN_HW, oh);135 this.ctx.lineTo(-bw+SCREEN_HW, SCREEN_HEIGHT);136 this.ctx.lineTo(bw+SCREEN_HW, SCREEN_HEIGHT);137 this.ctx.lineTo(bw+ba+SCREEN_HW, oh);138 this.ctx.clip();139 this.ctx.drawImage(this.fgspeed, o, oh, nw, nh);140 this.ctx.restore();141 this.ctx.save();142 this.ctx.beginPath();143 this.ctx.moveTo(-sw+SCREEN_HW, oh+sy);144 this.ctx.lineTo(sw+SCREEN_HW, oh+sy);145 this.ctx.lineTo(sw+SCREEN_HW, oh+sh+sy);146 this.ctx.lineTo(-sw+SCREEN_HW, oh+sh+sy);147 this.ctx.lineTo(-sw+SCREEN_HW, oh+sh);148 this.ctx.clip();149 this.ctx.drawImage(this.fgshield, o, oh, nw, nh);150 this.ctx.restore();151 // SPEED152 this.ctx.font = (SCREEN_WIDTH/this.speedFontRatio)+"px "+this.font;153 this.ctx.fillStyle = "rgba(255, 255, 255, 0.8)";154 this.ctx.fillText(speed, SCREEN_HW, SCREEN_HEIGHT - nh*0.57);155 // SHIELD156 this.ctx.font = (SCREEN_WIDTH/this.shieldFontRatio)+"px "+this.font;157 this.ctx.fillStyle = "rgba(255, 255, 255, 0.4)";158 this.ctx.fillText(shield, SCREEN_HW, SCREEN_HEIGHT - nh*0.44);159 }160 }161 else if(this.step == 1)162 {163 this.ctx.clearRect(0 , 0 , SCREEN_WIDTH , oh);164 // TIME165 if(this.time != "")166 {167 this.ctx.font = (SCREEN_WIDTH/this.timeFontRatio)+"px "+this.font;168 this.ctx.fillStyle = "rgba(255, 255, 255, 0.8)";169 this.ctx.fillText(this.time, SCREEN_HW, SCREEN_WIDTH/this.timeMarginRatio);170 }171 // LAPS172 if(this.lap != "")173 {174 this.ctx.font = (SCREEN_WIDTH/this.timeFontRatio)+"px "+this.font;175 this.ctx.fillStyle = "rgba(255, 255, 255, 0.8)";176 this.ctx.fillText(this.lap, SCREEN_WIDTH-SCREEN_WIDTH/this.lapMarginRatio, SCREEN_WIDTH/this.timeMarginRatio);177 }178 // MESSAGE179 var my = SCREEN_HH-SCREEN_WIDTH/this.messageYRatio;180 if(this.messageTiming > this.messageDuration+2000)181 {182 this.previousMessage = "";183 this.message = "";184 this.messageA = 0.0;185 }186 else if(this.messageTiming > this.messageDuration && this.message != "")187 {188 this.previousMessage = this.message;189 this.message = "";190 this.messagePos = 0.0;191 this.messagePosTarget = SCREEN_WIDTH/this.messagePosTargetRatio;192 this.messageA = this.messageFontAlpha;193 }194 if(this.previousMessage != "")195 {196 if(this.messageA < 0.001)197 this.messageA = 0.0;198 else199 this.messageA += (0.0 - this.messageA) * this.messageLerp;200 this.messagePos += (this.messagePosTarget - this.messagePos) * this.messageLerp;201 this.ctx.font = (SCREEN_WIDTH/this.messageFontRatioEnd)+"px "+this.font;202 this.ctx.fillStyle = "rgba(255, 255, 255, "+this.messageA+")";203 this.ctx.fillText(this.previousMessage, SCREEN_HW, my+this.messagePos);204 }205 if(this.message != "")206 {207 if(this.messageTiming < this.messageDurationS)208 {209 this.messageAS += (this.messageFontAlpha - this.messageAS) * this.messageFontLerp;210 this.messageFontRatio += (this.messageFontRatioEnd - this.messageFontRatio) * this.messageFontLerp;211 }212 else213 {214 this.messageAS = this.messageFontAlpha;215 this.messageFontRatio = this.messageFontRatioEnd;216 }217 this.ctx.font = (SCREEN_WIDTH/this.messageFontRatio)+"px "+this.font;218 this.ctx.fillStyle = "rgba(255, 255, 255, "+this.messageAS+")";219 this.ctx.fillText(this.message, SCREEN_HW, my);220 }221 }222 223 this.messageTiming++;224 this.step++;225 if(this.step == this.maxStep) this.step = 0;...
errors.js
Source:errors.js
1exports.ArgumentError = function (message) {2 this.message = message;3};4exports.ArgumentError.prototype = Object.create(Error.prototype);5exports.AuthError = function (message) {6 this.message = message;7};8exports.AuthError.prototype = Object.create(Error.prototype);9exports.ArchiveError = function (message) {10 this.message = message;11};12exports.ArchiveError.prototype = Object.create(Error.prototype);13exports.SipError = function (message) {14 this.message = message;15};16exports.SipError.prototype = Object.create(Error.prototype);17exports.SignalError = function (message) {18 this.message = message;19};20exports.SignalError.prototype = Object.create(Error.prototype);21exports.ForceDisconnectError = function (message) {22 this.message = message;23};24exports.ForceDisconnectError.prototype = Object.create(Error.prototype);25exports.CallbackError = function (message) {26 this.message = message;27};28exports.CallbackError.prototype = Object.create(Error.prototype);29exports.RequestError = function (message) {30 this.message = message;31};...
Using AI Code Generation
1var spy = sinon.spy();2spy("Hello World");3assert(spy.calledWith("Hello World"));4var stub = sinon.stub();5stub("Hello World");6assert(stub.calledWith("Hello World"));7var mock = sinon.mock();8mock.expects("foo").once().withArgs("Hello World");9mock.verify();10var server = sinon.fakeServer.create();11server.respondWith(12 [200, { "Content-Type": "text/plain" }, "Hello World"]13);14server.respond();15assert(server.requests[0].method === "GET");16assert(server.requests[0].responseText === "Hello World");17var xhr = sinon.useFakeXMLHttpRequest();18var requests = [];19xhr.onCreate = function (req) { requests.push(req); };20var clock = sinon.useFakeTimers();21clock.tick(1000);22assert(clock.now === 1000);23var server = sinon.fakeServer.create();24var xhr = sinon.useFakeXMLHttpRequest();25var requests = [];26xhr.onCreate = function (req) { requests.push(req); };27var clock = sinon.useFakeTimers();28var server = sinon.fakeServer.create();29var xhr = sinon.useFakeXMLHttpRequest();30var requests = [];31xhr.onCreate = function (req) { requests.push(req); };32var clock = sinon.useFakeTimers();33var server = sinon.fakeServer.create();34var xhr = sinon.useFakeXMLHttpRequest();35var requests = [];36xhr.onCreate = function (req) { requests.push(req); };37var sandbox = sinon.sandbox.create();38sandbox.stub(object, "method");39sandbox.spy(object, "method");40sandbox.mock(object).expects("method").once();41sandbox.useFakeTimers();42sandbox.useFakeXMLHttpRequest();43sandbox.server.autoRespond = true;44sandbox.server.respondWith("Hello World");45sandbox.server.respond();
Using AI Code Generation
1describe('test', function() {2 var spy;3 beforeEach(function() {4 spy = sinon.spy();5 spy("Hello", "World");6 });7 it('test', function() {8 });9});10TypeError: spy.withArgs(...).calledWith is not a function
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var myObject = {4 myMethod: function () {5 console.log("myMethod called");6 this.message();7 },8 message: function () {9 console.log("message called");10 }11};12var spy = sinon.spy(myObject, "message");13myObject.myMethod();14assert(spy.called);15assert(spy.calledOnce);16assert(spy.calledWith());17assert(spy.calledOn(myObject));18assert(spy.calledWithExactly());19assert(spy.calledWithNew());20assert(spy.alwaysCalledWithNew());21assert(spy.neverCalledWithNew());22assert(spy.threw());23assert(spy.alwaysThrew());24assert(spy.returned());25assert(spy.alwaysReturned());26assert(spy.calledWithMatch());27assert(spy.alwaysCalledWithMatch());28assert(spy.calledWithExactlyMatch());29assert(spy.alwaysCalledWithExactlyMatch());30assert(spy.calledWithNew());31assert(spy.alwaysCalledWithNew());32assert(spy.neverCalledWithNew());33assert(spy.calledBefore());34assert(spy.calledAfter());35assert(spy.calledImmediatelyBefore());36assert(spy.calledImmediatelyAfter());37assert(spy.callCount);38assert(spy.firstCall);39assert(spy.secondCall);40assert(spy.thirdCall);41assert(spy.lastCall);42assert(spy.thisValues);43assert(spy.args);44assert(spy.exceptions);45assert(spy.returnValues);46var sinon = require('sinon');47var assert = require('assert');48var myObject = {49 myMethod: function () {50 console.log("myMethod called");51 this.message();52 },53 message: function () {54 console.log("message called");55 }56};57var spy = sinon.spy(myObject, "message");58myObject.myMethod();59assert(spy.called);60assert(spy.calledOnce);61assert(spy.calledWith());62assert(spy.calledOn(myObject));63assert(spy.calledWithExactly());64assert(spy.calledWithNew());65assert(spy.alwaysCalledWithNew());66assert(spy.neverCalledWithNew());67assert(spy.threw());68assert(spy.alwaysThrew());69assert(spy.returned());70assert(spy.alwaysReturned());71assert(spy.calledWithMatch());72assert(spy.alwaysCalledWithMatch());73assert(spy.calledWithExactlyMatch());74assert(spy.alwaysCalledWith
Using AI Code Generation
1describe('sinon test', function() {2 it('should be called once', function() {3 var obj = {4 message: function() {5 return 'hello world';6 }7 };8 var spy = sinon.spy(obj, 'message');9 obj.message();10 expect(spy.calledOnce).to.be.true;11 });12});13describe('sinon test', function() {14 it('should be called once', function() {15 var obj = {16 message: function() {17 return 'hello world';18 }19 };20 var spy = sinon.spy(obj, 'message');21 obj.message();22 expect(spy.calledOnce).to.be.true;23 });24});25describe('sinon test', function() {26 it('should be called once', function() {27 var obj = {28 message: function() {29 return 'hello world';30 }31 };32 var spy = sinon.spy(obj, 'message');33 obj.message();34 expect(spy.calledOnce).to.be.true;35 });36});37describe('sinon test', function() {38 it('should be called once', function() {39 var obj = {40 message: function() {41 return 'hello world';42 }43 };44 var spy = sinon.spy(obj, 'message');45 obj.message();46 expect(spy.calledOnce).to.be.true;47 });48});49describe('sinon test', function() {50 it('should be called once', function() {51 var obj = {52 message: function() {53 return 'hello world';54 }55 };56 var spy = sinon.spy(obj, 'message');57 obj.message();58 expect(spy.calledOnce).to.be.true;59 });60});61describe('sinon test', function() {62 it('should be called once', function() {63 var obj = {64 message: function() {65 return 'hello world';66 }67 };68 var spy = sinon.spy(obj, 'message');69 obj.message();70 expect(spy.calledOnce).to.be.true;71 });
Using AI Code Generation
1var server = sinon.fakeServer.create();2server.respondWith("GET", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);3server.respond();4server.respondWith("POST", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);5server.respond();6server.respondWith("PUT", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);7server.respond();8server.respondWith("DELETE", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);9server.respond();10server.respondWith("GET", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);11server.respond();12server.respondWith("POST", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);13server.respond();14server.respondWith("PUT", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);15server.respond();16server.respondWith("DELETE", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);17server.respond();18server.respondWith("GET", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);19server.respond();20server.respondWith("POST", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);21server.respond();22server.respondWith("PUT", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);23server.respond();24server.respondWith("DELETE", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar" }']);25server.respond();26server.respondWith("GET", "/test", [ 200, { "Content-Type": "application/json" }, '{ "foo": "bar
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var obj = { message: 'Hello World' };4sinon.spy(obj, 'message');5assert(obj.message.calledOnce);6assert(obj.message.calledWith('Hello World'));7var sinon = require('sinon');8var assert = require('assert');9var obj = { message: 'Hello World' };10sinon.spy(obj, 'message');11assert(obj.message.calledOnce);12assert(obj.message.calledWith('Hello World'));13var sinon = require('sinon');14var assert = require('assert');15var obj = { message: 'Hello World' };16sinon.spy(obj, 'message');17assert(obj.message.calledOnce);18assert(obj.message.calledWith('Hello World'));19var sinon = require('sinon');20var assert = require('assert');21var obj = { message: 'Hello World' };22sinon.spy(obj, 'message');23assert(obj.message.calledOnce);24assert(obj.message.calledWith('Hello World'));25var sinon = require('sinon');26var assert = require('assert');27var obj = { message: 'Hello World' };28sinon.spy(obj, 'message');29assert(obj.message.calledOnce);30assert(obj.message.calledWith('Hello World'));31var sinon = require('sinon');32var assert = require('assert');33var obj = { message: 'Hello World' };34sinon.spy(obj, 'message');35assert(obj.message.calledOnce);36assert(obj.message.calledWith('Hello World'));37var sinon = require('sinon');38var assert = require('assert');39var obj = { message: 'Hello World' };40sinon.spy(obj, 'message');41assert(obj.message.calledOnce);42assert(obj.message.calledWith('Hello World'));43var sinon = require('sinon');44var assert = require('assert');45var obj = { message: 'Hello World' };46sinon.spy(obj, 'message');47assert(obj.message.calledOnce);48assert(obj.message.called
Using AI Code Generation
1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var assert = chai.assert;5var should = chai.should();6var message = require('./message.js');7var messageObj = new message();8describe('message', function() {9 it('message should be called', function() {10 sinon.spy(messageObj, 'message');11 messageObj.message();12 expect(messageObj.message.calledOnce).to.be.true;13 });14});15var message = function() {16 this.message = function() {17 console.log('Hello World');18 }19}20module.exports = message;
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!!