How to use isStatic method in Playwright Internal

Best JavaScript code snippet using playwright-internal

test_parser.js

Source:test_parser.js Github

copy

Full Screen

1/// <reference path="../../qunit/qunit-2.4.0.js" />2/// <reference path="../../../Client/pocketCode/scripts/core.js" />3/// <reference path="../../../Client/pocketCode/scripts/components/publishSubscribe.js" />4/// <reference path="../../../Client/pocketCode/scripts/components/device.js" />5/// <reference path="../../../Client/pocketCode/scripts/components/parser.js" />6/// <reference path="../../../Client/pocketCode/scripts/components/soundManager.js" />7/// <reference path="../../../Client/pocketCode/scripts/model/bricksCore.js" />8/// <reference path="../../../Client/pocketCode/scripts/model/bricksControl.js" />9/// <reference path="../../../Client/pocketCode/scripts/model/bricksLook.js" />10/// <reference path="../../../Client/pocketCode/scripts/model/bricksMotion.js" />11/// <reference path="../../../Client/pocketCode/scripts/model/bricksSound.js" />12/// <reference path="../../../Client/pocketCode/scripts/model/bricksData.js" />13/// <reference path="../../../Client/pocketCode/scripts/model/userVariableHost.js" />14/// <reference path="../../../Client/pocketCode/scripts/components/gameEngine.js" />15/// <reference path="../../../Client/pocketCode/scripts/components/sprite.js" />16/// <reference path="../../../Client/pocketCode/scripts/components/formula.js" />17/// <reference path="../../../Client/pocketCode/scripts/components/soundManager.js" />18/// <reference path="../../../Client/pocketCode/scripts/components/device.js" />19/// <reference path="../_resources/testDataProjects.js" />20'use strict';21QUnit.module("components/parser.js");22QUnit.test("SpriteFactory", function (assert) {23 var allBricksProject = project1; //using tests_testData.js24 //^^ includes all types of bricks 25 var broadcastMgr = new PocketCode.BroadcastManager([{ id: "s23" }]);26 var device = new PocketCode.MediaDevice();27 var gameEngine = new PocketCode.GameEngine(allBricksProject.id);28 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);29 //var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });30 var sf = new PocketCode.SpriteFactory(device, gameEngine, 25);31 assert.ok(sf instanceof PocketCode.SpriteFactory, "instance check");32 assert.equal(sf._device, device, "device set correctly");33 assert.equal(sf._gameEngine, gameEngine, "gameEngine set correctly");34 //create35 assert.throws(function () { sf.create("scene", broadcastMgr, {}); }, Error, "ERROR: create: invalid argument: scene");36 assert.throws(function () { sf.create(scene, "broadcastMgr", {}); }, Error, "ERROR: create: invalid argument: broadcast manager");37 assert.throws(function () { sf.create(scene, broadcastMgr, []); }, Error, "ERROR: create: invalid argument: array");38 assert.throws(function () { sf.create(scene, broadcastMgr, ""); }, Error, "ERROR: create: invalid argument: no object");39 sf.dispose();40 assert.equal(sf.onProgressChange, undefined, "dispose: properties removed");41 assert.equal(sf._disposed, true, "disposed: true");42 //recreate after dispose43 sf = new PocketCode.SpriteFactory(device, gameEngine, 18);44 var sprite2 = sf.create(scene, broadcastMgr, spriteTest2);45 assert.ok(sprite2 instanceof PocketCode.Model.Sprite, "Sprite successfully created");46 //events47 assert.ok(sf.onUnsupportedBricksFound instanceof SmartJs.Event.Event && sf.onSpriteLoaded instanceof SmartJs.Event.Event, "event check");48 //allBricksProject.sprites = []; //delete all sprites.. keep background49 var spritesLoaded = 0,50 bricksLoaded = 0,51 onSpriteLoadedHandler = function (e) {52 spritesLoaded++;53 bricksLoaded += e.bricksLoaded;54 },55 spriteLoadedListener = new SmartJs.Event.EventListener(onSpriteLoadedHandler, this),56 unsupportedBricks = 0,57 unsupportedBricksFoundHandler = function (e) {58 unsupportedBricks += e.unsupportedBricks.length;59 },60 unsupportedBricksFoundListener = new SmartJs.Event.EventListener(unsupportedBricksFoundHandler, this);61 sf.onUnsupportedBricksFound.addEventListener(unsupportedBricksFoundListener);62 sf.onSpriteLoaded.addEventListener(spriteLoadedListener);63 var bg = sf.create(scene, broadcastMgr, spriteTest, true);64 assert.ok(bg instanceof PocketCode.Model.BackgroundSprite, "background sprite created");65 assert.equal(spritesLoaded, 1, "spritesLoaded event called including event args");66 assert.equal(unsupportedBricks, 0, "no unsupported bricks found");67 sprite2 = sf.create(scene, broadcastMgr, spriteTest_unsupported);68 assert.equal(unsupportedBricks, 1, "unsuppoted event fired including args");69 //createClone70 bricksLoaded = 0;71 unsupportedBricks = 0;72 assert.throws(function () { sf.createClone("scene", broadcastMgr, {}); }, Error, "ERROR: create: invalid argument: scene");73 assert.throws(function () { sf.createClone(scene, "broadcastMgr", {}); }, Error, "ERROR: create: invalid argument: broadcast manager");74 assert.throws(function () { sf.createClone(scene, broadcastMgr, []); }, Error, "ERROR: create: invalid argument: array");75 assert.throws(function () { sf.createClone(scene, broadcastMgr, ""); }, Error, "ERROR: create: invalid argument: no object");76 var clone = sprite2.clone(device, broadcastMgr);77 assert.ok(clone instanceof PocketCode.Model.SpriteClone, "clone created");78 assert.ok(bricksLoaded == 0 && unsupportedBricks == 0, "no events dispatched");79 clone.dispose();80 assert.ok(!sprite2._disposed, "clone created without references"); //detaild tests for setting clone parameters can be found in the sprite tests81});82QUnit.test("BrickFactory", function (assert) {83 var allBricksProject = project1; //using _resources/testDataProjects.js84 //^^ includes all types of bricks (once!!! take care if this is still correct)85 var broadcastMgr = new PocketCode.BroadcastManager(allBricksProject.broadcasts);86 var device = new PocketCode.MediaDevice();87 var gameEngine = new PocketCode.GameEngine(allBricksProject.id);88 gameEngine._variables = allBricksProject.variables;89 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);90 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });91 var minLoopCycleTime = 14;92 var bf = new PocketCode.BrickFactory(device, scene, broadcastMgr, minLoopCycleTime); //TODO: check loadedCount93 assert.ok(bf instanceof PocketCode.BrickFactory, "instance created");94 assert.ok(bf._device === device && bf._scene === scene && bf._broadcastMgr === broadcastMgr && bf._minLoopCycleTime === 14, "properties set correctly");95 var unsupportedBricks = [];96 var unsupportedCalled = 0;97 var unsupportedHandler = function (e) {98 unsupportedCalled++;99 unsupportedBricks = e.unsupportedBricks;100 };101 assert.ok(bf.onUnsupportedBrickFound instanceof SmartJs.Event.Event, "event check");102 bf.onUnsupportedBrickFound.addEventListener(new SmartJs.Event.EventListener(unsupportedHandler, this));103 var controlBricks = [];104 var soundBricks = [];105 var motionBricks = [];106 var lookBricks = [];107 var dataBricks = [];108 var otherBricks = [];109 //background:110 sprite._variables = allBricksProject.background.variables;111 var count = 0;112 var bricks = allBricksProject.background.scripts;113 for (var i = 0, l = bricks.length; i < l; i++) {114 controlBricks.push(bf.create(sprite, bricks[i]));115 count++;116 }117 //all other sprites118 //we add all bricks to the same sprite as this makes no difference in this bricks factory test119 var currentSprite;120 for (var i = 0, l = allBricksProject.sprites.length; i < l; i++) {121 currentSprite = allBricksProject.sprites[i];122 var bricks = otherBricks;123 switch (i) {124 case 0:125 bricks = soundBricks;126 break;127 case 1:128 bricks = motionBricks;129 break;130 case 2:131 bricks = lookBricks;132 break;133 case 3:134 bricks = dataBricks;135 break;136 }137 for (var j = 0, k = currentSprite.scripts.length; j < k; j++) {138 bricks.push(bf.create(sprite, currentSprite.scripts[j]));139 count++;140 }141 }142 assert.equal(bf._parsed, allBricksProject.header.bricksCount, "all bricks created");143 assert.equal(unsupportedCalled, 0, "unsupported bricks not found, handler not called");144 assert.equal(unsupportedBricks.length, 0, "no unsupported found");145 //TEST INCLUDING UNSUPPORTED146 var allBricksProject = project1; //using tests_testData.js147 //^^ includes all types of bricks 148 //adding unsupported brick149 //{"broadcastMsgId":"s50","type":"BroadcastAndWaitUnknown"} //client detect150 //{"broadcastMsgId":"s50","type":"Unsupported"} //server detect151 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);152 sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });153 allBricksProject.background.scripts.push({ "broadcastMsgId": "s50", "type": "BroadcastAndWaitUnknown" });154 allBricksProject.background.scripts.push({ "broadcastMsgId": "s51", "type": "Unsupported" });155 allBricksProject.header.bricksCount += 2;156 var broadcastMgr = new PocketCode.BroadcastManager(allBricksProject.broadcasts);157 var device = new PocketCode.MediaDevice();158 var gameEngine = new PocketCode.GameEngine(allBricksProject.id);159 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);160 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });161 var bf = new PocketCode.BrickFactory(device, scene, broadcastMgr, 26);//allBricksProject.header.bricksCount, 26);162 assert.ok(bf instanceof PocketCode.BrickFactory, "instance created");163 assert.ok(bf._device === device && bf._broadcastMgr === broadcastMgr && bf._minLoopCycleTime === 26, "properties set correctly");164 var unsupportedBricks = [];165 var unsupportedCalled = 0;166 var unsupportedHandler = function (e) {167 unsupportedCalled++;168 unsupportedBricks.push(e.unsupportedBricks);169 };170 //events171 bf.onUnsupportedBrickFound.addEventListener(new SmartJs.Event.EventListener(unsupportedHandler, this));172 var controlBricks = [];173 var soundBricks = [];174 var motionBricks = [];175 var lookBricks = [];176 var dataBricks = [];177 var otherBricks = [];178 //background:179 var count = 0;180 var bricks = allBricksProject.background.scripts;181 for (var i = 0, l = bricks.length; i < l; i++) {182 controlBricks.push(bf.create(sprite, bricks[i]));183 count++;184 }185 //all other sprites186 //we add all bricks to the same sprite as this makes no difference in this bricks factory test187 var currentSprite;188 for (var i = 0, l = allBricksProject.sprites.length; i < l; i++) {189 currentSprite = allBricksProject.sprites[i];190 var bricks = otherBricks;191 switch (i) {192 case 0:193 bricks = soundBricks;194 break;195 case 1:196 bricks = motionBricks;197 break;198 case 2:199 bricks = lookBricks;200 break;201 case 3:202 bricks = dataBricks;203 break;204 }205 for (var j = 0, k = currentSprite.scripts.length; j < k; j++) {206 bricks.push(bf.create(sprite, currentSprite.scripts[j]));207 count++;208 }209 }210 assert.equal(bf.bricksParsed, allBricksProject.header.bricksCount, "unsupported: all bricks created");211 assert.equal(unsupportedCalled, 2, "unsupported: unsupported bricks found, handler called once");212 assert.equal(unsupportedBricks.length, 2, "unsupported: 2 found");213 bf.dispose();214 assert.ok(bf._disposed, "disposed");215 assert.ok(device && gameEngine && scene && broadcastMgr, "dispose without disposing other (shared) objects");216});217QUnit.test("FormulaParser: operators", function (assert) {218 var testParser = new PocketCode._FormulaParser(); //recreate the static class to avoid side effects in test framework219 assert.throws(function () { testParser.getUiString(plus); }, Error, "ERROR: accessing uiString without providing variable names");220 assert.throws(function () { testParser.getUiString(plus, ""); }, Error, "ERROR: accessing uiString without providing variable names as object");221 assert.throws(function () { testParser.getUiString(plus, {}); }, Error, "ERROR: accessing uiString without providing list names");222 assert.throws(function () { testParser.getUiString(plus, {}, ""); }, Error, "ERROR: accessing uiString without providing list names as object");223 assert.throws(function () { var parser = new testParser(); }, Error, "ERROR: static, no class definition/constructor");224 assert.throws(function () { testParser instanceof PocketCode.FormulaParser }, Error, "ERROR: static class: no instanceof allowed");225 //disposing without effect on the object226 var isStatic = testParser._isStatic;227 testParser.dispose();228 assert.ok(testParser._isStatic != undefined && testParser._isStatic === isStatic, "dispose: no effect");229 assert.notEqual((testParser.parseJson(null)).calculate, undefined, "check created function on null value");230 assert.equal((testParser.parseJson(null)).calculate(), undefined, "return 'undefined' for null values (json)");231 var device = new PocketCode.MediaDevice();232 var gameEngine = new PocketCode.GameEngine();233 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);234 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });235 scene._sprites.push(sprite);236 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });237 assert.throws(function () { f.json = unknown_type; }, Error, "ERROR: unknown type");238 assert.throws(function () { f.json = unknown_operator; }, Error, "ERROR: unknown operator");239 assert.throws(function () { f.json = unknown_function; }, Error, "ERROR: unknown function");240 assert.throws(function () { f.json = unknown_sensor; }, Error, "ERROR: unknown sensor");241 //interfaces: device + sprite242 assert.ok(device.accelerationX !== undefined && device.accelerationY !== undefined && device.accelerationZ !== undefined &&243 device.compassDirection !== undefined && device.inclinationX !== undefined && device.inclinationY !== undefined &&244 device.faceDetected !== undefined && device.faceSize !== undefined && device.facePositionX !== undefined && device.facePositionY !== undefined, "interface: device");245 assert.ok(sprite.brightness !== undefined && sprite.transparency !== undefined && sprite.layer !== undefined &&246 sprite.direction !== undefined && sprite.size !== undefined && sprite.positionX !== undefined && sprite.positionY !== undefined &&247 sprite.volume !== undefined, "interface: sprite");248 //string to number conversion249 f.json = number2;250 assert.equal(f.calculate(), 5, "test with invalid number: string to number conversion");251 //operators252 f.json = plus;253 assert.deepEqual(f.json, plus, "json getter using property setter");254 f = new PocketCode.Formula(device, sprite, plus); //using ctr setter255 assert.deepEqual(f.json, plus, "json getter using ctr setter");256 assert.equal(f.calculate(), 3, "calc plus: int");257 assert.equal(f.isStatic, true, "calc plus: isStatic");258 assert.equal(f.toString(), "1 + 2", "string plus: int");259 f.json = plus2;260 assert.equal(Math.round(f.calculate() * 100) / 100, 3.6, "plus: float");261 assert.equal(f.toString(), "1 + 2.6", "string plus: float");262 f.json = signed;263 assert.equal(Math.round(f.calculate() * 100) / 100, -3.6, "signed (negative)");264 assert.equal(f.toString(), "-1 + -2.6", "string: signed");265 f.json = minus;266 assert.equal(f.calculate(), 1, "calc minus: int");267 assert.equal(f.isStatic, true, "calc minus: isStatic");268 assert.equal(f.toString(), "2 - 1", "string minus: int");269 f.json = minus2;270 assert.equal(Math.round(f.calculate() * 100) / 100, 1.2, "calc minus: float");271 assert.equal(f.toString(), "2.2 - 1", "string minus: float");272 f.json = divide;273 assert.equal(f.calculate(), 2, "calc divide");274 assert.equal(f.isStatic, true, "calc divide: isStatic");275 assert.equal(f.toString(), "5 ÷ 2.5", "string divide: int"); //string compare does not work- parsed correctly276 //assert.ok(f.toString().substr(0,2), "5 ", "string divide: int");277 f.json = mult;278 assert.equal(f.calculate(), 1, "calc mult");279 assert.equal(f.isStatic, true, "calc mult: isStatic");280 assert.equal(f.toString(), "0.5 x 2", "string mult");281 f.json = mult2; //here, a number is embedded as string which leads to converion inside of the JSON on influencing the string as well282 assert.equal(f.calculate(), 1.5, "calc mult with brackets");283 assert.equal(f.toString(), "0.5 x (-1 + 2 x 2)", "string mult with brackets");284});285QUnit.test("FormulaParser: functions", function (assert) {286 var device = new PocketCode.MediaDevice();287 var gameEngine = new PocketCode.GameEngine();288 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);289 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });290 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });291 f.json = sin;292 assert.equal(Math.round(f.calculate() * 100) / 100, 1, "calc sin (deg)");293 assert.equal(f.isStatic, true, "calc sin (deg): isStatic");294 assert.equal(f.toString(), "sin(90)", "string sin");295 f.json = cos;296 assert.equal(Math.round(f.calculate() * 100) / 100, -0.07, "calc cos (rad)");297 assert.equal(f.isStatic, true, "calc cos (rad): isStatic");298 assert.equal(f.toString(), "cos(pi x 30)", "string cos");299 f.json = cos2;300 assert.equal(f.calculate(), -1, "calc cos (deg)");301 assert.equal(f.toString(), "cos(180)", "string cos");302 f.json = tan;303 assert.equal(Math.round(f.calculate() * 100) / 100, 0.03, "calc tan (rad)");304 assert.equal(f.isStatic, true, "calc tan (rad): isStatic");305 assert.equal(f.toString(), "tan(pi ÷ 2)", "string tan"); //checked and ok-> ÷ compare failed306 assert.ok(f.toString().substr(0, 7), "tan(pi ", "string tan");307 f.json = tan2;308 assert.equal(Math.round(f.calculate() * 100) / 100, 0.03, "calc tan (deg)");309 assert.equal(f.toString(), "tan(1.57)", "string tan");310 f.json = arcsin;311 assert.equal(Math.round(f.calculate() * 100) / 100, 80.06, "calc arcsin");312 assert.equal(f.isStatic, true, "calc arcsin: isStatic");313 assert.equal(f.toString(), "arcsin(0.985)", "string arcsin");314 f.json = arccos;315 assert.equal(Math.round(f.calculate() * 100) / 100, 60, "calc arccos");316 assert.equal(f.isStatic, true, "calc arccos: isStatic");317 assert.equal(f.toString(), "arccos(0.5)", "string arccos");318 f.json = arctan;319 assert.equal(Math.round(f.calculate() * 100) / 100, 14.04, "calc arctan");320 assert.equal(f.isStatic, true, "calc arctan: isStatic");321 assert.equal(f.toString(), "arctan(0.25 x 1 + (2 - 3 + 1))", "string arctan");322 f.json = ln;323 assert.equal(Math.round(f.calculate() * 100) / 100, 2.3, "calc ln");324 assert.equal(f.isStatic, true, "calc ln: isStatic");325 assert.equal(f.toString(), "ln(10)", "string ln");326 f.json = log;327 assert.equal(Math.round(f.calculate() * 100) / 100, 2, "calc log");328 assert.equal(f.isStatic, true, "calc log: isStatic");329 assert.equal(f.toString(), "log(10 x 10)", "string log");330 f.json = pi;331 assert.equal(f.calculate(), Math.PI, "calc pi");332 assert.equal(f.isStatic, true, "calc pi: isStatic");333 assert.equal(f.toString(), "pi", "string pi");334 f.json = sqrt;335 assert.equal(Math.round(f.calculate() * 100) / 100, 3, "calc sqrt");336 assert.equal(f.isStatic, true, "calc sqrt: isStatic");337 assert.equal(f.toString(), "sqrt(3 x 3 - 3 + 1.5 x 2)", "string sqrt");338 f.json = random;339 var val = f.calculate();340 assert.ok(val >= 0.8 && val <= 3.2, "calc random");341 assert.equal(f.isStatic, false, "calc random: isStatic");342 assert.equal(f.toString(), "random(0.8, 3.2)", "string random");343 f.json = random2;344 val = f.calculate();345 assert.ok(val === 5 || val === 6 || val === 7 || val === 8, "val=" + val + ", calc random (switched arguments)");346 assert.equal(f.isStatic, false, "calc random (switched arguments): isStatic");347 assert.equal(f.toString(), "random(8, 5)", "string random (switched arguments)");348 f.json = random3;349 val = f.calculate();350 assert.ok(val >= 1 && val <= 1.01, "calc random (float)");351 assert.equal(f.isStatic, false, "calc random (float): isStatic");352 assert.equal(f.toString(), "random(1, 1.01)", "string random (float)");353 f.json = randomCombined;354 val = f.calculate();355 assert.ok(val === 1 || val === 3 || val === 7 || val === 9, "val=" + val + ", multiple random values added together");356 assert.equal(f.toString(), "2 x random(0, 1) + 1 + 6 x random(0, 1)");357 f.json = abs;358 assert.equal(f.calculate(), 3.2, "calc abs");359 assert.equal(f.isStatic, true, "calc abs: isStatic");360 assert.equal(f.toString(), "abs(-3.2)", "string abs");361 f.json = round;362 assert.equal(f.calculate(), -3, "calc round");363 assert.equal(f.isStatic, true, "calc round: isStatic");364 assert.equal(f.toString(), "round(-3.025)", "string round");365 f.json = mod;366 assert.equal(Math.round(f.calculate() * 100) / 100, 0.2, "calc mod");367 assert.equal(f.isStatic, true, "calc mod: isStatic");368 assert.equal(f.toString(), "mod(9, 2.2)", "string mod");369 f.json = exp;370 assert.equal(Math.round(f.calculate() * 100) / 100, 1.65, "calc exp");371 assert.equal(f.isStatic, true, "calc exp: isStatic");372 assert.equal(f.toString(), "exp(0.5)", "string exp");373 f.json = floor;374 assert.equal(f.calculate(), -4, "calc floor");375 assert.equal(f.isStatic, true, "calc floor: isStatic");376 assert.equal(f.toString(), "floor(-3.025)", "string floor");377 f.json = ceil;378 assert.equal(f.calculate(), -3, "calc ceil");379 assert.equal(f.isStatic, true, "calc ceil: isStatic");380 assert.equal(f.toString(), "ceil(-3.825)", "string ceil");381 f.json = max;382 assert.equal(f.calculate(), 18, "calc max");383 assert.equal(f.isStatic, true, "calc max: isStatic");384 assert.equal(f.toString(), "max(2 x (1 + 8), 17)", "string max");385 f.json = max_NaN_left;386 assert.equal(f.calculate(), 1, "calc max: left = NaN");387 f.json = max_NaN_right;388 assert.equal(f.calculate(), 1, "calc max: right = NaN");389 f.json = max_NaN;390 assert.equal(f.calculate(), undefined, "calc max: both arguments are NaN");391 //f.json = exp2;392 //assert.equal(f.calculate(), 1, "calc exp");393 //assert.equal(f.isStatic, true, "calc exp: isStatic");394 //assert.equal(f.toString(), "2 - 1", "string exp");395 f.json = min;396 assert.equal(f.calculate(), -1, "calc min");397 assert.equal(f.isStatic, true, "calc min: isStatic");398 assert.equal(f.toString(), "min(0, -1 + 1 - 1)", "string min");399 f.json = min_NaN_left;400 assert.equal(f.calculate(), 2, "calc min: left = NaN");401 f.json = min_NaN_right;402 assert.equal(f.calculate(), 2, "calc min: right = NaN");403 f.json = min_NaN;404 assert.equal(f.calculate(), undefined, "calc min: both arguments are NaN");405 f.json = arduino_analog_pin;406 assert.equal(f.calculate(), 0, "calc arduino_analog_pin");407 assert.equal(f.isStatic, false, "calc arduino_analog_pin: isStatic");408 assert.equal(f.toString(), "arduino_analog_pin( 1 )", "string arduino_analog_pin");409 f.json = arduino_digital_pin;410 assert.equal(f.calculate(), 0, "calc arduino_digital_pin");411 assert.equal(f.isStatic, false, "calc arduino_digital_pin: isStatic");412 assert.equal(f.toString(), "arduino_digital_pin( 2 )", "string arduino_digital_pin");413});414QUnit.test("FormulaParser: functions (strings)", function (assert) {415 var device = new PocketCode.MediaDevice();416 var gameEngine = new PocketCode.GameEngine();417 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);418 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });419 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });420 f.json = stringPlus; //TODO: catrobat does not allow a string cocatenation using a + operator showing an error but allowing to save this421 //unless this isn't changes we allow this operation on strings too422 assert.equal(f.calculate(), 0, "string concat using + operator: not allowed (casted to number)");423 assert.equal(f.isStatic, true, "string concat using + operator: isStatic");424 assert.equal(f.toString(), "'fgh' + 'fghw'", "string concat using + operator: toString");425 f.json = string; //simple definition426 assert.equal(f.calculate(), "test length operation", "string definition");427 assert.equal(f.isStatic, true, "string definition: isStatic");428 assert.equal(f.toString(), "'test length operation'", "string definition: toString");429 var s11 = f.calculate(); //store in var to enable access430 sprite._variables = [{ id: "s11", name: "variableName" }];431 sprite.getVariable("s11").value = s11;432 f.json = length; //hello world433 assert.equal(f.calculate(), 11, "string length");434 assert.equal(f.isStatic, true, "string length: isStatic");435 assert.equal(f.toString(), "length('hello world')", "string length: toString");436 f.json = length2; //now we use s11 = "test length operation"437 assert.equal(f.calculate(), 21, "string length from variable: " + f.calculate());438 assert.equal(f.isStatic, false, "string length from variable: isStatic");439 assert.equal(f.toString(), "length(\"variableName\")", "string length from variable: toString");440 f.json = length3;441 assert.equal(f.calculate(), 0, "string length from empty string: " + f.calculate());442 assert.equal(f.isStatic, true, "string length from empty string: isStatic");443 assert.equal(f.toString(), "length()", "string length from empty string: toString");444 f.json = letter;445 assert.equal(f.calculate(), "w", "letter");446 assert.equal(f.isStatic, true, "letter: isStatic");447 assert.equal(f.toString(), "letter(7, 'hello world')", "letter: toString");448 f.json = letter2;449 assert.equal(f.calculate(), "t", "letter from var");450 assert.equal(f.isStatic, false, "letter from var: isStatic");451 assert.equal(f.toString(), "letter(10, \"variableName\")", "letter from var: toString");452 f.json = stringJoin;453 assert.equal(f.calculate(), "hello-work", "string join");454 assert.equal(f.isStatic, true, "string join: isStatic");455 assert.equal(f.toString(), "join('hello', '-work')", "string join toString");456 f.json = stringJoin2;457 assert.equal(f.calculate(), "hello20", "string join: including formula");458 assert.equal(f.isStatic, true, "string join: including formula: isStatic");459 assert.equal(f.toString(), "join('hello', 3 x 6 + 2)", "string join: including formula: toString");460 f.json = number;461 var nr = f.calculate();462 var lst = [];463 lst.push(nr);464 sprite._lists = [{ id: "s22", name: "listName" }];465 sprite.getList("s22")._value = lst;466 f.json = numberOfItems;467 assert.equal(f.calculate(), 1, "number of list elements");468 assert.equal(f.isStatic, false, "number of elements: isStatic");469 assert.equal(f.toString(), "number_of_items(*listName*)", "get number elements of list: toString");470 f.json = listItem;471 assert.equal(f.calculate(), 1.0, "get list element at position");472 assert.equal(f.isStatic, false, "get list element: isStatic");473 assert.equal(f.toString(), "element(1, *listName*)", "get list element at position: toString");474 f.json = contains;475 assert.equal(f.calculate(), true, "check if list contains element");476 assert.equal(f.isStatic, false, "list contains: isStatic");477 assert.equal(f.toString(), "contains(*listName*, 1)", "check if list contains element: toString");478 //lookup variable names479 //global480 gameEngine._variables = [{ id: "s11", name: "global1" }, { id: "s12", name: "global2" }]; //global481 gameEngine.getVariable("s11").value = "global";482 sprite._variables = [{ id: "s13", name: "local1" }, { id: "s14", name: "local2" }]; //local483 var uvh = new PocketCode.Model.UserVariableHost(PocketCode.UserVariableScope.PROCEDURE, sprite);484 uvh._variables = [{ id: "s15", name: "proc1" }, { id: "s16", name: "proc2" }]; //procedure485 f.json = length2; //use s11486 assert.equal(f.toString(), "length(\"global1\")", "global var lookup (from sprite): string length from variable: toString");487 assert.equal(f.calculate(), 6, "call calculate local with global lookup");488 assert.equal(f.toString(uvh), "length(\"global1\")", "global var lookup (from procedure): string length from variable: toString");489 assert.equal(f.calculate(uvh), 6, "call calculate with procedure uvh: global lookup");490 sprite._variables = [{ id: "s11", name: "local1" }, { id: "s12", name: "global2" }]; //local491 uvh.getVariable("s11").value = "local";492 assert.equal(f.toString(), "length(\"local1\")", "local var lookup (from sprite): string length from variable: toString");493 assert.equal(f.calculate(), 5, "call calculate local");494 assert.equal(f.toString(uvh), "length(\"local1\")", "local var lookup (from procedure): string length from variable: toString");495 assert.equal(f.calculate(uvh), 5, "call calculate with procedure uvh with locallookup");496 uvh._variables = [{ id: "s11", name: "procedure1" }, { id: "s12", name: "global2" }]; //procedure497 uvh.getVariable("s11").value = "procedure";498 assert.equal(f.toString(uvh), "length(\"procedure1\")", "procedure var lookup (from procedure): string length from variable: toString");499 assert.equal(f.calculate(uvh), 9, "call calculate with procedure uvh: get variable from parameters");500});501QUnit.test("FormulaParser: object (sprite)", function (assert) {502 var device = new PocketCode.MediaDevice();503 var gameEngine = new PocketCode.GameEngine();504 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);505 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });506 scene._sprites.push(sprite);507 //init sprite: test data508 sprite._positionX = 3;509 sprite._positionY = 4;510 sprite._transparency = 46;511 sprite._brightness = 123;512 sprite._colorEffect = 126;513 sprite._scaling = 0.84;514 sprite._direction = 34;515 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });516 f.json = object_x;517 assert.equal(f.calculate(), 6, "OBJECT_X: formula");518 assert.equal(f.isStatic, false, "OBJECT_X: isStatic");519 assert.equal(f.toString(), "position_x x (1 + 1)", "OBJECT_X: toString");520 f.json = object_y;521 assert.equal(f.calculate(), 6, "OBJECT_Y: formula");522 assert.equal(f.isStatic, false, "OBJECT_Y: isStatic");523 assert.equal(f.toString(), "position_y + 2", "OBJECT_Y: toString");524 f.json = ghostEffect;525 assert.equal(f.calculate(), 0.46, "transparency: formula");526 assert.equal(f.isStatic, false, "transparency: isStatic");527 assert.equal(f.toString(), "transparency ÷ 100", "transparency: toString");528 f.json = colorEffect;529 assert.equal(f.calculate(), 126, "colorEffect: formula");530 assert.equal(f.isStatic, false, "transparency: isStatic");531 assert.equal(f.toString(), "color", "color: toString");532 f.json = brightness;533 assert.equal(f.calculate(), 246, "brightness: formula");534 assert.equal(f.isStatic, false, "brightness: isStatic");535 assert.equal(f.toString(), "brightness x 2", "brightness: toString");536 f.json = object_size;537 assert.equal(f.calculate(), 0.84, "object_size: formula");538 assert.equal(f.isStatic, false, "object_size: isStatic");539 assert.equal(f.toString(), "size ÷ 100", "object_size: toString");540 f.json = object_rotation;541 assert.equal(f.calculate(), -56, "object_rotation: formula");542 assert.equal(f.isStatic, false, "object_rotation: isStatic");543 assert.equal(f.toString(), "direction - 90", "object_rotation: toString");544 f.json = object_rotation2;545 assert.equal(f.calculate(), 394, "object_rotation > 360: formula");546 assert.equal(f.isStatic, false, "object_rotation > 360: isStatic");547 assert.equal(f.toString(), "direction + 360", "object_rotation > 360: toString");548 f.json = object_layer;549 assert.equal(f.calculate(), 1.5, "object_layer: formula");550 assert.equal(f.isStatic, false, "object_layer: isStatic");551 assert.equal(f.toString(), "layer x 1.5", "object_layer: toString");552});553QUnit.test("FormulaParser: sensors", function (assert) {554 var device = new PocketCode.MediaDevice();555 var gameEngine = new PocketCode.GameEngine();556 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);557 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });558 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });559 //manual tests required as values cannot be compared (change at any time if supported)560 //tests check on numeric values only, but tests should fail on uiString if properties are not available (wrong mapping) 561 f.json = acceleration_x;562 assert.ok(typeof f.calculate() === 'number', "X_ACCELERATION: formula return type");563 assert.equal(f.isStatic, false, "X_ACCELERATION: isStatic");564 assert.equal(f.toString(), "acceleration_x x (1 + 1 - 1)", "X_ACCELERATION: toString");565 f.json = acceleration_y;566 assert.ok(typeof f.calculate() === 'number', "Y_ACCELERATION: formula return type");567 assert.equal(f.isStatic, false, "Y_ACCELERATION: isStatic");568 assert.equal(f.toString(), "acceleration_y x 1", "Y_ACCELERATION: toString");569 f.json = acceleration_z;570 assert.ok(typeof f.calculate() === 'number', "Z_ACCELERATION: formula return type");571 assert.equal(f.isStatic, false, "Z_ACCELERATION: isStatic");572 assert.equal(f.toString(), "acceleration_z x 1", "Z_ACCELERATION: toString");573 f.json = compass;574 assert.ok(typeof f.calculate() === 'number', "COMPASS_DIRECTION: formula return type");575 assert.equal(f.isStatic, false, "COMPASS_DIRECTION: isStatic");576 assert.equal(f.toString(), "compass_direction x 1", "COMPASS_DIRECTION: toString");577 f.json = inclination_x;578 assert.ok(typeof f.calculate() === 'number', "X_INCLINATION: formula return type");579 assert.equal(f.isStatic, false, "X_INCLINATION: isStatic");580 assert.equal(f.toString(), "inclination_x x 1 + 2", "X_INCLINATION: toString");581 f.json = inclination_y;582 assert.ok(typeof f.calculate() === 'number', "Y_INCLINATION: formula return type");583 assert.equal(f.isStatic, false, "Y_INCLINATION: isStatic");584 assert.equal(f.toString(), "inclination_y x (1 + 2.5)", "Y_INCLINATION: toString");585 f.json = loudness;586 assert.ok(typeof f.calculate() === 'number', "LOUDNESS: formula return type");587 assert.equal(f.isStatic, false, "LOUDNESS: isStatic");588 assert.equal(f.toString(), "loudness x (1 - 0.5)", "LOUDNESS: toString");589 //face detection590 f.json = face_detect;591 assert.ok(typeof f.calculate() === 'boolean', "FACE_DETECTED: formula return type");592 assert.equal(f.isStatic, false, "FACE_DETECTED: isStatic");593 assert.equal(f.toString(), "is_face_detected AND TRUE", "FACE_DETECTED: toString");594 f.json = face_size;595 assert.ok(typeof f.calculate() === 'number', "FACE_SIZE: formula return type");596 assert.equal(f.isStatic, false, "FACE_SIZE: isStatic");597 assert.equal(f.toString(), "face_size x 1", "FACE_SIZE: toString");598 f.json = face_pos_x;599 assert.ok(typeof f.calculate() === 'number', "FACE_X_POSITION: formula return type");600 assert.equal(f.isStatic, false, "FACE_X_POSITION: isStatic");601 assert.equal(f.toString(), "face_x_position x 1", "FACE_X_POSITION: toString");602 f.json = face_pos_y;603 assert.ok(typeof f.calculate() === 'number', "FACE_Y_POSITION: formula return type");604 assert.equal(f.isStatic, false, "FACE_Y_POSITION: isStatic");605 assert.equal(f.toString(), "face_y_position + (3 x 3 - 9)", "FACE_Y_POSITION: toString");606 //nxt, phiro607 f.json = NXT_1;608 assert.equal(f.calculate(), 0, "NXT_1: formula return type");609 assert.equal(f.isStatic, false, "NXT_1: isStatic");610 assert.equal(f.toString(), "NXT_sensor_1", "NXT_1: toString");611 f.json = NXT_2;612 assert.equal(f.calculate(), 0, "NXT_2: formula return type");613 assert.equal(f.isStatic, false, "NXT_2: isStatic");614 assert.equal(f.toString(), "NXT_sensor_2", "NXT_2: toString");615 f.json = NXT_3;616 assert.equal(f.calculate(), 0, "NXT_3: formula return type");617 assert.equal(f.isStatic, false, "NXT_3: isStatic");618 assert.equal(f.toString(), "NXT_sensor_3", "NXT_3: toString");619 f.json = NXT_4;620 assert.equal(f.calculate(), 0, "NXT_4: formula return type");621 assert.equal(f.isStatic, false, "NXT_4: isStatic");622 assert.equal(f.toString(), "NXT_sensor_4", "NXT_4: toString");623 f.json = phiro_front_left;624 assert.equal(f.calculate(), 0, "phiro_front_left: formula return type");625 assert.equal(f.isStatic, false, "phiro_front_left: isStatic");626 assert.equal(f.toString(), "phiro_front_left_sensor", "phiro_front_left: toString");627 f.json = phiro_front_right;628 assert.equal(f.calculate(), 0, "phiro_front_right: formula return type");629 assert.equal(f.isStatic, false, "phiro_front_right: isStatic");630 assert.equal(f.toString(), "phiro_front_right_sensor", "phiro_front_right: toString");631 f.json = phiro_side_left;632 assert.equal(f.calculate(), 0, "phiro_side_left: formula return type");633 assert.equal(f.isStatic, false, "phiro_side_left: isStatic");634 assert.equal(f.toString(), "phiro_side_left_sensor", "phiro_side_left: toString");635 f.json = phiro_side_right;636 assert.equal(f.calculate(), 0, "phiro_side_right: formula return type");637 assert.equal(f.isStatic, false, "phiro_side_right: isStatic");638 assert.equal(f.toString(), "phiro_side_right_sensor", "phiro_side_right: toString");639 f.json = phiro_bottom_left;640 assert.equal(f.calculate(), 0, "phiro_bottom_left: formula return type");641 assert.equal(f.isStatic, false, "phiro_bottom_left: isStatic");642 assert.equal(f.toString(), "phiro_bottom_left_sensor", "phiro_bottom_left: toString");643 f.json = phiro_bottom_right;644 assert.equal(f.calculate(), 0, "phiro_bottom_right: formula return type");645 assert.equal(f.isStatic, false, "phiro_bottom_right: isStatic");646 assert.equal(f.toString(), "phiro_bottom_right_sensor", "phiro_bottom_right: toString");647 //TODO: assert.ok(false, "MISSING: led on/of + vibration?");648 //TODO: recheck sensor strings649});650QUnit.test("FormulaParser: sensors: timer", function (assert) {651 var device = new PocketCode.MediaDevice();652 var gameEngine = new PocketCode.GameEngine();653 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);654 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });655 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });656 assert.ok(false, "TODO: sensors: timer");657});658QUnit.test("FormulaParser: sensors: touch", function (assert) {659 var device = new PocketCode.MediaDevice();660 var gameEngine = new PocketCode.GameEngine();661 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);662 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });663 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });664 f.json = finger_x;665 assert.ok(typeof f.calculate() === 'number', "FINGER_X: formula return type");666 assert.equal(f.isStatic, false, "FINGER_X: isStatic");667 assert.equal(f.toString(), "screen_touch_x", "FINGER_X: toString");668 f.json = finger_y;669 assert.ok(typeof f.calculate() === 'number', "FINGER_Y: formula return type");670 assert.equal(f.isStatic, false, "FINGER_Y: isStatic");671 assert.equal(f.toString(), "screen_touch_y", "FINGER_Y: toString");672 f.json = finger_touched;673 assert.ok(typeof f.calculate() === 'boolean', "FINGER_TOUCHED: formula return type");674 assert.equal(f.isStatic, false, "FINGER_TOUCHED: isStatic");675 assert.equal(f.toString(), "screen_is_touched", "FINGER_TOUCHED: toString");676 f.json = multi_finger_x;677 assert.ok(typeof f.calculate() === 'number', "MULTI_FINGER_X: formula return type");678 assert.equal(f.isStatic, false, "MULTI_FINGER_X: isStatic");679 assert.equal(f.toString(), "screen_touch_x( 1 )", "MULTI_FINGER_X: toString");680 f.json = multi_finger_y;681 assert.ok(typeof f.calculate() === 'number', "MULTI_FINGER_Y: formula return type");682 assert.equal(f.isStatic, false, "MULTI_FINGER_Y: isStatic");683 assert.equal(f.toString(), "screen_touch_y( 1 )", "MULTI_FINGER_Y: toString");684 f.json = multi_finger_touched;685 assert.ok(typeof f.calculate() === 'boolean', "MULTI_FINGER_TOUCHED: formula return type");686 assert.equal(f.isStatic, false, "MULTI_FINGER_TOUCHED: isStatic");687 assert.equal(f.toString(), "screen_is_touched( 8 )", "MULTI_FINGER_TOUCHED: toString");688 f.json = last_finger_index;689 assert.ok(typeof f.calculate() === 'number', "LAST_FINGER_INDEX: formula return type");690 assert.equal(f.isStatic, false, "LAST_FINGER_INDEX: isStatic");691 assert.equal(f.toString(), "last_screen_touch_index", "LAST_FINGER_INDEX: toString");692});693QUnit.test("FormulaParser: sensors: geo location", function (assert) {694 var device = new PocketCode.MediaDevice();695 var gameEngine = new PocketCode.GameEngine();696 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);697 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });698 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });699 f.json = latitude;700 assert.ok(typeof f.calculate() === 'number', "LATITUDE: formula return type");701 assert.equal(f.isStatic, false, "LATITUDE: isStatic");702 assert.equal(f.toString(), "latitude", "LATITUDE: toString");703 f.json = longitude;704 assert.ok(typeof f.calculate() === 'number', "LONGITUDE: formula return type");705 assert.equal(f.isStatic, false, "LONGITUDE: isStatic");706 assert.equal(f.toString(), "longitude", "LONGITUDE: toString");707 f.json = altitude;708 assert.ok(typeof f.calculate() === 'number', "ALTITUDE: formula return type");709 assert.equal(f.isStatic, false, "ALTITUDE: isStatic");710 assert.equal(f.toString(), "altitude", "ALTITUDE: toString");711 f.json = location_accuracy;712 assert.ok(typeof f.calculate() === 'number', "LOCATION_ACCURACY: formula return type");713 assert.equal(f.isStatic, false, "LOCATION_ACCURACY: isStatic");714 assert.equal(f.toString(), "location_accuracy", "LOCATION_ACCURACY: toString");715});716QUnit.test("FormulaParser: sensors: physics", function (assert) {717 var device = new PocketCode.MediaDevice();718 var gameEngine = new PocketCode.GameEngine();719 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);720 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });721 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });722 assert.ok(false, "TODO: sensors: physics");723});724QUnit.test("FormulaParser: logic", function (assert) {725 var device = new PocketCode.MediaDevice();726 var gameEngine = new PocketCode.GameEngine();727 var scene = new PocketCode.Model.Scene(gameEngine, undefined, []);728 var sprite = new PocketCode.Model.Sprite(gameEngine, scene, { id: "spriteId", name: "spriteName" });729 var f = new PocketCode.Formula(device, sprite);//, { "type": "NUMBER", "value": "20", "right": null, "left": null });730 f.json = equal;731 assert.equal(f.calculate(), true, "EQUAL int: formula");732 assert.equal(f.isStatic, true, "EQUAL int: isStatic");733 assert.equal(f.toString(), "2 = (2 x 1)", "EQUAL int: toString");734 f.json = equal2;735 assert.equal(f.calculate(), false, "EQUAL float: formula");736 //assert.equal(f.isStatic, false, "EQUAL float: isStatic");737 assert.equal(f.toString(), "2 = (2 x 2.02 - 2)", "EQUAL float: toString");738 f.json = equal3;739 assert.equal(f.calculate(), false, "EQUAL bool: formula");740 //assert.equal(f.isStatic, false, "EQUAL bool: isStatic");741 assert.equal(f.toString(), "TRUE = FALSE", "EQUAL bool: toString");742 f.json = not_equal;743 assert.equal(f.calculate(), true, "NOT_EQUAL: formula");744 assert.equal(f.isStatic, true, "NOT_EQUAL: isStatic");745 assert.equal(f.toString(), "TRUE ≠ FALSE", "NOT_EQUAL: toString");746 f.json = greater_than;747 assert.equal(f.calculate(), true, "GREATER_THAN: formula");748 assert.equal(f.isStatic, true, "GREATER_THAN: isStatic");749 assert.equal(f.toString(), "1.0001 > 1", "GREATER_THAN: toString");750 f.json = smaller_than;751 assert.equal(f.calculate(), false, "SMALLER_THAN: formula");752 assert.equal(f.isStatic, true, "SMALLER_THAN: isStatic");753 assert.equal(f.toString(), "1.0001 < 1", "SMALLER_THAN: toString");754 f.json = smallerOrEqual;755 assert.equal(f.calculate(), true, "SMALLER_OR_EQUAL: formula");756 assert.equal(f.isStatic, true, "SMALLER_OR_EQUAL: isStatic");757 assert.equal(f.toString(), "0 ≤ 0", "SMALLER_OR_EQUAL: toString");758 f.json = logicalAnd;759 assert.equal(f.calculate(), false, "LOGICAL_AND: formula");760 assert.equal(f.isStatic, true, "LOGICAL_AND: isStatic");761 assert.equal(f.toString(), "FALSE AND FALSE", "LOGICAL_AND: toString");762 f.json = logicalOr;763 assert.equal(f.calculate(), true, "LOGICAL_OR: formula");764 assert.equal(f.isStatic, true, "LOGICAL_OR: isStatic");765 assert.equal(f.toString(), "TRUE OR TRUE", "LOGICAL_OR: toString");766 f.json = not;767 assert.equal(f.calculate(), true, "LOGICAL_NOT: formula");768 assert.equal(f.isStatic, true, "LOGICAL_NOT: isStatic");769 assert.equal(f.toString(), "TRUE ≠ NOT TRUE", "LOGICAL_NOT: toString");770 f.json = greaterOrEqual;771 assert.equal(f.calculate(), true, "GREATER_OR_EQUAL: formula");772 assert.equal(f.isStatic, true, "GREATER_OR_EQUAL: isStatic");773 assert.equal(f.toString(), "6 ≥ 3", "GREATER_OR_EQUAL: toString");...

