How to use calculateEngine method in Testcafe

Best JavaScript code snippet using testcafe

classic.js

Source:classic.js Github

copy

Full Screen

...70 var curr = this;71 var entries = Object.assign({72 getDraft:function(){ return curr.draft; }73 }, this.draft.entry);74 return this.calculateEngine(items, entries, tmpl, citm);75 }7677 this.compute = function()78 {79 var curr = this;80 var items = this.data.scraped?this.data.scraped.items:{};81 var oitems = this.data.facade.items?this.data.facade.items:{};82 var sitems = [];83 for(var sid in items)84 {85 var sitm = items[sid];86 sitm.id = sid;87 sitm.logic = oitems[sid];88 sitems.push(sitm); ...

Full Screen

Full Screen

loading-bar.js

Source:loading-bar.js Github

copy

Full Screen

1/*2 * angular-loading-bar3 *4 * intercepts XHR requests and creates a loading bar.5 * Based on the excellent nprogress work by rstacruz (more info in readme)6 *7 * (c) 2013 Wes Cruver8 * License: MIT9 */10(function() {11'use strict';12// Alias the loading bar for various backwards compatibilities since the project has matured:13angular.module('angular-loading-bar', ['cfp.loadingBarInterceptor']);14angular.module('calculateengine.loadingBar', ['cfp.loadingBarInterceptor']);15/**16 * loadingBarInterceptor service17 *18 * Registers itself as an Angular interceptor and listens for XHR requests.19 */20angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])21 .config(['$httpProvider', function ($httpProvider) {22 var interceptor = ['$q', '$cacheFactory', '$timeout', '$rootScope', '$log', 'cfpLoadingBar', function ($q, $cacheFactory, $timeout, $rootScope, $log, cfpLoadingBar) {23 /**24 * The total number of requests made25 */26 var reqsTotal = 0;27 /**28 * The number of requests completed (either successfully or not)29 */30 var reqsCompleted = 0;31 /**32 * The amount of time spent fetching before showing the loading bar33 */34 var latencyThreshold = cfpLoadingBar.latencyThreshold;35 /**36 * $timeout handle for latencyThreshold37 */38 var startTimeout;39 /**40 * calls cfpLoadingBar.complete() which removes the41 * loading bar from the DOM.42 */43 function setComplete() {44 $timeout.cancel(startTimeout);45 cfpLoadingBar.complete();46 reqsCompleted = 0;47 reqsTotal = 0;48 }49 /**50 * Determine if the response has already been cached51 * @param {Object} config the config option from the request52 * @return {Boolean} retrns true if cached, otherwise false53 */54 function isCached(config) {55 var cache;56 var defaultCache = $cacheFactory.get('$http');57 var defaults = $httpProvider.defaults;58 // Choose the proper cache source. Borrowed from angular: $http service59 if ((config.cache || defaults.cache) && config.cache !== false &&60 (config.method === 'GET' || config.method === 'JSONP')) {61 cache = angular.isObject(config.cache) ? config.cache62 : angular.isObject(defaults.cache) ? defaults.cache63 : defaultCache;64 }65 var cached = cache !== undefined ?66 cache.get(config.url) !== undefined : false;67 if (config.cached !== undefined && cached !== config.cached) {68 return config.cached;69 }70 config.cached = cached;71 return cached;72 }73 return {74 'request': function(config) {75 // Check to make sure this request hasn't already been cached and that76 // the requester didn't explicitly ask us to ignore this request:77 if (!config.ignoreLoadingBar && !isCached(config)) {78 $rootScope.$broadcast('cfpLoadingBar:loading', {url: config.url});79 if (reqsTotal === 0) {80 startTimeout = $timeout(function() {81 cfpLoadingBar.start();82 }, latencyThreshold);83 }84 reqsTotal++;85 cfpLoadingBar.set(reqsCompleted / reqsTotal);86 }87 return config;88 },89 'response': function(response) {90 if (!response || !response.config) {91 $log.error('Broken interceptor detected: Config object not supplied in response:\n https://github.com/chieffancypants/angular-loading-bar/pull/50');92 return response;93 }94 if (!response.config.ignoreLoadingBar && !isCached(response.config)) {95 reqsCompleted++;96 $rootScope.$broadcast('cfpLoadingBar:loaded', {url: response.config.url, result: response});97 if (reqsCompleted >= reqsTotal) {98 setComplete();99 } else {100 cfpLoadingBar.set(reqsCompleted / reqsTotal);101 }102 }103 return response;104 },105 'responseError': function(rejection) {106 if (!rejection || !rejection.config) {107 $log.error('Broken interceptor detected: Config object not supplied in rejection:\n https://github.com/chieffancypants/angular-loading-bar/pull/50');108 return $q.reject(rejection);109 }110 if (!rejection.config.ignoreLoadingBar && !isCached(rejection.config)) {111 reqsCompleted++;112 $rootScope.$broadcast('cfpLoadingBar:loaded', {url: rejection.config.url, result: rejection});113 if (reqsCompleted >= reqsTotal) {114 setComplete();115 } else {116 cfpLoadingBar.set(reqsCompleted / reqsTotal);117 }118 }119 return $q.reject(rejection);120 }121 };122 }];123 $httpProvider.interceptors.push(interceptor);124 }]);125/**126 * Loading Bar127 *128 * This service handles adding and removing the actual element in the DOM.129 * Generally, best practices for DOM manipulation is to take place in a130 * directive, but because the element itself is injected in the DOM only upon131 * XHR requests, and it's likely needed on every view, the best option is to132 * use a service.133 */134angular.module('cfp.loadingBar', [])135 .provider('cfpLoadingBar', function() {136 this.includeSpinner = true;137 this.includeBar = true;138 this.latencyThreshold = 100;139 this.startSize = 0.02;140 this.parentSelector = 'body';141 this.spinnerTemplate = '<div id="loading-bar-spinner"><div class="spinner-icon"></div></div>';142 this.loadingBarTemplate = '<div id="loading-bar"><div class="bar"><div class="peg"></div></div></div>';143 this.$get = ['$injector', '$document', '$timeout', '$rootScope', function ($injector, $document, $timeout, $rootScope) {144 var $animate;145 var $parentSelector = this.parentSelector,146 loadingBarContainer = angular.element(this.loadingBarTemplate),147 loadingBar = loadingBarContainer.find('div').eq(0),148 spinner = angular.element(this.spinnerTemplate);149 var incTimeout,150 completeTimeout,151 started = false,152 status = 0;153 var includeSpinner = this.includeSpinner;154 var includeBar = this.includeBar;155 var startSize = this.startSize;156 /**157 * Inserts the loading bar element into the dom, and sets it to 2%158 */159 function _start() {160 if (!$animate) {161 $animate = $injector.get('$animate');162 }163 var $parent = $document.find($parentSelector).eq(0);164 $timeout.cancel(completeTimeout);165 // do not continually broadcast the started event:166 if (started) {167 return;168 }169 $rootScope.$broadcast('cfpLoadingBar:started');170 started = true;171 if (includeBar) {172 $animate.enter(loadingBarContainer, $parent, angular.element($parent[0].lastChild));173 }174 if (includeSpinner) {175 $animate.enter(spinner, $parent, angular.element($parent[0].lastChild));176 }177 _set(startSize);178 }179 /**180 * Set the loading bar's width to a certain percent.181 *182 * @param n any value between 0 and 1183 */184 function _set(n) {185 if (!started) {186 return;187 }188 var pct = (n * 100) + '%';189 loadingBar.css('width', pct);190 status = n;191 // increment loadingbar to give the illusion that there is always192 // progress but make sure to cancel the previous timeouts so we don't193 // have multiple incs running at the same time.194 $timeout.cancel(incTimeout);195 incTimeout = $timeout(function() {196 _inc();197 }, 250);198 }199 /**200 * Increments the loading bar by a random amount201 * but slows down as it progresses202 */203 function _inc() {204 if (_status() >= 1) {205 return;206 }207 var rnd = 0;208 // TODO: do this mathmatically instead of through conditions209 var stat = _status();210 if (stat >= 0 && stat < 0.25) {211 // Start out between 3 - 6% increments212 rnd = (Math.random() * (5 - 3 + 1) + 3) / 100;213 } else if (stat >= 0.25 && stat < 0.65) {214 // increment between 0 - 3%215 rnd = (Math.random() * 3) / 100;216 } else if (stat >= 0.65 && stat < 0.9) {217 // increment between 0 - 2%218 rnd = (Math.random() * 2) / 100;219 } else if (stat >= 0.9 && stat < 0.99) {220 // finally, increment it .5 %221 rnd = 0.005;222 } else {223 // after 99%, don't increment:224 rnd = 0;225 }226 var pct = _status() + rnd;227 _set(pct);228 }229 function _status() {230 return status;231 }232 function _completeAnimation() {233 status = 0;234 started = false;235 }236 function _complete() {237 if (!$animate) {238 $animate = $injector.get('$animate');239 }240 $rootScope.$broadcast('cfpLoadingBar:completed');241 _set(1);242 $timeout.cancel(completeTimeout);243 // Attempt to aggregate any start/complete calls within 500ms:244 completeTimeout = $timeout(function() {245 var promise = $animate.leave(loadingBarContainer, _completeAnimation);246 if (promise && promise.then) {247 promise.then(_completeAnimation);248 }249 $animate.leave(spinner);250 }, 500);251 }252 return {253 start : _start,254 set : _set,255 status : _status,256 inc : _inc,257 complete : _complete,258 includeSpinner : this.includeSpinner,259 latencyThreshold : this.latencyThreshold,260 parentSelector : this.parentSelector,261 startSize : this.startSize262 };263 }]; //264 }); // wtf javascript. srsly...

Full Screen

Full Screen

CalculateEngine.js

Source:CalculateEngine.js Github

copy

Full Screen

1import {2 CLEAR_BUTTON_STATES,3 DEFAULT_NUMBER_INPUT,4 DOT_BUTTON_ENUM,5 EQUAL_BUTTON_ENUM,6 OPERATOR_EVAL_MAPPING,7 TOGGLE_BUTTONS8} from "../constants/Defined";9import { MathUtils } from "../utils";10class CalculateEngine {11 constructor() {12 this.number = "";13 this.previousInput = null;14 this.previousNumber = null;15 this.previousOperation = null;16 this.repeatNumber = null;17 this.repeatOperation = null;18 this.clearable = false;19 this.OperationEnum = {20 addition: OPERATOR_EVAL_MAPPING.ADD.value,21 subtraction: OPERATOR_EVAL_MAPPING.SUB.value,22 multiplication: OPERATOR_EVAL_MAPPING.MUL.value,23 division: OPERATOR_EVAL_MAPPING.DIV.value,24 percentage: TOGGLE_BUTTONS.PERCENT.value,25 sign: TOGGLE_BUTTONS.SIGN.value,26 equal: EQUAL_BUTTON_ENUM.value,27 allClear: CLEAR_BUTTON_STATES.ALL_CLEAR.value,28 clear: CLEAR_BUTTON_STATES.CLEAR.value,29 };30 }31 updatePreviousStatus(number, input) {32 this.previousNumber = number;33 this.previousInput = input;34 this.previousOperation = input;35 }36 // Handle and process all digit inputs including .37 handleDigitInput(input) {38 this.clearable = true;39 if (this.isOperation(this.previousInput)) {40 this.number = "";41 }42 if (input === DOT_BUTTON_ENUM.value && this.containDecimalPoint(this.number)) {43 return this.number;44 }45 if (input === DOT_BUTTON_ENUM.value && this.number === "") {46 this.number = "0" + DOT_BUTTON_ENUM.value;47 return this.number;48 }49 this.number += input;50 this.previousInput = input;51 return this.removeZero(this.number);52 }53 // Handle all operation other than digit inputs.54 handleOperationInput(input) {55 if (56 input === this.OperationEnum.addition ||57 input === this.OperationEnum.subtraction ||58 input === this.OperationEnum.multiplication ||59 input === this.OperationEnum.division60 ) {61 return this.handleBasicMathOperation(input);62 }63 if (input === this.OperationEnum.percentage) {64 return this.handlePercentageOperation();65 }66 if (input === this.OperationEnum.sign) {67 return this.handleSignOperation();68 }69 if (input === this.OperationEnum.allClear) {70 return this.handleAllClearOperation();71 }72 if (input === this.OperationEnum.clear) {73 return this.handleClearOperation();74 }75 if (input === this.OperationEnum.equal) {76 return this.handleEqualOperation(input);77 }78 }79 // Only handle basic +, -, /, x operations80 handleBasicMathOperation(input) {81 this.repeatNumber = null;82 this.repeatOperation = null;83 if (this.previousNumber == null) {84 this.updatePreviousStatus(this.number, input);85 return this.number;86 } else {87 let temp = this.previousInput;88 this.previousInput = input;89 if (90 temp !== input &&91 this.previousOperation !== this.OperationEnum.equal &&92 temp !== "="93 ) {94 if (this.previousOperation === this.OperationEnum.addition) {95 this.number = this.add(this.previousNumber, this.number);96 }97 if (this.previousOperation === this.OperationEnum.subtraction) {98 this.number = this.subtract(this.previousNumber, this.number);99 }100 if (this.previousOperation === this.OperationEnum.multiplication) {101 this.number = this.muliply(this.previousNumber, this.number);102 }103 if (this.previousOperation === this.OperationEnum.division) {104 this.number = this.divide(this.previousNumber, this.number);105 }106 this.updatePreviousStatus(this.number, input);107 return this.number;108 } else {109 this.updatePreviousStatus(this.number, input);110 return this.number;111 }112 }113 }114 handlePercentageOperation() {115 if (this.number === "") {116 this.number = DEFAULT_NUMBER_INPUT;117 }118 this.number = this.percentage(this.number);119 return this.number;120 }121 handleSignOperation() {122 if (this.number === "") {123 this.number = DEFAULT_NUMBER_INPUT;124 }125 this.number = this.changeSign(this.number);126 return this.number;127 }128 handleAllClearOperation() {129 return this.allClear();130 }131 handleClearOperation() {132 return this.clear();133 }134 // Paramter operation is one of add, subtract, multiply or divide135 perform(operation) {136 if (this.repeatNumber !== null) {137 this.number = operation(this.number, this.repeatNumber);138 } else {139 this.repeatNumber = this.number;140 this.number = operation(this.previousNumber, this.number);141 }142 }143 handleEqualOperation(input) {144 if (this.previousNumber == null) {145 this.updatePreviousStatus(this.number, input);146 return this.number;147 } else {148 this.previousInput = input;149 if (150 this.previousOperation !== this.OperationEnum.equal &&151 input === this.OperationEnum.equal152 ) {153 let temp = this.number;154 if (this.previousOperation === this.OperationEnum.addition) {155 this.perform(this.add);156 }157 if (this.previousOperation === this.OperationEnum.subtraction) {158 this.perform(this.subtract);159 }160 if (this.previousOperation === this.OperationEnum.multiplication) {161 this.perform(this.muliply);162 }163 if (this.previousOperation === this.OperationEnum.division) {164 this.perform(this.divide);165 }166 this.repeatNumber = temp;167 this.repeatOperation = this.previousOperation;168 this.previousInput = input;169 this.previousOperation = input;170 return this.number;171 } else {172 let temp = this.number;173 if (this.repeatNumber != null) {174 if (this.repeatOperation === this.OperationEnum.addition) {175 this.number = this.add(this.number, this.repeatNumber);176 }177 if (this.repeatOperation === this.OperationEnum.subtraction) {178 this.number = this.subtract(this.number, this.repeatNumber);179 }180 if (this.repeatOperation === this.OperationEnum.multiplication) {181 this.number = this.muliply(this.number, this.repeatNumber);182 }183 if (this.repeatOperation === this.OperationEnum.division) {184 this.number = this.divide(this.number, this.repeatNumber);185 }186 }187 this.updatePreviousStatus(temp, input);188 return this.number;189 }190 }191 }192 calculate(input) {193 if (this.isDigit(input)) {194 return this.handleDigitInput(input);195 }196 if (this.isOperation(input)) {197 return this.handleOperationInput(input);198 }199 return "Error";200 }201 isDigit(input) {202 return !isNaN(input) || input === DOT_BUTTON_ENUM.value;203 }204 isOperation(input) {205 return Object.values(this.OperationEnum).includes(input);206 }207 add(previousNumber, number) {208 return MathUtils.add(parseFloat(previousNumber), parseFloat(number)).toString();209 }210 subtract(previousNumber, number) {211 return MathUtils.subtract(parseFloat(previousNumber), parseFloat(number)).toString();212 }213 muliply(previousNumber, number) {214 return MathUtils.multiply(parseFloat(previousNumber), parseFloat(number)).toString();215 }216 divide(previousNumber, number) {217 return MathUtils.divide(parseFloat(previousNumber), parseFloat(number)).toString();218 }219 percentage(number) {220 return (parseFloat(number) / 100).toString();221 }222 changeSign(number) {223 return parseFloat(number) === 0224 ? DEFAULT_NUMBER_INPUT225 : (parseFloat(number) * -1).toString();226 }227 clear() {228 if (this.isDigit(this.previousInput)) {229 this.number = "";230 } else {231 this.previousOperation = null;232 this.previousNumber = null;233 }234 this.previousInput = null;235 236 this.repeatNumber = null;237 this.repeatOperation = null;238 this.clearable = false;239 return this.number;240 }241 allClear() {242 this.number = "";243 this.previousInput = null;244 this.previousNumber = null;245 this.previousOperation = null;246 this.repeatNumber = null;247 this.repeatOperation = null;248 this.clearable = false;249 return DEFAULT_NUMBER_INPUT;250 }251 removeZero(number) {252 if (number.length > 1 && number[0] === DEFAULT_NUMBER_INPUT && number[1] !== DOT_BUTTON_ENUM.value) {253 return this.removeZero(number.substr(1, number.length));254 }255 return number;256 }257 containDecimalPoint(number) {258 return number.includes(DOT_BUTTON_ENUM.value) || MathUtils.isDecimal(number);259 }260}...

Full Screen

Full Screen

CalculateEngine.test.js

Source:CalculateEngine.test.js Github

copy

Full Screen

1import CalculateEngine from "./CalculateEngine";2test("typing numbers", () => {3 let engine = new CalculateEngine();4 expect(engine.calculate("1")).toBe("1");5 expect(engine.calculate("2")).toBe("12");6});7test("check remove zero", () => {8 let engine = new CalculateEngine();9 expect(engine.removeZero("0")).toBe("0");10 expect(engine.removeZero("01")).toBe("1");11 expect(engine.removeZero("101")).toBe("101");12 expect(engine.removeZero("01010")).toBe("1010");13 expect(engine.removeZero("001010")).toBe("1010");14 expect(engine.removeZero("00001010")).toBe("1010");15});16test("typing numbers starts with zero", () => {17 let engine = new CalculateEngine();18 expect(engine.calculate("0")).toBe("0");19 expect(engine.calculate("1")).toBe("1");20 expect(engine.calculate("2")).toBe("12");21});22test("typing decimal values", () => {23 let engine = new CalculateEngine();24 expect(engine.calculate("1")).toBe("1");25 expect(engine.calculate(".")).toBe("1.");26 expect(engine.calculate("2")).toBe("1.2");27});28test("check containDecimalPoint", () => {29 let engine = new CalculateEngine();30 expect(engine.containDecimalPoint("")).toBe(false);31 expect(engine.containDecimalPoint(".")).toBe(true);32 expect(engine.containDecimalPoint("1.1")).toBe(true);33 expect(engine.containDecimalPoint("1..1")).toBe(true);34});35test("typing decimal values with double decimal", () => {36 let engine = new CalculateEngine();37 expect(engine.calculate("1")).toBe("1");38 expect(engine.calculate(".")).toBe("1.");39 expect(engine.calculate(".")).toBe("1.");40 expect(engine.calculate("2")).toBe("1.2");41});42test("typing decimal values start with zero", () => {43 let engine = new CalculateEngine();44 expect(engine.calculate("0")).toBe("0");45 expect(engine.calculate(".")).toBe("0.");46 expect(engine.calculate("2")).toBe("0.2");47});48test("typing decimal values start with decimal point", () => {49 let engine = new CalculateEngine();50 expect(engine.calculate(".")).toBe("0.");51 expect(engine.calculate("1")).toBe("0.1");52 expect(engine.calculate(".")).toBe("0.1");53 expect(engine.calculate("0")).toBe("0.10");54});55test("addition only using + button", () => {56 let engine = new CalculateEngine();57 expect(engine.calculate("1")).toBe("1");58 expect(engine.calculate("+")).toBe("1");59 expect(engine.calculate("2")).toBe("2");60 expect(engine.calculate("+")).toBe("3");61 expect(engine.calculate("3")).toBe("3");62 expect(engine.calculate("+")).toBe("6");63});64test("addition only using + button with double click +", () => {65 let engine = new CalculateEngine();66 expect(engine.calculate("1")).toBe("1");67 expect(engine.calculate("+")).toBe("1");68 expect(engine.calculate("+")).toBe("1");69 expect(engine.calculate("2")).toBe("2");70 expect(engine.calculate("+")).toBe("3");71 expect(engine.calculate("+")).toBe("3");72 expect(engine.calculate("3")).toBe("3");73 expect(engine.calculate("+")).toBe("6");74});75test("add using equal", () => {76 let engine = new CalculateEngine();77 expect(engine.calculate("1")).toBe("1");78 expect(engine.calculate("+")).toBe("1");79 expect(engine.calculate("2")).toBe("2");80 expect(engine.calculate("=")).toBe("3");81});82test("equal sign behavior", () => {83 let engine = new CalculateEngine();84 expect(engine.calculate("1")).toBe("1");85 expect(engine.calculate("=")).toBe("1");86 expect(engine.calculate("2")).toBe("2");87 expect(engine.calculate("=")).toBe("2");88 expect(engine.calculate("+")).toBe("2");89 expect(engine.calculate("3")).toBe("3");90 expect(engine.calculate("+")).toBe("5");91});92test("equal sign repeat behavior", () => {93 let engine = new CalculateEngine();94 expect(engine.calculate("1")).toBe("1");95 expect(engine.calculate("+")).toBe("1");96 expect(engine.calculate("2")).toBe("2");97 expect(engine.calculate("=")).toBe("3");98 expect(engine.calculate("=")).toBe("5");99 expect(engine.calculate("=")).toBe("7");100});101test("press plus after equal", () => {102 let engine = new CalculateEngine();103 expect(engine.calculate("1")).toBe("1");104 expect(engine.calculate("+")).toBe("1");105 expect(engine.calculate("2")).toBe("2");106 expect(engine.calculate("=")).toBe("3");107 expect(engine.calculate("=")).toBe("5");108 expect(engine.calculate("=")).toBe("7");109 expect(engine.calculate("+")).toBe("7");110});111test("subtract one value from another", () => {112 let engine = new CalculateEngine();113 expect(engine.calculate("5")).toBe("5");114 expect(engine.calculate("-")).toBe("5");115 expect(engine.calculate("2")).toBe("2");116 expect(engine.calculate("=")).toBe("3");117});118test("add then subtract", () => {119 let engine = new CalculateEngine();120 expect(engine.calculate("5")).toBe("5");121 expect(engine.calculate("+")).toBe("5");122 expect(engine.calculate("3")).toBe("3");123 expect(engine.calculate("-")).toBe("8");124 expect(engine.calculate("5")).toBe("5");125 expect(engine.calculate("=")).toBe("3");126});127test("pressing + after =", () => {128 let engine = new CalculateEngine();129 expect(engine.calculate("5")).toBe("5");130 expect(engine.calculate("+")).toBe("5");131 expect(engine.calculate("4")).toBe("4");132 expect(engine.calculate("=")).toBe("9");133 expect(engine.calculate("1")).toBe("1");134 expect(engine.calculate("+")).toBe("1");135});136test("muliply two numbers with muliply", () => {137 let engine = new CalculateEngine();138 expect(engine.calculate("3")).toBe("3");139 expect(engine.calculate(engine.OperationEnum.multiplication)).toBe("3");140 expect(engine.calculate("2")).toBe("2");141 expect(engine.calculate(engine.OperationEnum.multiplication)).toBe("6");142});143test("muliply two numbers with equal", () => {144 let engine = new CalculateEngine();145 expect(engine.calculate("3")).toBe("3");146 expect(engine.calculate(engine.OperationEnum.multiplication)).toBe("3");147 expect(engine.calculate("2")).toBe("2");148 expect(engine.calculate(engine.OperationEnum.equal)).toBe("6");149});150test("divide with symbol", () => {151 let engine = new CalculateEngine();152 expect(engine.calculate("6")).toBe("6");153 expect(engine.calculate(engine.OperationEnum.division)).toBe("6");154 expect(engine.calculate("3")).toBe("3");155 expect(engine.calculate(engine.OperationEnum.division)).toBe("2");156});157test("divide with equal sign", () => {158 let engine = new CalculateEngine();159 expect(engine.calculate("6")).toBe("6");160 expect(engine.calculate(engine.OperationEnum.division)).toBe("6");161 expect(engine.calculate("3")).toBe("3");162 expect(engine.calculate(engine.OperationEnum.equal)).toBe("2");163});164test("presentage", () => {165 let engine = new CalculateEngine();166 expect(engine.calculate(engine.OperationEnum.percentage)).toBe("0");167 expect(engine.calculate("0")).toBe("0");168 expect(engine.calculate(engine.OperationEnum.percentage)).toBe("0");169 expect(engine.calculate("1")).toBe("1");170 expect(engine.calculate(engine.OperationEnum.percentage)).toBe("0.01");171});172test("change sign", () => {173 let engine = new CalculateEngine();174 expect(engine.calculate(engine.OperationEnum.sign)).toBe("0");175 expect(engine.calculate("1")).toBe("1");176 expect(engine.calculate(engine.OperationEnum.sign)).toBe("-1");177 expect(engine.calculate(engine.OperationEnum.sign)).toBe("1");178});179test("all clear", () => {180 let engine = new CalculateEngine();181 expect(engine.calculate(engine.OperationEnum.percentage)).toBe("0");182 expect(engine.calculate(engine.OperationEnum.allClear)).toBe("0");183});184test("clear", () => {185 let engine = new CalculateEngine();186 expect(engine.calculate("1")).toBe("1");187 expect(engine.calculate(engine.OperationEnum.addition)).toBe("1");188 expect(engine.calculate(engine.OperationEnum.clear)).toBe("1");189 expect(engine.calculate(engine.OperationEnum.subtraction)).toBe("1");190 expect(engine.calculate("2")).toBe("2");191 expect(engine.calculate(engine.OperationEnum.equal)).toBe("-1");...

Full Screen

Full Screen

core.client.config.js

Source:core.client.config.js Github

copy

Full Screen

1angular.module('core', ['calculateengine.loadingBar']).run(['$rootScope', '$window', '$location', '$route', '$cookieStore', 'authService', 'globalconfigService',2 function ($rootScope, $window, $location, $route, $cookieStore, authService, globalconfigService) {3 $rootScope.$on('$locationChangeStart', function (event, next, current) {4 var authorize = false;5 if (!angular.isUndefined(($route.routes[$location.path()]))) {6 authorize = ($route.routes[$location.path()]).authorize;7 }8 if (authorize) {9 authService.IsLoggedIn().then(function (response) {10 if (!angular.isUndefined(response) && !angular.isUndefined(response.data) && !response.data.success) {11 //User is not logged in, redirect it to login page.12 var path = $location.path();13 if (path != window.base_dir) {14 $window.location.href = window.base_dir + "#/?loggedout=true";15 }16 }17 });18 }19 });20 $rootScope.Logout = function () {21 $cookieStore.remove('globals');22 }23 //Login pop up ig user is logged out.24 if (!angular.isUndefined($location.search().loggedout)) {25 angular.element('a.popup').trigger('click');26 }27 //Get App name to show in tittle28 globalconfigService.getKeyValue('APP_NAME').then(function (response) {29 if (!angular.isUndefined(response.data)) {30 $rootScope.App = { AppName: response.data, Tittle: '' };31 }32 });33 //Show Alert34 $rootScope.ShowAlert = function (message) {35 $("#dialog-confirm").removeClass('hidden');36 $rootScope.message = message;37 $("#dialog-confirm").dialog({38 resizable: false,39 height: 200,40 width: 400,41 modal: true,42 buttons: {43 Cancel: function () {44 $("#dialog-confirm").addClass('hidden');45 $(this).dialog("close");46 },47 OK: function () {48 $("#dialog-confirm").addClass('hidden');49 $(this).dialog("close");50 }51 }52 });53 };...

Full Screen

Full Screen

03_e-CarFactory.js

Source:03_e-CarFactory.js Github

copy

Full Screen

1function carFactory(carObject){2 let resultCar = {3 model: carObject.model,4 engine: calculateEngine(carObject.power),5 carriage: {6 type: carObject.carriage,7 color: carObject.color8 },9 wheels: calculateWheelsDiameter(carObject.wheelsize)10 };11 return resultCar;12 function calculateWheelsDiameter(wheelSize){13 if (wheelSize % 2 == 0) {14 return Array(4).fill(wheelSize - 1, 0, 4);15 }16 17 return Array(4).fill(wheelSize, 0, 4);18 }19 function calculateEngine(power){20 if (power <= 90) {21 return {22 power: 90,23 volume: 180024 };25 } else if (power > 90 && power <= 120) {26 return {27 power: 120,28 volume: 240029 };30 } else if (power > 120 && power <= 200) {31 return {32 power: 200,33 volume: 3500...

Full Screen

Full Screen

Calculator.js

Source:Calculator.js Github

copy

Full Screen

1import React, { useCallback, useEffect, useState } from 'react'2import { Wrapper } from '../../components/elements'3import CalculateEngine from '../../models/CalculateEngine'4import Keyboard from '../Keyboard'5import Result from '../Result'6import './Calculator.css'7const Calculator = () => {8 const [display, setDisplay] = useState('0');9 const [engine, setEngine] = useState(new CalculateEngine());10 const [clearable, setClearable] = useState(engine.clearable);11 const handleButtonClick = useCallback((value) => {12 setDisplay(engine.calculate(value));13 setClearable(engine.clearable)14 }, [engine])15 useEffect(() => {16 setDisplay('0')17 setEngine(new CalculateEngine());18 }, [])19 return (20 <Wrapper className="calculator" data-testid="calculator">21 <Result value={display} />22 <Keyboard calculateEngine={engine} clearable={clearable} onButtonClick={handleButtonClick} />23 </Wrapper>24 )25}...

Full Screen

Full Screen

core.client.module.js

Source:core.client.module.js Github

copy

Full Screen

1// Use Applicaion configuration module to register a new module2ApplicationConfiguration.registerModule('core');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});7import { Selector } from 'testcafe';8test('My first test', async t => {9 .typeText('#developer-name', 'John Smith')10 .click('#submit-button')11 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');12});13import { Selector } from 'testcafe';14test('My first test', async t => {15 .typeText('#developer-name', 'John Smith')16 .click('#submit-button')17 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');18});19import { Selector } from 'testcafe';20test('My first test', async t => {21 .typeText('#developer-name', 'John Smith')22 .click('#submit-button')23 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');24});25import { Selector } from 'testcafe';26test('My first test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button')29 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');30});31import { Selector } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .click('#tried-test-cafe');6});7test('My second test', async t => {8 .typeText('#developer-name', 'John Smith')9 .click('#submit-button')10 .click('#tried-test-cafe');11});12test('My third test', async t => {13 .typeText('#developer-name', 'John Smith')14 .click('#submit-button')15 .click('#tried-test-cafe');16});17test('My fourth test', async t => {18 .typeText('#developer-name', 'John Smith')19 .click('#submit-button')20 .click('#tried-test-cafe');21});22test('My fifth test', async t => {23 .typeText('#developer-name', 'John Smith')24 .click('#submit-button')25 .click('#tried-test-cafe');26});27test('My sixth test', async t => {28 .typeText('#developer-name', 'John Smith')29 .click('#submit-button')30 .click('#tried-test-cafe');31});32test('My seventh test', async t => {33 .typeText('#developer-name', 'John Smith')34 .click('#submit-button')35 .click('#tried-test-cafe');36});37test('My eighth test', async t => {38 .typeText('#developer-name', 'John Smith')39 .click('#submit-button')40 .click('#tried-test-cafe');41});42test('My ninth test', async t => {43 .typeText('#developer-name', 'John Smith')44 .click('#submit-button')45 .click('#tried-test-cafe');46});47test('My tenth test', async t => {48 .typeText('#developer-name', 'John Smith')49 .click('#submit-button')50 .click('#tried-test-cafe');51});52test('My eleventh test', async t => {53 .typeText('#developer-name', 'John Smith')

Full Screen

Using AI Code Generation

copy

Full Screen

1const TestcafeEngine = require('testcafe-engine');2const testcafeEngine = new TestcafeEngine();3testcafeEngine.calculateEngine();4class TestcafeEngine {5 calculateEngine() {6 console.log('calculateEngine method called');7 }8}9module.exports = TestcafeEngine;10class TestcafeEngine {11 calculateEngine() {12 console.log('calculateEngine method called');13 }14}15module.exports = TestcafeEngine;16class TestcafeEngine {17 calculateEngine() {18 console.log('calculateEngine method called');19 }20}21module.exports = TestcafeEngine;22class TestcafeEngine {23 calculateEngine() {24 console.log('calculateEngine method called');25 }26}27module.exports = TestcafeEngine;28class TestcafeEngine {29 calculateEngine() {30 console.log('calculateEngine method called');31 }32}33module.exports = TestcafeEngine;34class TestcafeEngine {35 calculateEngine() {36 console.log('calculateEngine method called');37 }38}39module.exports = TestcafeEngine;40class TestcafeEngine {41 calculateEngine() {42 console.log('calculateEngine method called');43 }44}45module.exports = TestcafeEngine;46class TestcafeEngine {47 calculateEngine() {48 console.log('calculateEngine method called');49 }50}51module.exports = TestcafeEngine;52class TestcafeEngine {53 calculateEngine() {54 console.log('calculateEngine method called

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2fixture('Testcafe')3test('Testcafe', async t => {4 .typeText('#lst-ib', 'Testcafe')5 .click('#tsbb')6 .click('#rso > div:nth-child(1) > div > div:nth-child(1) > div > div > h3 > a')7 .click('#main > div > div > div > div:nth-child

Full Screen

Using AI Code Generation

copy

Full Screen

1var TestcafeEngine = require('testcafe-engine');2var testcafeEngine = new TestcafeEngine();3testcafeEngine.calculateEngine('test.js', function(err, result) {4 if(err) {5 console.log(err);6 } else {7 console.log(result);8 }9});10var MochaEngine = require('mocha-engine');11var mochaEngine = new MochaEngine();12mochaEngine.calculateEngine('test.js', function(err, result) {13 if(err) {14 console.log(err);15 } else {16 console.log(result);17 }18});19var JasmineEngine = require('jasmine-engine');20var jasmineEngine = new JasmineEngine();21jasmineEngine.calculateEngine('test.js', function(err, result) {22 if(err) {23 console.log(err);24 } else {25 console.log(result);26 }27});28var QUnitEngine = require('qunit-engine');29var qunitEngine = new QUnitEngine();30qunitEngine.calculateEngine('test.js', function(err, result) {31 if(err) {32 console.log(err);33 } else {34 console.log(result);35 }36});37var ProtractorEngine = require('protractor-engine');38var protractorEngine = new ProtractorEngine();39protractorEngine.calculateEngine('test.js', function(err, result) {40 if(err) {41 console.log(err);42 } else {43 console.log(result);44 }45});46var NightwatchEngine = require('nightwatch-engine');47var nightwatchEngine = new NightwatchEngine();48nightwatchEngine.calculateEngine('test.js', function(err, result) {49 if(err) {50 console.log(err);51 } else {52 console.log(result);53 }54});55var CucumberEngine = require('cucumber-engine');56var cucumberEngine = new CucumberEngine();57cucumberEngine.calculateEngine('test.js', function(err, result) {58 if(err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const testCafe = require('testcafe');2const TestCafeEngine = require('./TestcafeEngine.js');3var testCafeEngine = new TestCafeEngine();4testCafeEngine.calculateEngine(2,3);5function calculateEngine(a,b){6 console.log(a+b);7}8module.exports = calculateEngine;9class Test {10 constructor() {11 this._test = 'test';12 }13 get test() {14 return this._test;15 }16 set test(value) {17 this._test = value;18 }19}20function test() {21 const test = new Test();22 test.test = 'test2';23 console.log(test.test);24}25test();26const mongoose = require('mongoose');27const userSchema = new mongoose.Schema({28});29const User = mongoose.model('User', userSchema);30const user = new User({

Full Screen

Using AI Code Generation

copy

Full Screen

1const testcafeEngine = require('./TestcafeEngine');2testcafeEngine.calculateEngine(1, 2);3class TestcafeEngine {4 calculateEngine(a, b) {5 console.log(a + b);6 }7}8module.exports = new TestcafeEngine();9{10 "scripts": {11 },12 "dependencies": {13 }14}

Full Screen

Using AI Code Generation

copy

Full Screen

1var Testcafe = require('testcafe');2var testcafe = new Testcafe();3 .createRunner()4 .src('test.js')5 .browsers('chrome')6 .run()7 .then(function (failedCount) {8 testcafe.close();9 });

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

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

Run Testcafe 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