How to use testHistory method in qawolf

Best JavaScript code snippet using qawolf

test.directive.js

Source:test.directive.js Github

copy

Full Screen

1(function() {2 'use strict';3 /**4 * @name eolinker open source,eolinker开源版本5 * @link https://www.eolinker.com6 * @package eolinker7 * @author www.eolinker.com 广州银云信息科技有限公司 2015-20188 * eolinker,业内领先的Api接口管理及测试平台,为您提供最专业便捷的在线接口管理、测试、维护以及各类性能测试方案,帮助您高效开发、安全协作。9 * 如在使用的过程中有任何问题,可通过[图片]http://help.eolinker.com寻求帮助10 *11 * 注意!eolinker开源版本遵循GPL V3开源协议,仅供用户下载试用,禁止“一切公开使用于商业用途”或者“以eoLinker开源版本为基础而开发的二次版本”在互联网上流通。12 * 注意!一经发现,我们将立刻启用法律程序进行维权。13 * 再次感谢您的使用,希望我们能够共同维护国内的互联网开源文明和正常商业秩序。14 *15 * @function [测试指令js] [Test instructions js]16 * @version 3.1.517 * @service $filter [注入过滤器服务] [Inject filter service]18 * @service $timeout [注入$timeout服务] [Inject filter service]19 * @service $rootScope [注入根作用域服务] [Inject rootScope service]20 * @service ApiManagementResource [注入接口管理接口服务] [inject ApiManagement API service]21 * @constant CODE [注入状态码常量] [inject status code constant service]22 * @param version [版本:0个人 1企业] [Version: 0 Personal 1 Business]23 * @param auth [验证类型] [Authentication type]24 * @param json [转json参数] [Turn json parameters]25 * @param message [值可能性object类集(可选)] [Value Possibility object Class Set (optional)]26 * @param result [双向绑定测试后返回结果] [Return the result after bidirectional binding test]27 * @param detail [双向绑定测试初始化getApi内容] [Bidirectional binding test initializes getApi content]28 * @param format [双向绑定格式整理内容] [Two-way binding format]29 * @param testForm [双向绑定基本表单信息是否填写完整] [Bind the basic form information is complete]30 * @param info [双向绑定基本的路由信息] [Bind the basic routing information]31 * @param isPlug [双向绑定是否为插件(用于对界面有无插件的差异性显示)] [Whether the two-way binding for the plug-in (for the interface with or without plug-in differences show)]32 * @param envParam [环境变量全局参数数组] [Environment variable global parameter array]33 */34 angular.module('eolinker.directive')35 .directive('testDirective', ['$window', '$filter', '$timeout', '$rootScope', 'ApiManagementResource', 'CODE', function($window, $filter, $timeout, $rootScope, ApiManagementResource, CODE) {36 return {37 restrict: 'A',38 transclude: true,39 replace: true,40 template: '<div>' + '<button class="eo-button-info " data-ng-click="test()" >' + ' <span class="iconfont icon-fasong" ng-class="{\'hidden\':send.disable}"></span> {{send.disable?data.info.stop&nbsp;+(send.countdown>0?send.countdown:""):data.info.send}}' + '</button>' + '<div class="hidden" id="plug-in-result-js"></div>' + '<div class="hidden" id="plug-in-js">{"method":{{detail.baseInfo.type}},"requestInfo":{{message}},"env":{{envParam}},"formDataToJson":{"checkbox":{{json.checkbox}},"raw":{{message.params|paramLevelToJsonFilter}}},"auth":{{auth}},"script":{{script}}}</div>' + '</div>',41 scope: {42 version: '@',43 auth: '=',44 json: '=',45 message: '=',46 result: '=',47 detail: '=',48 format: '=',49 testForm: '=',50 info: '=',51 isPlug: '=',52 envParam: '=',53 addHistory: '&',54 script:'<'55 },56 link: function($scope, elem, attrs, ctrl) {57 var countdown = null;58 var templateCountdown = null;59 var timer = null;60 $scope.send = {61 countdown: '',62 disable: false63 }64 $scope.data = {65 info: {66 stop: $filter('translate')('350'),67 send: $filter('translate')('351'),68 },69 }70 var data = {71 fun: {72 restfulSet: null73 }74 }75 /**76 * @function [环境变量全局参数重构功能函数] [Global Parameter Reconstruction of Environment Variables]77 * @param {[obj]} origin [原始值 Original value]78 * @return {[obj]} [重构后的值 Reconstructed value]79 */80 var envSet = function(origin) {81 if ($scope.envParam.length > 0) {82 var templateResult = {};83 angular.copy(origin, templateResult);84 angular.forEach($scope.envParam, function(val, key) {85 templateResult.URL = templateResult.URL.replace(eval('/({{' + val.paramKey + '}})/g'), val.paramValue);86 angular.forEach(templateResult.headers, function(childVal, childKey) {87 childVal.headerValue = childVal.headerValue.replace(eval('/({{' + val.paramKey + '}})/g'), val.paramValue);88 childVal.headerName = childVal.headerName.replace(eval('/({{' + val.paramKey + '}})/g'), val.paramValue);89 })90 angular.forEach(templateResult.params, function(childVal, childKey) {91 childVal.paramKey = childVal.paramKey.replace(eval('/({{' + val.paramKey + '}})/g'), val.paramValue);92 childVal.paramInfo = (childVal.paramInfo || '').replace(eval('/({{' + val.paramKey + '}})/g'), val.paramValue);93 })94 })95 return templateResult;96 } else {97 return origin;98 }99 }100 /**101 * @function [显示测试结果调用功能函数] [Show test result call]102 * @param {[obj]} testHistory [测试历史] [Test history]103 * @param {[obj]} data [测试数据] [Test Data]104 */105 var showTestResult = function(testHistory, data) {106 if ($scope.send.disable) {107 if (data.statusCode == CODE.COMMON.SUCCESS) {108 $scope.result = {109 menuType:'body',110 testHttpCode: data.testHttpCode,111 testDeny: data.testDeny,112 testResult: data.testResult,113 httpCodeType: data.testHttpCode >= 100 && data.testHttpCode < 200 ? 1 : data.testHttpCode >= 200 && data.testHttpCode < 300 ? 2 : data.testHttpCode >= 300 && data.testHttpCode < 400 ? 3 : 4114 };115 var result = $scope.result.testResult.body;116 testHistory.resultInfo = {117 headers: data.testResult.headers,118 body: data.testResult.body,119 httpCode: data.testHttpCode,120 testDeny: data.testDeny121 };122 testHistory.testID = data.testID;123 testHistory.httpCodeType = data.testHttpCode >= 100 && data.testHttpCode < 200 ? 1 : data.testHttpCode >= 200 && data.testHttpCode < 300 ? 2 : data.testHttpCode >= 300 && data.testHttpCode < 400 ? 3 : 4;124 var array = [];125 array.push(testHistory);126 $scope.detail.testHistory = array.concat($scope.detail.testHistory);127 $scope.format.message = result;128 } else {129 $scope.result = {130 httpCodeType: 5,131 menuType:'body'132 };133 $scope.format.message = '';134 }135 $scope.result.hadTest = true;136 clearInterval(countdown);137 $scope.send.countdown = null;138 $scope.send.disable = false;139 }140 }141 /**142 * @function [插件测试调用功能函数] [The plugin test calls the function function]143 * @param {[obj]} testHistory [测试历史 Test history]144 */145 var plugTest = function(testHistory) {146 var data = {};147 var template = {148 img: {149 html: ''150 }151 }152 try {153 data = JSON.parse($filter('HtmlFilter')(document.getElementById('plug-in-result-js').innerText));154 } catch (e) {155 data = {156 statusCode: '2xxxxx'157 }158 }159 if (data.statusCode == CODE.COMMON.SUCCESS) {160 $scope.result = {161 menuType:'body',162 testHttpCode: data.testHttpCode,163 testDeny: data.testDeny,164 testResult: data.testResult,165 httpCodeType: data.testHttpCode >= 100 && data.testHttpCode < 200 ? 1 : data.testHttpCode >= 200 && data.testHttpCode < 300 ? 2 : data.testHttpCode >= 300 && data.testHttpCode < 400 ? 3 : 4166 };167 if (/image\/(jpg|jpeg|png|gif)/ig.test(JSON.stringify(data.testResult.headers))) {168 template.img.html = '<img style="max-width:100%;" author="eolinker-frontend" src="' + data.testResult.body + '"/>';169 }170 var result = $scope.result.testResult.body;171 testHistory.resultInfo = {172 headers: data.testResult.headers,173 body: template.img.html || ((typeof result == 'object') ? angular.toJson(data.testResult.body) : data.testResult.body),174 httpCode: data.testHttpCode,175 testDeny: data.testDeny176 };177 testHistory.testID = data.testID;178 testHistory.httpCodeType = data.testHttpCode >= 100 && data.testHttpCode < 200 ? 1 : data.testHttpCode >= 200 && data.testHttpCode < 300 ? 2 : data.testHttpCode >= 300 && data.testHttpCode < 400 ? 3 : 4;179 var array = [];180 array.push(testHistory);181 $scope.detail.testHistory = array.concat($scope.detail.testHistory);182 if (typeof result == 'object') {183 $scope.format.message = angular.toJson(result);184 } else {185 $scope.format.message = template.img.html || result;186 }187 $scope.addHistory({188 arg: {189 history: testHistory190 }191 });192 } else {193 $scope.result = {194 menuType:'body',195 httpCodeType: 5196 };197 if (data.errorText) {198 $scope.format.message = data.errorText;199 } else {200 $scope.format.message = '';201 }202 }203 $scope.result.hadTest = true;204 clearInterval(templateCountdown);205 clearInterval(countdown);206 $scope.send.countdown = null;207 $scope.send.disable = false;208 $scope.$apply();209 }210 /**211 * @function [服务器测试调用功能函数] [Server test call]212 */213 var serverTest = function() {214 var template = {215 env: envSet($scope.message),216 restfulObject: {217 hadFilterParams: []218 }219 }220 if (!$scope.send.disable) {221 var info = {222 apiProtocol: $scope.message.httpHeader,223 URL: $scope.message.URL,224 headers: {},225 params: {},226 }227 if (/(http:\/\/)/.test(info.URL.substring(0, 7))) {228 info.URL = info.URL.substring(7);229 } else if (/(https:\/\/)/.test(info.URL.substring(0, 8))) {230 info.URL = info.URL.substring(8);231 }232 info = envSet(info);233 var testHistory = {234 requestInfo: {235 apiProtocol: info.apiProtocol,236 URL: info.URL,237 headers: [],238 params: [],239 method: $scope.detail.baseInfo.type == '0' ? 'POST' : $scope.detail.baseInfo.type == '1' ? 'GET' : $scope.detail.baseInfo.type == '2' ? 'PUT' : $scope.detail.baseInfo.type == '3' ? 'DELETE' : $scope.detail.baseInfo.type == '4' ? 'HEAD' : $scope.detail.baseInfo.type == '5' ? 'OPTIONS' : 'PATCH',240 methodType: $scope.detail.baseInfo.type,241 requestType: ($scope.json.checkbox && $scope.message.requestType != '1' && /0|2|6/.test($scope.detail.baseInfo.type)) ? 1 : $scope.message.requestType242 }243 };244 if ($scope.testForm.$valid) {245 angular.forEach(template.env.headers, function(val, key) {246 if (val.checkbox) {247 if (!!val.headerName) {248 info.headers[val.headerName] = val.headerValue;249 var history = {250 name: val.headerName,251 value: val.headerValue252 }253 testHistory.requestInfo.headers.push(history);254 }255 }256 });257 switch ($scope.auth.status) {258 case '1':259 {260 info.headers['Authorization'] = $filter('base64Filter')($scope.auth.basicAuth.username + ':' + $scope.auth.basicAuth.password);261 testHistory.requestInfo.headers.push({262 name: 'Authorization',263 value: $filter('base64Filter')($scope.auth.basicAuth.username + ':' + $scope.auth.basicAuth.password)264 });265 break;266 }267 }268 switch ($scope.message.requestType) {269 case '0':270 {271 if ($scope.json.checkbox && /0|2|6/.test($scope.detail.baseInfo.type)) {272 info.params = testHistory.requestInfo.params = $filter('paramLevelToJsonFilter')(template.env.params);273 } else {274 angular.forEach(template.env.params, function(val, key) {275 if (val.checkbox) {276 if (!!val.paramKey) {277 info.params[val.paramKey] = val.paramInfo;278 var history = {279 key: val.paramKey,280 value: val.paramInfo281 }282 testHistory.requestInfo.params.push(history);283 }284 }285 });286 info.params = angular.toJson(info.params);287 }288 break;289 }290 case '1':291 {292 info.params = testHistory.requestInfo.params = $scope.message.raw;293 break;294 }295 case '2':296 {297 angular.forEach(template.env.params, function(val, key) {298 if (val.checkbox) {299 if (val.paramKey) {300 if (info.URL.trim().indexOf('{' + val.paramKey + '}') > -1) {301 info.URL = info.URL.replace(eval('/(\\\{' + val.paramKey + '\\\})/g'), val.paramInfo);302 } else {303 template.restfulObject.hadFilterParams.push(val);304 info.params[val.paramKey] = val.paramInfo;305 var history = {306 key: val.paramKey,307 value: val.paramInfo308 }309 testHistory.requestInfo.params.push(history);310 }311 }312 }313 });314 if ($scope.json.checkbox && /0|2|6/.test($scope.detail.baseInfo.type)) {315 info.params = testHistory.requestInfo.params = $filter('paramLevelToJsonFilter')(template.restfulObject.hadFilterParams);316 } else {317 info.params = angular.toJson(info.params);318 }319 testHistory.requestInfo.URL = info.URL;320 break;321 }322 }323 var message = {324 apiProtocol: info.apiProtocol,325 URL: info.URL,326 headers: angular.toJson(info.headers),327 params: info.params,328 apiID: $scope.info.apiID,329 projectID: $scope.info.projectID,330 requestType: testHistory.requestInfo.requestType331 }332 var type = $scope.detail.baseInfo.type;333 testHistory.testTime = $filter('currentTimeFilter')();334 var result = {};335 $scope.send.countdown = 0;336 $scope.send.disable = true;337 countdown = setInterval(function() {338 $scope.send.countdown++;339 $scope.$digest(); // 通知视图模型的变化 Notification changes to the view model340 }, 1000);341 switch ($scope.detail.baseInfo.type) {342 case '0':343 ApiManagementResource.Test.Post(message).$promise.then(function(data) {344 showTestResult(testHistory, data);345 })346 break;347 case '1':348 ApiManagementResource.Test.Get(message).$promise.then(function(data) {349 showTestResult(testHistory, data);350 })351 break;352 case '2':353 ApiManagementResource.Test.Put(message).$promise.then(function(data) {354 showTestResult(testHistory, data);355 })356 break;357 case '3':358 ApiManagementResource.Test.Delete(message).$promise.then(function(data) {359 showTestResult(testHistory, data);360 })361 break;362 case '4':363 ApiManagementResource.Test.Head(message).$promise.then(function(data) {364 showTestResult(testHistory, data);365 })366 break;367 case '5':368 ApiManagementResource.Test.Options(message).$promise.then(function(data) {369 showTestResult(testHistory, data);370 })371 break;372 case '6':373 ApiManagementResource.Test.Patch(message).$promise.then(function(data) {374 showTestResult(testHistory, data);375 })376 break;377 }378 }379 } else {380 clearInterval(countdown);381 $scope.send.countdown = null;382 $scope.send.disable = false;383 }384 }385 /**386 * @function [绑定click,执行测试功能函数] [Bind the click, perform the test]387 */388 $scope.test = function() {389 var template = {390 env: envSet($scope.message),391 modal: {392 html: ''393 },394 restfulObject: {395 hadFilterParams: []396 }397 }398 if (!$scope.send.disable) {399 if ($window.plug && $window.plug.type == "application/eolinker") {400 document.getElementById('plug-in-result-js').innerText = '';401 var info = {402 apiProtocol: $scope.message.httpHeader,403 URL: $scope.message.URL,404 headers: {},405 params: {},406 }407 if (/(http:\/\/)/.test(info.URL.substring(0, 7))) {408 info.URL = info.URL.substring(7);409 } else if (/(https:\/\/)/.test(info.URL.substring(0, 8))) {410 info.URL = info.URL.substring(8);411 }412 var testHistory = {413 requestInfo: {414 apiProtocol: info.apiProtocol,415 URL: template.env.URL,416 headers: [],417 params: [],418 method: $scope.detail.baseInfo.type == '0' ? 'POST' : $scope.detail.baseInfo.type == '1' ? 'GET' : $scope.detail.baseInfo.type == '2' ? 'PUT' : $scope.detail.baseInfo.type == '3' ? 'DELETE' : $scope.detail.baseInfo.type == '4' ? 'HEAD' : $scope.detail.baseInfo.type == '5' ? 'OPTIONS' : 'PATCH',419 methodType: $scope.detail.baseInfo.type,420 requestType: ($scope.json.checkbox && $scope.message.requestType != '1' && /0|2|6/.test($scope.detail.baseInfo.type)) ? 1 : $scope.message.requestType421 }422 };423 if ($scope.testForm.$valid) {424 angular.forEach(template.env.headers, function(val, key) {425 if (val.checkbox) {426 if (!!val.headerName) {427 info.headers[val.headerName] = val.headerValue;428 var history = {429 name: val.headerName,430 value: val.headerValue431 }432 testHistory.requestInfo.headers.push(history);433 }434 }435 });436 switch ($scope.auth.status) {437 case '1':438 {439 testHistory.requestInfo.headers.push({440 name: 'Authorization',441 value: $filter('base64Filter')($scope.auth.basicAuth.username + ':' + $scope.auth.basicAuth.password)442 });443 break;444 }445 }446 switch ($scope.message.requestType) {447 case '0':448 {449 if ($scope.json.checkbox && /0|2|6/.test($scope.detail.baseInfo.type)) {450 testHistory.requestInfo.params = $filter('paramLevelToJsonFilter')(template.env.params);451 } else {452 angular.forEach(template.env.params, function(val, key) {453 if (val.checkbox) {454 if (!!val.paramKey) {455 var history = {456 key: val.paramKey,457 value: val.paramInfo458 }459 testHistory.requestInfo.params.push(history);460 }461 }462 });463 }464 break;465 }466 case '1':467 {468 testHistory.requestInfo.params = $scope.message.raw;469 break;470 }471 case '2':472 {473 angular.forEach(template.env.params, function(val, key) {474 if (val.checkbox) {475 if (val.paramKey) {476 if (info.URL.trim().indexOf('{' + val.paramKey + '}') > -1) {477 info.URL = info.URL.replace(eval('/(\\\{' + val.paramKey + '\\\})/g'), val.paramInfo);478 } else {479 template.restfulObject.hadFilterParams.push(val);480 var history = {481 key: val.paramKey,482 value: val.paramInfo483 }484 testHistory.requestInfo.params.push(history);485 }486 }487 }488 });489 if ($scope.json.checkbox && /0|2|6/.test($scope.detail.baseInfo.type)) {490 testHistory.requestInfo.params = $filter('paramLevelToJsonFilter')(template.restfulObject.hadFilterParams);491 }492 testHistory.requestInfo.URL = info.URL;493 break;494 }495 }496 var type = $scope.detail.baseInfo.type;497 testHistory.testTime = $filter('currentTimeFilter')();498 var result = {};499 $scope.send.countdown = 0;500 $scope.send.disable = true;501 templateCountdown = setInterval(function() {502 if (!!document.getElementById('plug-in-result-js').innerText) {503 plugTest(testHistory);504 }505 }, 10);506 countdown = setInterval(function() {507 $scope.send.countdown++;508 $scope.$digest(); // 通知视图模型的变化509 if ($scope.send.countdown == 60) {510 $scope.result = {511 httpCodeType: 5,512 menuType:'body'513 };514 $scope.format.message = '';515 $scope.isJson = false;516 $scope.result.hadTest = true;517 clearInterval(countdown);518 clearInterval(templateCountdown);519 $scope.send.countdown = null;520 $scope.send.disable = false;521 $scope.$digest();522 }523 }, 1000);524 }525 } else {526 serverTest();527 }528 } else {529 clearInterval(templateCountdown);530 clearInterval(countdown);531 $scope.send.countdown = null;532 $scope.send.disable = false;533 }534 }535 /**536 * @function [销毁页面时销毁计时器] [Destroy the timer when the page is destroyed]537 */538 $scope.$on('$destroy', function() {539 if (timer) {540 $timeout.cancel(timer);541 }542 });543 /**544 * @function [路由开始转换时清除计时器] [The timer clears the timer when the route starts to transition]545 */546 $scope.$on('$stateChangeStart', function() {547 if (!!templateCountdown) {548 clearInterval(templateCountdown);549 }550 if (!!countdown) {551 clearInterval(countdown);552 }553 })554 }555 };556 }]);...

Full Screen

Full Screen

inMemory.spec.ts

Source:inMemory.spec.ts Github

copy

Full Screen

1import "jest";2import { inMemory } from "../src";3import {4 navigateSuite,5 goSuite,6 cancelSuite,7 confirmationSuite8} from "../../../tests/cases";9import { TestCase, Suite } from "../../../tests/types";10import { InMemoryOptions, HistoryConstructor } from "@hickory/in-memory";11interface FnOptions {12 constructor: HistoryConstructor<InMemoryOptions>;13 options: InMemoryOptions;14}15interface AsyncFnOptions extends FnOptions {16 resolve: (value?: {} | PromiseLike<{}>) => void;17}18function runAsyncTest(test: TestCase) {19 it(test.msg, async () => {20 expect.assertions(test.assertions);21 await new Promise(resolve => {22 test.fn({23 constructor: inMemory,24 options: {25 locations: [{ url: "/one" }]26 },27 resolve28 } as AsyncFnOptions);29 });30 });31}32function runTest(test: TestCase) {33 it(test.msg, () => {34 test.fn({35 constructor: inMemory,36 options: {37 locations: [{ url: "/one" }]38 }39 } as FnOptions);40 });41}42function runSuite(suite: Suite) {43 suite.forEach(test => {44 if (test.async) {45 runAsyncTest(test);46 } else {47 runTest(test);48 }49 });50}51describe("Memory constructor", () => {52 it("initializes with root location (/) if none provided", () => {53 let testHistory = inMemory(pending => {54 pending.finish();55 });56 expect(testHistory.location).toMatchObject({57 pathname: "/",58 hash: "",59 query: ""60 });61 });62 it("creates locations from url strings", () => {63 let testHistory = inMemory(64 pending => {65 pending.finish();66 },67 {68 locations: [{ url: "/one#step" }]69 }70 );71 expect(testHistory.location).toMatchObject({72 pathname: "/one",73 hash: "step"74 });75 });76 it("uses the provided index to select initial location", () => {77 let testHistory = inMemory(78 pending => {79 pending.finish();80 },81 {82 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }],83 index: 284 }85 );86 expect(testHistory.location).toMatchObject({87 pathname: "/three"88 });89 });90 it("defaults to index 0 if provided index is out of bounds", () => {91 [-1, 3].forEach(value => {92 let testHistory = inMemory(93 pending => {94 pending.finish();95 },96 {97 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }],98 index: value99 }100 );101 expect(testHistory.location).toMatchObject({102 pathname: "/one"103 });104 });105 });106 it('sets initial action to "push"', () => {107 let testHistory = inMemory(108 pending => {109 expect(pending.action).toBe("push");110 pending.finish();111 },112 {113 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }],114 index: 0115 }116 );117 });118});119describe("cancel", () => {120 runSuite(cancelSuite);121});122describe("navigate()", () => {123 runSuite(navigateSuite);124});125describe("go suite", () => {126 runSuite(goSuite);127});128describe("confirmation suite", () => {129 runSuite(confirmationSuite);130});131describe("go", () => {132 describe("with no value", () => {133 it('calls response handler with current location and "pop" action', done => {134 let testHistory = inMemory(pending => {135 expect(pending.location).toMatchObject({136 pathname: "/"137 });138 expect(pending.action).toBe("pop");139 done();140 pending.finish();141 });142 testHistory.go();143 });144 });145 describe("with a value", () => {146 it("does nothing if the value is outside of the range", () => {147 let router = jest.fn();148 let testHistory = inMemory(router);149 testHistory.go(10);150 // just verifying that a popstate event hasn't emitted to151 // trigger the history's event handler152 expect(router.mock.calls.length).toBe(0);153 });154 });155});156describe("url", () => {157 it("returns the location formatted as a string", () => {158 let testHistory = inMemory(159 pending => {160 pending.finish();161 },162 {163 locations: [{ url: "/one?test=query" }]164 }165 );166 let currentPath = testHistory.url(testHistory.location);167 expect(currentPath).toBe("/one?test=query");168 });169});170describe("reset()", () => {171 describe("locations", () => {172 it("creates locations from url strings", () => {173 let testHistory = inMemory(174 pending => {175 pending.finish();176 },177 {178 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }]179 }180 );181 expect(testHistory.location).toMatchObject({182 pathname: "/one"183 });184 testHistory.reset({185 locations: [{ url: "/uno" }, { url: "/dos" }]186 });187 expect(testHistory.location).toMatchObject({188 pathname: "/uno"189 });190 });191 it("uses default '/' location if no locations are provided", () => {192 let testHistory = inMemory(193 pending => {194 pending.finish();195 },196 {197 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }]198 }199 );200 expect(testHistory.location).toMatchObject({201 pathname: "/one"202 });203 testHistory.reset();204 expect(testHistory.location).toMatchObject({205 pathname: "/"206 });207 });208 it("reset removes existing locations", () => {209 let router = jest.fn();210 let testHistory = inMemory(router, {211 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }]212 });213 // reset the call from attaching the router214 router.mockReset();215 testHistory.go(2);216 // response handler is called because we can pop217 expect(router.mock.calls.length).toBe(1);218 testHistory.reset({ locations: [{ url: "/uno" }] });219 router.mockReset();220 testHistory.go(2);221 // response handler is not called because there is no location222 // to pop to223 expect(router.mock.calls.length).toBe(0);224 });225 });226 it("sets location using provided index value", () => {227 let testHistory = inMemory(228 pending => {229 pending.finish();230 },231 {232 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }],233 index: 1234 }235 );236 expect(testHistory.location.pathname).toBe("/two");237 testHistory.reset({238 locations: [{ url: "/uno" }, { url: "/dos" }, { url: "/tres" }],239 index: 2240 });241 expect(testHistory.location.pathname).toBe("/tres");242 });243 it("uses location at index 0 if index is not provided", () => {244 let testHistory = inMemory(245 pending => {246 pending.finish();247 },248 {249 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }],250 index: 1251 }252 );253 expect(testHistory.location.pathname).toBe("/two");254 testHistory.reset({255 locations: [{ url: "/uno" }, { url: "/dos" }, { url: "/tres" }]256 });257 expect(testHistory.location.pathname).toBe("/uno");258 });259 it("uses location at index 0 if provided index < 0", () => {260 let testHistory = inMemory(261 pending => {262 pending.finish();263 },264 {265 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }],266 index: 1267 }268 );269 expect(testHistory.location.pathname).toBe("/two");270 testHistory.reset({271 locations: [{ url: "/uno" }, { url: "/dos" }, { url: "/tres" }],272 index: -1273 });274 expect(testHistory.location.pathname).toBe("/uno");275 });276 it("uses location at index 0 if index is larger than length of locations array", () => {277 let testHistory = inMemory(278 pending => {279 pending.finish();280 },281 {282 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }],283 index: 1284 }285 );286 expect(testHistory.location.pathname).toBe("/two");287 testHistory.reset({288 locations: [{ url: "/uno" }, { url: "/dos" }, { url: "/tres" }],289 index: 7290 });291 expect(testHistory.location.pathname).toBe("/uno");292 });293 describe("emitting new location", () => {294 it("emits the new location", () => {295 let router = jest.fn();296 let testHistory = inMemory(router, {297 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }]298 });299 testHistory.reset({300 locations: [{ url: "/uno" }, { url: "/dos" }]301 });302 expect(router.mock.calls.length).toBe(1);303 expect(router.mock.calls[0][0]).toMatchObject({304 location: {305 pathname: "/uno"306 }307 });308 });309 it('emits the action as "push"', () => {310 let router = jest.fn();311 let testHistory = inMemory(router, {312 locations: [{ url: "/one" }, { url: "/two" }, { url: "/three" }]313 });314 testHistory.reset({315 locations: [{ url: "/uno" }, { url: "/dos" }]316 });317 expect(router.mock.calls[0][0]).toMatchObject({318 action: "push"319 });320 });321 });322});323describe("destroy", () => {324 it("doesn't emit navigation after being destroyed", () => {325 let navCount = 0;326 let testHistory = inMemory(327 pending => {328 navCount++;329 pending.finish();330 },331 {332 locations: [{ url: "/one" }]333 }334 );335 testHistory.navigate({ url: "/two" });336 expect(navCount).toBe(1);337 testHistory.destroy();338 testHistory.navigate({ url: "/three" });339 expect(navCount).toBe(1);340 });...

Full Screen

Full Screen

history.spec.js

Source:history.spec.js Github

copy

Full Screen

1import History from 'src/logic/filemanager/operations/history';2import Folder from 'src/logic/filemanager/data/folder';3import idMap from 'src/logic/filemanager/data/idmap';4describe('History', () => {5 /* Test History() */6 describe('History()', () => {7 it('should throw an error if input is null', () => {8 expect(() => {9 /* eslint no-new:0 */10 new History();11 }).to.throw(Error);12 });13 it('should create History given a Folder', () => {14 const testFolder = new Folder(0);15 const testHistory = new History(testFolder);16 expect(testHistory.currFolderID).to.equal(testFolder.id);17 });18 });19 /* Test update() */20 describe('update()', () => {21 it('should throw an error if input is null', () => {22 expect(() => {23 const testFolder = new Folder(0);24 idMap.addFolderToMap(testFolder.id, testFolder);25 const testHistory = new History(testFolder);26 testHistory.update();27 }).to.throw(Error);28 });29 idMap.clearMap();30 it('should throw an error if input is the same as current folder', () => {31 expect(() => {32 const testFolder = new Folder(0);33 idMap.addFolderToMap(testFolder.id, testFolder);34 const testHistory = new History(testFolder);35 testHistory.update(testFolder);36 }).to.throw(Error);37 });38 idMap.clearMap();39 it('should update current folder correctly', () => {40 const testFolder1 = new Folder(1);41 const testFolder2 = new Folder(2);42 idMap.addFolderToMap(testFolder1.id, testFolder1);43 idMap.addFolderToMap(testFolder2.id, testFolder2);44 const testHistory = new History(testFolder1);45 expect(testHistory.update(testFolder2)).to.equal(testFolder2);46 });47 idMap.clearMap();48 it('should update previous history correctly', () => {49 const testFolder1 = new Folder(1);50 const testFolder2 = new Folder(2);51 idMap.addFolderToMap(testFolder1.id, testFolder1);52 idMap.addFolderToMap(testFolder2.id, testFolder2);53 const expectedPreviousHistory = [testFolder1.id];54 const testHistory = new History(testFolder1);55 testHistory.update(testFolder2);56 expect(testHistory.previousHistory).to.deep.equal(expectedPreviousHistory);57 });58 idMap.clearMap();59 it('should clear next history', () => {60 const testFolder1 = new Folder(1);61 const testFolder2 = new Folder(2);62 idMap.addFolderToMap(testFolder1.id, testFolder1);63 idMap.addFolderToMap(testFolder2.id, testFolder2);64 const expectedNextHistory = [];65 const testHistory = new History(testFolder1);66 testHistory.update(testFolder2);67 expect(testHistory.nextHistory).to.deep.equal(expectedNextHistory);68 });69 idMap.clearMap();70 });71 /* Test previous() */72 describe('previous()', () => {73 it('should update current folder correctly', () => {74 const testFolder1 = new Folder(1);75 const testFolder2 = new Folder(2);76 idMap.addFolderToMap(testFolder1.id, testFolder1);77 idMap.addFolderToMap(testFolder2.id, testFolder2);78 const testHistory = new History(testFolder1);79 testHistory.update(testFolder2);80 expect(testHistory.previous()).to.equal(testFolder1);81 });82 idMap.clearMap();83 it('should update previous history correctly', () => {84 const testFolder1 = new Folder(1);85 const testFolder2 = new Folder(2);86 idMap.addFolderToMap(testFolder1.id, testFolder1);87 idMap.addFolderToMap(testFolder2.id, testFolder2);88 const expectedPreviousHistory = [];89 const testHistory = new History(testFolder1);90 testHistory.update(testFolder2);91 testHistory.previous();92 expect(testHistory.previousHistory).to.deep.equal(expectedPreviousHistory);93 });94 idMap.clearMap();95 it('should update next history correctly', () => {96 const testFolder1 = new Folder(1);97 const testFolder2 = new Folder(2);98 idMap.addFolderToMap(testFolder1.id, testFolder1);99 idMap.addFolderToMap(testFolder2.id, testFolder2);100 const expectedNextHistory = [testFolder2.id];101 const testHistory = new History(testFolder1);102 testHistory.update(testFolder2);103 testHistory.previous();104 expect(testHistory.nextHistory).to.deep.equal(expectedNextHistory);105 });106 idMap.clearMap();107 it('should return current folder if previous history is empty', () => {108 const testFolder1 = new Folder(0);109 const testHistory = new History(testFolder1);110 idMap.addFolderToMap(testFolder1.id, testFolder1);111 expect(testHistory.previous()).to.equal(testFolder1);112 });113 idMap.clearMap();114 });115 /* Test next() */116 describe('next()', () => {117 it('should update current folder correctly', () => {118 const testFolder1 = new Folder(1);119 const testFolder2 = new Folder(2);120 idMap.addFolderToMap(testFolder1.id, testFolder1);121 idMap.addFolderToMap(testFolder2.id, testFolder2);122 const testHistory = new History(testFolder1);123 testHistory.update(testFolder2);124 testHistory.previous();125 expect(testHistory.next()).to.equal(testFolder2);126 });127 idMap.clearMap();128 it('should update previous history correctly', () => {129 const testFolder1 = new Folder(1);130 const testFolder2 = new Folder(2);131 idMap.addFolderToMap(testFolder1.id, testFolder1);132 idMap.addFolderToMap(testFolder2.id, testFolder2);133 const expectedPreviousHistory = [testFolder1.id];134 const testHistory = new History(testFolder1);135 testHistory.update(testFolder2);136 testHistory.previous();137 testHistory.next();138 expect(testHistory.previousHistory).to.deep.equal(expectedPreviousHistory);139 });140 idMap.clearMap();141 it('should update next history correctly', () => {142 const testFolder1 = new Folder(1);143 const testFolder2 = new Folder(2);144 idMap.addFolderToMap(testFolder1.id, testFolder1);145 idMap.addFolderToMap(testFolder2.id, testFolder2);146 const expectedNextHistory = [];147 const testHistory = new History(testFolder1);148 testHistory.update(testFolder2);149 testHistory.previous();150 testHistory.next();151 expect(testHistory.nextHistory).to.deep.equal(expectedNextHistory);152 });153 idMap.clearMap();154 it('should return current folder if next history is empty', () => {155 const testFolder1 = new Folder(0);156 const testHistory = new History(testFolder1);157 idMap.addFolderToMap(testFolder1.id, testFolder1);158 expect(testHistory.next()).to.equal(testFolder1);159 });160 idMap.clearMap();161 });...

Full Screen

Full Screen

routeHelpers.test.js

Source:routeHelpers.test.js Github

copy

Full Screen

1import goToRoute, { RouteNames } from 'utils/routeHelpers';2describe('routeHelpers', () => {3 let testHistory;4 let mockPush;5 beforeEach(() => {6 mockPush = jest.fn();7 testHistory = {8 push: mockPush,9 };10 });11 const projectId = '14';12 const modelId = '7';13 const client = {14 id: '2',15 itsAppId: 'default',16 itsClientId: '247ai',17 standardClientName: 'tfsai',18 name: '247 ai',19 };20 const paramData = {21 client,22 projectId,23 modelId,24 };25 test('returns expected route for selected route name', () => {26 const expectedRoute = `/projects?clientid=${client.standardClientName}&appid=${client.itsAppId}&projectid=${projectId}`;27 goToRoute(RouteNames.PROJECTID, paramData, testHistory);28 expect(mockPush.mock.calls.length).toBe(1);29 expect(mockPush.mock.calls[0][0]).toBe(expectedRoute);30 });31 test('history is called for PROJECTS', () => {32 goToRoute(RouteNames.PROJECTS, paramData, testHistory);33 expect(mockPush.mock.calls.length).toBe(1);34 });35 test('history is called for TAG_DATASETS', () => {36 goToRoute(RouteNames.TAG_DATASETS, paramData, testHistory);37 expect(mockPush.mock.calls.length).toBe(1);38 });39 test('history is called for MODELS', () => {40 goToRoute(RouteNames.MODELS, paramData, testHistory);41 expect(mockPush.mock.calls.length).toBe(1);42 });43 test('history is called for CREATEMODEL', () => {44 goToRoute(RouteNames.CREATEMODEL, paramData, testHistory);45 expect(mockPush.mock.calls.length).toBe(1);46 });47 test('history is called for TUNEMODEL', () => {48 goToRoute(RouteNames.TUNEMODEL, paramData, testHistory);49 expect(mockPush.mock.calls.length).toBe(1);50 });51 test('history is called for DATASETS', () => {52 goToRoute(RouteNames.DATASETS, paramData, testHistory);53 expect(mockPush.mock.calls.length).toBe(1);54 });55 test('history is called for TESTMODEL', () => {56 goToRoute(RouteNames.TESTMODEL, paramData, testHistory);57 expect(mockPush.mock.calls.length).toBe(1);58 });59 test('history is called for REPORTS', () => {60 goToRoute(RouteNames.REPORTS, paramData, testHistory);61 expect(mockPush.mock.calls.length).toBe(1);62 });63 test('history is called for UPDATEPROJECT', () => {64 goToRoute(RouteNames.UPDATEPROJECT, paramData, testHistory);65 expect(mockPush.mock.calls.length).toBe(1);66 });67 test('history is called for READPROJECT', () => {68 goToRoute(RouteNames.READPROJECT, paramData, testHistory);69 expect(mockPush.mock.calls.length).toBe(1);70 });71 test('history is called for MANAGE_INTENTS', () => {72 goToRoute(RouteNames.MANAGE_INTENTS, paramData, testHistory);73 expect(mockPush.mock.calls.length).toBe(1);74 });75 test('history is called for SETTINGS PAGE', () => {76 goToRoute(RouteNames.SETTINGS, paramData, testHistory);77 expect(mockPush.mock.calls.length).toBe(1);78 });79 test('history is called for SETTINGS TAB', () => {80 goToRoute(RouteNames.MANAGE_SETTINGS, paramData, testHistory);81 expect(mockPush.mock.calls.length).toBe(1);82 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { testHistory } = require("qawolf");2const { chromium } = require("playwright");3(async () => {4 const browser = await chromium.launch();5 await testHistory(browser, "./test.js");6 await browser.close();7})();8const { testHistory } = require("qawolf");9const { chromium } = require("playwright");10(async () => {11 const browser = await chromium.launch();12 await testHistory(browser, "./test.js");13 await browser.close();14})();15const { testHistory } = require("qawolf");16const { chromium } = require("playwright");17(async () => {18 const browser = await chromium.launch();19 await testHistory(browser, "./test.js");20 await browser.close();21})();22const { testHistory } = require("qawolf");23const { chromium } = require("playwright");24(async () => {25 const browser = await chromium.launch();26 await testHistory(browser, "./test.js");27 await browser.close();28})();29const { testHistory } = require("qawolf");30const { chromium } = require("playwright");31(async () => {32 const browser = await chromium.launch();33 await testHistory(browser, "./test.js");34 await browser.close();35})();36const { testHistory } = require("qawolf");37const { chromium } = require("playwright");38(async () => {39 const browser = await chromium.launch();40 await testHistory(browser, "./test.js");41 await browser.close();42})();43const { testHistory } = require("qawolf");

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 qawolf 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