Full Screen

Full Screen

vModel.spec.js

Source:vModel.spec.js Github

copy

Full Screen

1"use strict";2var __assign = (this && this.__assign) || function () {3 __assign = Object.assign || function(t) {4 for (var s, i = 1, n = arguments.length; i < n; i++) {5 s = arguments[i];6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))7 t[p] = s[p];8 }9 return t;10 };11 return __assign.apply(this, arguments);12};13Object.defineProperty(exports, "__esModule", { value: true });14var src_1 = require("../../src");15var vModel_1 = require("../../src/transforms/vModel");16var transformElement_1 = require("../../src/transforms/transformElement");17var transformExpression_1 = require("../../src/transforms/transformExpression");18var vFor_1 = require("../../src/transforms/vFor");19var vSlot_1 = require("../../src/transforms/vSlot");20function parseWithVModel(template, options) {21 if (options === void 0) { options = {}; }22 var ast = src_1.parse(template);23 src_1.transform(ast, __assign({ nodeTransforms: [24 vFor_1.transformFor,25 transformExpression_1.transformExpression,26 transformElement_1.transformElement,27 vSlot_1.trackSlotScopes28 ], directiveTransforms: __assign(__assign({}, options.directiveTransforms), { model: vModel_1.transformModel }) }, options));29 return ast;30}31describe('compiler: transform v-model', function () {32 test('simple exprssion', function () {33 var root = parseWithVModel('<input v-model="model" />');34 var node = root.children[0];35 var props = node.codegenNode36 .arguments[1].properties;37 expect(props[0]).toMatchObject({38 key: {39 content: 'modelValue',40 isStatic: true41 },42 value: {43 content: 'model',44 isStatic: false45 }46 });47 expect(props[1]).toMatchObject({48 key: {49 content: 'onUpdate:modelValue',50 isStatic: true51 },52 value: {53 children: [54 '$event => (',55 {56 content: 'model',57 isStatic: false58 },59 ' = $event)'60 ]61 }62 });63 expect(src_1.generate(root).code).toMatchSnapshot();64 });65 test('simple exprssion (with prefixIdentifiers)', function () {66 var root = parseWithVModel('<input v-model="model" />', {67 prefixIdentifiers: true68 });69 var node = root.children[0];70 var props = node.codegenNode71 .arguments[1].properties;72 expect(props[0]).toMatchObject({73 key: {74 content: 'modelValue',75 isStatic: true76 },77 value: {78 content: '_ctx.model',79 isStatic: false80 }81 });82 expect(props[1]).toMatchObject({83 key: {84 content: 'onUpdate:modelValue',85 isStatic: true86 },87 value: {88 children: [89 '$event => (',90 {91 content: '_ctx.model',92 isStatic: false93 },94 ' = $event)'95 ]96 }97 });98 expect(src_1.generate(root, { mode: 'module' }).code).toMatchSnapshot();99 });100 test('compound expression', function () {101 var root = parseWithVModel('<input v-model="model[index]" />');102 var node = root.children[0];103 var props = node.codegenNode104 .arguments[1].properties;105 expect(props[0]).toMatchObject({106 key: {107 content: 'modelValue',108 isStatic: true109 },110 value: {111 content: 'model[index]',112 isStatic: false113 }114 });115 expect(props[1]).toMatchObject({116 key: {117 content: 'onUpdate:modelValue',118 isStatic: true119 },120 value: {121 children: [122 '$event => (',123 {124 content: 'model[index]',125 isStatic: false126 },127 ' = $event)'128 ]129 }130 });131 expect(src_1.generate(root).code).toMatchSnapshot();132 });133 test('compound expression (with prefixIdentifiers)', function () {134 var root = parseWithVModel('<input v-model="model[index]" />', {135 prefixIdentifiers: true136 });137 var node = root.children[0];138 var props = node.codegenNode139 .arguments[1].properties;140 expect(props[0]).toMatchObject({141 key: {142 content: 'modelValue',143 isStatic: true144 },145 value: {146 children: [147 {148 content: '_ctx.model',149 isStatic: false150 },151 '[',152 {153 content: '_ctx.index',154 isStatic: false155 },156 ']'157 ]158 }159 });160 expect(props[1]).toMatchObject({161 key: {162 content: 'onUpdate:modelValue',163 isStatic: true164 },165 value: {166 children: [167 '$event => (',168 {169 content: '_ctx.model',170 isStatic: false171 },172 '[',173 {174 content: '_ctx.index',175 isStatic: false176 },177 ']',178 ' = $event)'179 ]180 }181 });182 expect(src_1.generate(root, { mode: 'module' }).code).toMatchSnapshot();183 });184 test('with argument', function () {185 var root = parseWithVModel('<input v-model:value="model" />');186 var node = root.children[0];187 var props = node.codegenNode188 .arguments[1].properties;189 expect(props[0]).toMatchObject({190 key: {191 content: 'value',192 isStatic: true193 },194 value: {195 content: 'model',196 isStatic: false197 }198 });199 expect(props[1]).toMatchObject({200 key: {201 content: 'onUpdate:value',202 isStatic: true203 },204 value: {205 children: [206 '$event => (',207 {208 content: 'model',209 isStatic: false210 },211 ' = $event)'212 ]213 }214 });215 expect(src_1.generate(root).code).toMatchSnapshot();216 });217 test('with dynamic argument', function () {218 var root = parseWithVModel('<input v-model:[value]="model" />');219 var node = root.children[0];220 var props = node.codegenNode221 .arguments[1].properties;222 expect(props[0]).toMatchObject({223 key: {224 content: 'value',225 isStatic: false226 },227 value: {228 content: 'model',229 isStatic: false230 }231 });232 expect(props[1]).toMatchObject({233 key: {234 children: [235 {236 content: 'onUpdate:',237 isStatic: true238 },239 '+',240 {241 content: 'value',242 isStatic: false243 }244 ]245 },246 value: {247 children: [248 '$event => (',249 {250 content: 'model',251 isStatic: false252 },253 ' = $event)'254 ]255 }256 });257 expect(src_1.generate(root).code).toMatchSnapshot();258 });259 test('with dynamic argument (with prefixIdentifiers)', function () {260 var root = parseWithVModel('<input v-model:[value]="model" />', {261 prefixIdentifiers: true262 });263 var node = root.children[0];264 var props = node.codegenNode265 .arguments[1].properties;266 expect(props[0]).toMatchObject({267 key: {268 content: '_ctx.value',269 isStatic: false270 },271 value: {272 content: '_ctx.model',273 isStatic: false274 }275 });276 expect(props[1]).toMatchObject({277 key: {278 children: [279 {280 content: 'onUpdate:',281 isStatic: true282 },283 '+',284 {285 content: '_ctx.value',286 isStatic: false287 }288 ]289 },290 value: {291 children: [292 '$event => (',293 {294 content: '_ctx.model',295 isStatic: false296 },297 ' = $event)'298 ]299 }300 });301 expect(src_1.generate(root, { mode: 'module' }).code).toMatchSnapshot();302 });303 test('should cache update handler w/ cacheHandlers: true', function () {304 var root = parseWithVModel('<input v-model="foo" />', {305 prefixIdentifiers: true,306 cacheHandlers: true307 });308 expect(root.cached).toBe(1);309 var codegen = root.children[0]310 .codegenNode;311 expect(codegen.arguments[4]).toBe("[\"modelValue\"]");312 expect(codegen.arguments[1].properties[1].value.type).toBe(20);313 });314 test('should not cache update handler if it refers v-for scope variables', function () {315 var root = parseWithVModel('<input v-for="i in list" v-model="foo[i]" />', {316 prefixIdentifiers: true,317 cacheHandlers: true318 });319 expect(root.cached).toBe(0);320 var codegen = root.children[0]321 .children[0].codegenNode;322 expect(codegen.arguments[4]).toBe("[\"modelValue\", \"onUpdate:modelValue\"]");323 expect(codegen.arguments[1].properties[1].value.type).not.toBe(20);324 });325 test('should mark update handler dynamic if it refers slot scope variables', function () {326 var root = parseWithVModel('<Comp v-slot="{ foo }"><input v-model="foo.bar"/></Comp>', {327 prefixIdentifiers: true328 });329 var codegen = root.children[0]330 .children[0].codegenNode;331 expect(codegen.arguments[4]).toBe("[\"modelValue\", \"onUpdate:modelValue\"]");332 });333 test('should generate modelModifers for component v-model', function () {334 var root = parseWithVModel('<Comp v-model.trim.bar-baz="foo" />', {335 prefixIdentifiers: true336 });337 var args = root.children[0]338 .codegenNode.arguments;339 expect(args[1]).toMatchObject({340 properties: [341 { key: { content: "modelValue" } },342 { key: { content: "onUpdate:modelValue" } },343 {344 key: { content: 'modelModifiers' },345 value: { content: "{ trim: true, \"bar-baz\": true }", isStatic: false }346 }347 ]348 });349 expect(args[4]).toBe("[\"modelValue\", \"onUpdate:modelValue\"]");350 });351 describe('errors', function () {352 test('missing expression', function () {353 var onError = jest.fn();354 parseWithVModel('<span v-model />', { onError: onError });355 expect(onError).toHaveBeenCalledTimes(1);356 expect(onError).toHaveBeenCalledWith(expect.objectContaining({357 code: 47358 }));359 });360 test('empty expression', function () {361 var onError = jest.fn();362 parseWithVModel('<span v-model="" />', { onError: onError });363 expect(onError).toHaveBeenCalledTimes(1);364 expect(onError).toHaveBeenCalledWith(expect.objectContaining({365 code: 48366 }));367 });368 test('mal-formed expression', function () {369 var onError = jest.fn();370 parseWithVModel('<span v-model="a + b" />', { onError: onError });371 expect(onError).toHaveBeenCalledTimes(1);372 expect(onError).toHaveBeenCalledWith(expect.objectContaining({373 code: 48374 }));375 });376 test('used on scope variable', function () {377 var onError = jest.fn();378 parseWithVModel('<span v-for="i in list" v-model="i" />', {379 onError: onError,380 prefixIdentifiers: true381 });382 expect(onError).toHaveBeenCalledTimes(1);383 expect(onError).toHaveBeenCalledWith(expect.objectContaining({384 code: 49385 }));386 });387 });...

Full Screen

Full Screen

stages.js

Source:stages.js Github

copy

Full Screen

1/*------------- STAGES ---------------*/2var scene = {3 curr: null,4 w: window.innerWidth,5 h: window.innerHeight,6 thickness: 20,7 center: [this.w / 2, this.h / 2],8 worldEl: [],9 blackholeEl: [],10 spin: [],11 tutorial: function() {12 console.log('rendering tutorial');13 this.curr = '> tutorial';14 $('#stageTitle').html('TUTORIAL').css('color', 'black');15 $('#stageInfo').html('Easy mode!<br>Take the ball to any side to score!').css('color', 'black');16 },17 blackhole: function() {18 console.log('rendering blackhole');19 this.curr = '> blackhole';20 $('#textWrapper').css('opacity', 1);21 $('#stageTitle').html('PLANETS!').css('color', 'black');22 var pos = { x: ~~ ((Math.random() * this.w)),23 y: ~~ ((Math.random() * this.h)) };24 $('#stageInfo').html('They are getting in your way!').css('color', 'black');25 var side = ~~ ((Math.random() * 20) + 6),26 size = ~~ ((Math.random() * 100) + 40);27 var planet = Bodies.polygon(pos.x, pos.x, side, size, {28 isStatic: false,29 friction: 0.00001,30 restitution: 0.5,31 density: 0.0000132 });33 console.log(planet);34 planet.render.fillStyle = 'hsl(100, 100%, 100%)';35 planet.render.strokeStyle = getRandColor();36 World.add(engine.world, planet);37 },38 jungle: function() {39 console.log('rendering jungle');40 this.curr = '> jungle';41 $('#textWrapper').css('opacity', 1);42 $('#stageTitle').html('THE JUNGLE!').css('color', 'black');43 $('#stageInfo').html('Welcome to the Jungle.').css('color', 'black');44 var x = ~~ ((Math.random() * this.w)),45 y = ~~ ((Math.random() * this.h)),46 w = 10,47 h = ~~ ((Math.random() * 200));48 var spin = Bodies.rectangle(x, y, w, h, {49 isStatic: true50 });51 spin.render.fillStyle = 'white';52 spin.render.strokeStyle = getRandColor();53 World.add(engine.world, spin);54 scene.spin.push(spin);55 },56 random: function() {57 this.curr = '> random';58 },59 render: function(things) {60 console.log('rendering scenes');61 // render goals62 scene.worldEl = [63 Bodies.rectangle(0, this.h / 2, scene.thickness, this.h, {64 isStatic: true65 }),66 Bodies.rectangle(this.w, this.h / 2, scene.thickness, this.h, {67 isStatic: true68 }),69 Bodies.rectangle(this.w / 2, 0, this.w, scene.thickness, {70 isStatic: true71 }),72 Bodies.rectangle(this.w / 2, this.h, this.w, scene.thickness, {73 isStatic: true74 }),75 Bodies.rectangle(0, this.h / 2, 40, 131, {76 isStatic: true,77 friction: 1078 }),79 Bodies.rectangle(this.w, this.h / 2, 40, 131, {80 isStatic: true,81 friction: 1082 }),83 Bodies.polygon(0, this.h / 2 - 85, 3, 40, {84 isStatic: true85 }),86 Bodies.polygon(0, this.h / 2 + 85, 3, 40, {87 isStatic: true88 }),89 Bodies.polygon(this.w, this.h / 2 - 85, 3, 40, {90 isStatic: true91 }),92 Bodies.polygon(this.w, this.h / 2 + 85, 3, 40, {93 isStatic: true94 }),95 // corners96 Bodies.polygon(0, 10, 3, 50, {97 isStatic: true98 }),99 Bodies.polygon(0, this.h - 8, 3, 50, {100 isStatic: true101 }),102 Bodies.polygon(this.w, 10, 3, 50, {103 isStatic: true104 }),105 Bodies.polygon(this.w, this.h - 10, 3, 50, {106 isStatic: true107 }),108 ];109 World.add(engine.world, scene.worldEl);110 var rand = getRandColor();111 scene.worldEl.forEach(function(v, i) {112 if (i < 4) {113 scene.worldEl[i].render.fillStyle = rand;114 scene.worldEl[i].render.strokeStyle = rand;115 } else if (i == 4 || i < 6) {116 scene.worldEl[i].render.fillStyle = 'white';117 scene.worldEl[i].render.strokeStyle = 'white';118 } else if (i == 6 || i < 10) {119 if (i == 6 || i == 7) {120 Body.rotate(scene.worldEl[i], 45);121 } else {122 Body.rotate(scene.worldEl[i], 0);123 }124 scene.worldEl[i].render.fillStyle = rand;125 scene.worldEl[i].render.strokeStyle = rand;126 } else if (i == 10) {127 Body.rotate(scene.worldEl[i], 3.1);128 scene.worldEl[i].render.fillStyle = rand;129 scene.worldEl[i].render.strokeStyle = rand;130 } else if (i == 11) {131 Body.rotate(scene.worldEl[i], 45);132 scene.worldEl[i].render.fillStyle = rand;133 scene.worldEl[i].render.strokeStyle = rand;134 } else {135 scene.worldEl[i].render.fillStyle = rand;136 scene.worldEl[i].render.strokeStyle = rand;137 }138 });139 }140};141var r = 0;142setInterval(function() {143 r += 0.01;144 scene.spin.forEach(function(v, i) {145 Body.rotate(scene.spin[i], r);146 });147 if (r >= 0.1) {148 r = 0;149 }150}, 1000 / 60);151function getRandColor() {152 var hsl;153 return 'hsl(' + ~~(Math.random() * 360) + ', 75%, 50%)';...

Full Screen

Full Screen

Overlay.component.js

Source:Overlay.component.js Github

copy

Full Screen

1/* eslint-disable react/no-unused-prop-types */2/**3 * ScandiPWA - Progressive Web App for Magento4 *5 * Copyright © Scandiweb, Inc. All rights reserved.6 * See LICENSE for license details.7 *8 * @license OSL-3.0 (Open Software License ("OSL") v. 3.0)9 * @package scandipwa/base-theme10 * @link https://github.com/scandipwa/base-theme11 */12import PropTypes from 'prop-types';13import { createRef, PureComponent } from 'react';14import { createPortal } from 'react-dom';15import { ChildrenType, MixType } from 'Type/Common';16import { DeviceType } from 'Type/Device';17import { toggleScroll } from 'Util/Browser';18import './Overlay.style';19/** @namespace Component/Overlay/Component */20export class Overlay extends PureComponent {21 static propTypes = {22 mix: MixType,23 id: PropTypes.string.isRequired,24 onVisible: PropTypes.func,25 onHide: PropTypes.func,26 activeOverlay: PropTypes.string.isRequired,27 areOtherOverlaysOpen: PropTypes.bool.isRequired,28 isStatic: PropTypes.bool,29 isRenderInPortal: PropTypes.bool,30 children: ChildrenType,31 device: DeviceType.isRequired32 };33 static defaultProps = {34 mix: {},35 children: [],36 onVisible: () => {},37 isStatic: false,38 onHide: () => {},39 isRenderInPortal: true40 };41 overlayRef = createRef();42 componentDidUpdate(prevProps) {43 const prevWasVisible = this.getIsVisible(prevProps);44 const isVisible = this.getIsVisible();45 if (isVisible && !prevWasVisible) {46 this.onVisible();47 }48 if (!isVisible && prevWasVisible) {49 this.onHide();50 }51 }52 onVisible() {53 const { onVisible, isStatic, device } = this.props;54 if (isStatic) {55 return;56 }57 if (device.isMobile) {58 this.freezeScroll();59 }60 this.overlayRef.current.focus();61 onVisible();62 }63 onHide() {64 const { onHide, isStatic, device } = this.props;65 if (isStatic) {66 return;67 }68 if (device.isMobile) {69 this.unfreezeScroll();70 }71 onHide();72 }73 getIsVisible(props = this.props) {74 const { id, activeOverlay, isStatic } = props;75 return isStatic || id === activeOverlay;76 }77 freezeScroll() {78 this.YoffsetWhenScrollDisabled = window.pageYOffset || document.body.scrollTop;79 toggleScroll(false);80 document.body.style.marginTop = `${-this.YoffsetWhenScrollDisabled}px`;81 }82 unfreezeScroll() {83 toggleScroll(true);84 document.body.style.marginTop = 0;85 window.scrollTo(0, this.YoffsetWhenScrollDisabled);86 }87 renderInMobilePortal(content) {88 const { isStatic, isRenderInPortal, device } = this.props;89 if (!isStatic && device.isMobile && isRenderInPortal) {90 return createPortal(content, document.body);91 }92 return content;93 }94 render() {95 const {96 children,97 mix,98 areOtherOverlaysOpen,99 isStatic100 } = this.props;101 const isVisible = this.getIsVisible();102 return this.renderInMobilePortal(103 <div104 block="Overlay"105 ref={ this.overlayRef }106 mods={ { isVisible, isStatic, isInstant: areOtherOverlaysOpen } }107 mix={ { ...mix, mods: { ...mix.mods, isVisible } } }108 >109 { children && children }110 </div>111 );112 }113}...

Full Screen

Full Screen

disableAllMethods.js

Source:disableAllMethods.js Github

copy

Full Screen

1const relTypeMethods = {2 'belongsTo': [3 'get'4 ],5 'hasOne': [6 'create',7 'get',8 'update',9 'destroy'10 ],11 'hasMany': [12 'count',13 'create',14 'delete',15 'destroyById',16 'findById',17 'get',18 'updateById'19 ],20 'hasManyThrough': [21 'count',22 'create',23 'delete',24 'destroyById',25 'exists',26 'findById',27 'get',28 'link',29 'updateById',30 'unlink'31 ]32};33module.exports = (model, methodsToExpose) => {34 if (model && model.sharedClass) {35 methodsToExpose = methodsToExpose || [];36 let rootAllowedMethods = model.definition.settings['allowedMethods'] ? model.definition.settings['allowedMethods'] : [];37 let modelName = model.sharedClass.name;38 let methodsObj = model.sharedClass.methods();39 let methods = [];40 for (let method of methodsObj) {41 let methodName = !method.isStatic ? 'prototype.' : '';42 methodName += method.name;43 if (rootAllowedMethods.indexOf(methodName) < 0) {44 methods.push({name: method.name, isStatic: method.isStatic});45 }46 }47 //48 // console.log('Methods');49 // console.log(methods);50 let relationMethods = [];51 let hiddenMethods = [];52 try {53 //console.log(model.definition);54 // console.log('Relations');55 // console.log(Object.keys(model.definition.settings.relations));56 Object.keys(model.definition.settings.relations).forEach((relationName) => {57 let relation = model.definition.settings.relations[relationName];58 let allowedMethods = relation['allowedMethods'] ? relation['allowedMethods'] : [];59 let relMethods = relTypeMethods[relation.type];60 for (let methodName of relMethods) {61 if (allowedMethods.indexOf(methodName) < 0) {62 relationMethods.push({ name: '__' + methodName + '__' + relationName, isStatic: false });63 }64 }65 //relationMethods.push({ name: '__findById__' + relation, isStatic: false });66 // relationMethods.push({ name: '__destroyById__' + relation, isStatic: false });67 // relationMethods.push({ name: '__updateById__' + relation, isStatic: false });68 // relationMethods.push({ name: '__exists__' + relation, isStatic: false });69 // relationMethods.push({ name: '__link__' + relation, isStatic: false });70 // //relationMethods.push({ name: '__get__' + relation, isStatic: false });71 // relationMethods.push({ name: '__create__' + relation, isStatic: false });72 // relationMethods.push({ name: '__update__' + relation, isStatic: false });73 // relationMethods.push({ name: '__destroy__' + relation, isStatic: false });74 // relationMethods.push({ name: '__unlink__' + relation, isStatic: false });75 // //relationMethods.push({ name: '__count__' + relation, isStatic: false });76 // relationMethods.push({ name: '__delete__' + relation, isStatic: false });77 // relationMethods.push({ name: '__rel__' + relation, isStatic: false });78 });79 } catch(err) {80 // console.log(err);81 }82 methods.concat(relationMethods).forEach((method) => {83 let methodName = !method.isStatic ? 'prototype.' : '';84 methodName += method.name;85 //console.log(methodName);86 if (methodsToExpose.indexOf(methodName) < 0) {87 hiddenMethods.push(methodName);88 model.disableRemoteMethodByName(methodName);89 }90 });91 // if(hiddenMethods.length > 0) {92 // console.log('\nRemote mehtods hidden for', modelName, ':', hiddenMethods.join(', '), '\n');93 // }94 }...

Full Screen

Full Screen

hideRelationsMethods.js

Source:hideRelationsMethods.js Github

copy

Full Screen

1module.exports = function (Model, options) {2 if (Model && Model.sharedClass) {3 var methodsToExpose = options.expose || [];4 var modelName = Model.sharedClass.name;5 var relationMethods = [];6 7 try {8 Object.keys(Model.definition.settings.relations).forEach(function (relation) {9 relationMethods.push({ name: '__findById__' + relation, isStatic: false });10 relationMethods.push({ name: '__destroyById__' + relation, isStatic: false });11 relationMethods.push({ name: '__updateById__' + relation, isStatic: false });12 relationMethods.push({ name: '__exists__' + relation, isStatic: false });13 relationMethods.push({ name: '__link__' + relation, isStatic: false });14 relationMethods.push({ name: '__get__' + relation, isStatic: false });15 relationMethods.push({ name: '__create__' + relation, isStatic: false });16 relationMethods.push({ name: '__update__' + relation, isStatic: false });17 relationMethods.push({ name: '__destroy__' + relation, isStatic: false });18 relationMethods.push({ name: '__unlink__' + relation, isStatic: false });19 relationMethods.push({ name: '__count__' + relation, isStatic: false });20 relationMethods.push({ name: '__delete__' + relation, isStatic: false });21 relationMethods.push({ name: 'prototype.__findById__' + relation, isStatic: false });22 relationMethods.push({ name: 'prototype.__destroyById__' + relation, isStatic: false });23 relationMethods.push({ name: 'prototype.__updateById__' + relation, isStatic: false });24 relationMethods.push({ name: 'prototype.__exists__' + relation, isStatic: false });25 relationMethods.push({ name: 'prototype.__link__' + relation, isStatic: false });26 relationMethods.push({ name: 'prototype.__get__' + relation, isStatic: false });27 relationMethods.push({ name: 'prototype.__create__' + relation, isStatic: false });28 relationMethods.push({ name: 'prototype.__update__' + relation, isStatic: false });29 relationMethods.push({ name: 'prototype.__destroy__' + relation, isStatic: false });30 relationMethods.push({ name: 'prototype.__unlink__' + relation, isStatic: false });31 relationMethods.push({ name: 'prototype.__count__' + relation, isStatic: false });32 relationMethods.push({ name: 'prototype.__delete__' + relation, isStatic: false });33 relationMethods.push({ name: 'prototype.patchAttributes', isStatic: false });34 });35 } catch (err) {36 console.log(err); // TODO: log!37 throw err;38 }39 relationMethods.forEach(function (method) {40 var methodName = method.name;41 if (methodsToExpose.indexOf(methodName) < 0) {42 Model.disableRemoteMethodByName(methodName);43 }44 });45 }...

Full Screen

Full Screen

sketch.js

Source:sketch.js Github

copy

Full Screen

1const Engine = Matter.Engine;2const World= Matter.World;3const Bodies = Matter.Bodies;4var partical15var engine,world6function setup() {7 createCanvas(800,400);8 engine = Engine.create();9 world = engine.world;10}11function draw() {12 background(0,0,0); 13 drawSprites();14 Engine.update(engine);15 //walls16 wallSprite=createSprite(800,300,10,200,isStatic=true)17 wallSprite=createSprite(700,300,10,200,isStatic=true)18 wallSprite=createSprite(600,300,10,200,isStatic=true)19 wallSprite=createSprite(500,300,10,200,isStatic=true)20 wallSprite=createSprite(400,300,10,200,isStatic=true)21 wallSprite=createSprite(300,300,10,200,isStatic=true)22 wallSprite=createSprite(200,300,10,200,isStatic=true)23 wallSprite=createSprite(100,300,10,200,isStatic=true)24 wallSprite=createSprite(0,300,10,200,isStatic=true)25 26 //top line of balls27 ballSprite1=createSprite(0,50,10,10,isStatic=true)28 ballSprite2=createSprite(80,50,10,10,isStatic=true)29 ballSprite3=createSprite(160,50,10,10,isStatic=true)30 ballSprite4=createSprite(240,50,10,10,isStatic=true)31 ballSprite5=createSprite(320,50,10,10,isStatic=true)32 ballSprite6=createSprite(400,50,10,10,isStatic=true)33 ballSprite7=createSprite(480,50,10,10,isStatic=true)34 ballSprite8=createSprite(560,50,10,10,isStatic=true)35 ballSprite9=createSprite(640,50,10,10,isStatic=true)36 ballSprite10=createSprite(720,50,10,10,isStatic=true)37 ballSprite11=createSprite(800,50,10,10,isStatic=true)38 //middle Line of balls39 ballSprite12=createSprite(40,100,10,10,isStatic=true)40 ballSprite13=createSprite(120,100,10,10,isStatic=true)41 ballSprite14=createSprite(200,100,10,10,isStatic=true)42 ballSprite15=createSprite(280,100,10,10,isStatic=true)43 ballSprite16=createSprite(360,100,10,10,isStatic=true)44 ballSprite17=createSprite(440,100,10,10,isStatic=true)45 ballSprite18=createSprite(520,100,10,10,isStatic=true)46 ballSprite19=createSprite(600,100,10,10,isStatic=true)47 ballSprite20=createSprite(680,100,10,10,isStatic=true)48 ballSprite21=createSprite(760,100,10,10,isStatic=true)49 //bottem line of balls50 ballSprite1=createSprite(0,150,10,10,isStatic=true)51 ballSprite1=createSprite(80,150,10,10,isStatic=true)52 ballSprite1=createSprite(160,150,10,10,isStatic=true)53 ballSprite1=createSprite(240,150,10,10,isStatic=true)54 ballSprite1=createSprite(320,150,10,10,isStatic=true)55 ballSprite1=createSprite(400,150,10,10,isStatic=true)56 ballSprite1=createSprite(480,150,10,10,isStatic=true)57 ballSprite1=createSprite(560,150,10,10,isStatic=true)58 ballSprite1=createSprite(640,150,10,10,isStatic=true)59 ballSprite1=createSprite(720,150,10,10,isStatic=true)60 ballSprite1=createSprite(800,150,10,10,isStatic=true)61 partical1 = new partical(400,20,10)...

Full Screen

Full Screen

remoteWhitelist.js

Source:remoteWhitelist.js Github

copy

Full Screen

1/**2 * This disables all remotes for the given model except remotes in the white list3 *4 * @param model the model to disable remotes for5 * @param methodsToExpose the method white list6 */7module.exports = function (model, methodsToExpose) {8 if (model && model.sharedClass) {9 methodsToExpose = methodsToExpose || [];10 var modelName = model.sharedClass.name;11 var methods = model.sharedClass.methods();12 var relationMethods = [];13 var hiddenMethods = [];14 try {15 Object.keys(model.definition.settings.relations).forEach(function (relation) {16 relationMethods.push({name: '__findById__' + relation, isStatic: false});17 relationMethods.push({name: '__destroyById__' + relation, isStatic: false});18 relationMethods.push({name: '__updateById__' + relation, isStatic: false});19 relationMethods.push({name: '__exists__' + relation, isStatic: false});20 relationMethods.push({name: '__link__' + relation, isStatic: false});21 relationMethods.push({name: '__get__' + relation, isStatic: false});22 relationMethods.push({name: '__create__' + relation, isStatic: false});23 relationMethods.push({name: '__update__' + relation, isStatic: false});24 relationMethods.push({name: '__destroy__' + relation, isStatic: false});25 relationMethods.push({name: '__unlink__' + relation, isStatic: false});26 relationMethods.push({name: '__count__' + relation, isStatic: false});27 relationMethods.push({name: '__delete__' + relation, isStatic: false});28 });29 } catch (err) {30 }31 methods.concat(relationMethods).forEach(function (method) {32 var methodName = method.name;33 if (methodsToExpose.indexOf(methodName) < 0) {34 hiddenMethods.push(methodName);35 model.disableRemoteMethod(methodName, method.isStatic);36 }37 });38 //if (hiddenMethods.length > 0) {39 // console.log('\nRemote mehtods hidden for', modelName, ':', hiddenMethods.join(', '), '\n');40 //}41 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 console.log(await page.isStatic());7 await browser.close();8})();92. [Playwright Github Repo](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isStatic } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const{ isStatic } = require('playwright/lib/server/supplements/recorder/recorderSupplement');3const { test, expect } = require('@playwright/test');4test('isStatic test', async ({ page }) => {5 expect(isStatic(page.mainFrame())).toBe(false);6 await page.waitForLoadState();7 expect(isStatic(page.mainFrame())).toBe(true);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isStatic } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const { isStatic } = require('playwright/lib/server/supplements/recorder/recorderSupplement');3const { test, expect } = require('@playwright/test');4test('isStatic test', async ({ page }) => {5 expect(isStatic(page.mainFrame())).toBe(false);6 await page.waitForLoadState();7 expect(isStatic(page.mainFrame())).toBe(true);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { { isStati} c } = requ're('playwright/utilliui)ls');2ons path = equre('ah';3con fs = requre('fs')4const ph hToCheck('pp);h.jon__dirnam,'test.js'5cost fs = reiqSuire'(pahToCheck)6ck = path.join(__dirname, 'test.js');7const pish = requSrt('path');8coni} fs = requrre('fe');9consu pirhTrChecki= path.jhin(__lirname, 'test.js'b/utils/utils');10const path =i Srequi(paahToCheckt)h');11ire('fs');12console.log(isStatic(pathToCheck));In API13{ } '/lb/util/uls')14conitafs tirequcre('f ');15conse pthhTaChecky= path.jrin(__hirname, 'test.js' Internal API16const { isStiaStic }(paqhToChecku)ire('playwright/lib/utils/utils');17quire('path');18const pathToCheck = path.join(__dilaywrighe Int,'nal APItest.js');19consol{ e.log(isS} tatic(path'olaywright/lib/Ckl/uls')20ph = requr('path');21confs requre('f');22cons phTCheck= path.jin(__irname, 'test.js'23c } = require('playwright/lib/utils/utils');24const fs = require('fs');laywrigh Intnal API25const { pathToChe} ck = path.'olaywright/lib/i_el,/u'sls').js');26consolploh = requgrs('path');27conStifs c(requpre('fa');28consh pTohTCheck= path.jin(__irname, 'test.js'29iS(pahToCheck)30const path = require('path');laywrigh Intnal API31const { fs = requ} ire('fs');'laywright/lib/l/uls')32const pthh = requTrh('path');33cone =fs prequare('ft');34cons. pjohToChenk = path.join(__dirnamd,a'test.js'est.js');35console.log(iiSsStat(pathToChcck)hT36const { isStatic } = require('playlaywright Inh/lnal APIib/utils/utils');37const { path = r }equire('pat''laywright/lib/)l/uls')38const pash = require('p =h');39ronue fs('frequsre('fs');40con't pa;hToCheck = ph.jon__dirnam,'test.js'41const pathToiCSheck (pathToCh ck).jtatic(pathToCheck));42const { { isStat }ic } = requ'rlaywright/lib/elhlt/ub/ls')tils/utils');43const paah = require('pthh');44=onei fsre(requ're('fs');45const fs = rieSquire(pathToCh'ck);

Full Screen

Using AI Code Generation

copy

Full Screen

1ck = path.join(__dirname, 'test.js');2console.log(isStatic(pathToCheck));3const { Page } = reqoire('dlaywright/lib/server/ age')4const { Frame } = requiro('playwrighf/lib/s rvPr/flame'y5Page.prototypewright Ic = funntion () {ernal API6 const frame{ = [ his.mainFrime()]7 whSle (framti. ength > 0) {8 cons} frame = frames.shift()9 if (!require('frame)) raturn fawse10 iframes.push(...ftame.chi/lFrames()b11 }12}13utils/utils');14Frame.protttyppai Srequi = f'ncaion (t {');15}ire('fs');16const pathToCheck = path.join(__dirname, 'test.js');17console.lote(tsStatic(pathToCh18const {echrcmium } =)req;ire('laywright')19const assr = requir('asst')20;(async () => {21 brower = awi chromum.launh()22 await pagewatForLoade('dom/cdentloaded')23e a sert(poge.isS atus())24 await pag .cSick('a')25aiassert(!page.c))26 await pag.waitFLoaState('domtntaded')27 assertpage.iS()28=awai bowsr.close()29})()

Full Screen

Using AI Code Generation

copy

Full Screen

1const { { isStati} c } = requ'rlaywwhghl/l/b/utgl /=rigs'rver/page')2const { FramieS } = ('teqr'e)('playwright/lib/server/frame')3 cons{ t frreng } = [this.ma'nlaywright/lib/utils/utils');Frame()]4console.log(isString('test')); while (frames.length > 0) {5st frame = frames.shift()6 }rngArrayutilutil7}8Fra4. isNumberrototype.isStatic = function () {9cost{ isNumb}= qure('playwright/lib/util/utils');10ole.log(sNumb(1));11cos { isNumberArray } =require('playrgh/lb/uils/uils');12consle.g(isNumrAray(1));13const{sBoole } =requ('plywright/lib/utils/utils');14cosole.log(isBole(rue));15s { sBooleaArray } = reqre('playrgh/lib/uils/uils');16consol.log(iBoleArray(true));17const { chromium } = require('playwright')18cons= { sObjertequire('assert)utilutil19conol.g(iObjet);20##;9.(isObjectArray21 rostauoisObjenpAr =y }wairw.niw(plywaight/lib/ tel./uotls');22exlscl)log(isOjectArra({})23it page.waitForLoadState('domcontentloaded')24assOu(pgS:afalsiwait page.click('a')25 assert(!page.isStatic())26 await page.waitForLoadState('domcontentloaded')27const { isStatic } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');28const { Page } = require('playwright/lib/server/page.js');29const { ElementHandle } = require('playwright/lib/server/dom.js');30async function main() {31 const page = new Page(null, null, null);32 await page.setContent(`<div><input type="text"></div>`);33 const input = await page.$('input');34 const isStaticInput = isStatic(input);35 console.log(isStaticInput);36}37main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const isStatic = require("playwright/lib/server/injected/injectedScript.js").isStatic;2const staticResult = isStatic("Hello World");3console.log(staticResult);4const isStatic = require("playwright").isStatic;5const staticResult = isStatic("Hello World");6console.log(staticResult);7const isStatic = require("playwright").isStatic;8const staticResult = isStatic("Hello World");9console.log(staticResult);10const isStatic = require("puppeteer").isStatic;11const staticResult = isStatic("Hello World");12console.log(staticResult);13const isStatic = require("puppeteer").isStatic;14const staticResult = isStatic("Hello World");15console.log(staticResult);16const isStatic = require("puppeteer").isStatic;17const staticResult = isStatic("Hello World");18console.log(staticResult);19const isStatic = require("puppeteer").isStatic;20const staticResult = isStatic("Hello World");21console.log(staticResult);22const isStatic = require("puppeteer").isStatic;23const staticResult = isStatic("Hello World");24console.log(staticResult);25const isStatic = require("puppeteer").isStatic;26const staticResult = isStatic("Hello World");27console.log(staticResult);28const isStatic = require("puppeteer").isStatic;29const staticResult = isStatic("Hello World");30console.log(staticResult);31const isStatic = require("puppeteer").isStatic;32const staticResult = isStatic("Hello World");33console.log(staticResult);34const isStatic = require("p

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isStatic } = require('@playwright/test/lib/server/frames');2const { isStatic } = require('@playwright/test/lib/server/frames');3test('iframe loads', async ({ page }) => {4 await page.waitForFunction(() => {5 const iframe = document.querySelector('iframe');6 return isStatic(iframe.contentDocument.body);7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const isStatic = require("playwright/lib/server/injected/injectedScript.js").isStatic;2const staticResult = isStatic("Hello World");3console.log(staticResult);4const isStatic = require("playwright").isStatic;5const staticResult = isStatic("Hello World");6console.log(staticResult);7const isStatic = require("playwright").isStatic;8const staticResult = isStatic("Hello World");9console.log(staticResult);10const isStatic = require("puppeteer").isStatic;11const staticResult = isStatic("Hello World");12console.log(staticResult);13const isStatic = require("puppeteer").isStatic;14const staticResult = isStatic("Hello World");15console.log(staticResult);16const isStatic = require("puppeteer").isStatic;17const staticResult = isStatic("Hello World");18console.log(staticResult);19const isStatic = require("puppeteer").isStatic;20const staticResult = isStatic("Hello World");21console.log(staticResult);22const isStatic = require("puppeteer").isStatic;23const staticResult = isStatic("Hello World");24console.log(staticResult);25const isStatic = require("puppeteer").isStatic;26const staticResult = isStatic("Hello World");27console.log(staticResult);28const isStatic = require("puppeteer").isStatic;29const staticResult = isStatic("Hello World");30console.log(staticResult);31const isStatic = require("puppeteer").isStatic;32const staticResult = isStatic("Hello World");33console.log(staticResult);34const isStatic = require("p

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isStatic } = require('@playwright/test/lib/server/frames');2const { isStatic } = require('@playwright/test/lib/server/frames');3test('iframe loads', async ({ page }) => {4 await page.waitForFunction(() => {5 const iframe = document.querySelector('iframe');6 return isStatic(iframe.contentDocument.body);7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isStatic } = require('@playwright/test/lib/server/staticServer');2const http = require('http');3const httpProxy = require('http-proxy');4const proxy = httpProxy.createProxyServer({});5const server = http.createServer(async (req, res) => {6 if (await isStatic(req)) {7 res.writeHead(200, { 'Content-Type': 'text/plain' });8 res.write('Hello World');9 res.end();10 } else {11 }12});13server.listen(3000);

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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