How to use intercept method in wpt

Best JavaScript code snippet using wpt

lifecycle-manager.spec.js

Source:lifecycle-manager.spec.js Github

copy

Full Screen

1import {LifecycleManager} from '../src/lifecycle-manager';2import {ClassActivator} from 'aurelia-dependency-injection';3import {FluxDispatcher} from '../src/flux-dispatcher';4import {Symbols} from '../src/symbols';5import {HtmlBehaviorResource} from 'aurelia-templating';6import {Dispatcher, DispatcherProxy} from '../src/instance-dispatcher';7import {Metadata} from '../src/metadata';8describe('Lifecycle Manager', () => {9 describe('interceptInstanceDeactivate', () => {10 var instance;11 beforeEach(() => {12 instance = {};13 });14 describe('without instance.deactivate', () => {15 it('adds new deactivate method', () => {16 expect(instance.deactivate).toBeUndefined();17 LifecycleManager.interceptInstanceDeactivate(instance);18 expect(instance.deactivate).toBeDefined();19 });20 describe('intercepted deactivate method', () => {21 it('runs FluxDispatcher', () => {22 spyOn(FluxDispatcher.instance, 'unregisterInstanceDispatcher');23 LifecycleManager.interceptInstanceDeactivate(instance);24 instance.deactivate();25 expect(FluxDispatcher.instance.unregisterInstanceDispatcher).toHaveBeenCalled();26 });27 });28 });29 describe('with instance.deactivate', () => {30 it('intercepts deactivate method', () => {31 var deactivate = function () { };32 instance.deactivate = deactivate;33 LifecycleManager.interceptInstanceDeactivate(instance);34 expect(instance.deactivate).toBeDefined();35 expect(instance.deactivate).not.toBe(deactivate);36 });37 describe('intercepted deactivate method', () => {38 it('runs original deactivate method', () => {39 var deactivate = jasmine.createSpy('deactivate');40 instance.deactivate = deactivate;41 LifecycleManager.interceptInstanceDeactivate(instance);42 instance.deactivate();43 expect(deactivate).toHaveBeenCalled();44 });45 it('runs FluxDispatcher', () => {46 spyOn(FluxDispatcher.instance, 'unregisterInstanceDispatcher');47 var deactivate = function () { };48 instance.deactivate = deactivate;49 LifecycleManager.interceptInstanceDeactivate(instance);50 instance.deactivate();51 expect(FluxDispatcher.instance.unregisterInstanceDispatcher).toHaveBeenCalled();52 });53 });54 });55 });56 describe('interceptInstanceDetached', () => {57 var instance;58 beforeEach(() => {59 instance = {};60 });61 describe('without instance.detached', () => {62 it('adds new detached method', () => {63 expect(instance.detached).toBeUndefined();64 LifecycleManager.interceptInstanceDetached(instance);65 expect(instance.detached).toBeDefined();66 });67 describe('intercepted detached method', () => {68 it('runs FluxDispatcher', () => {69 spyOn(FluxDispatcher.instance, 'unregisterInstanceDispatcher');70 LifecycleManager.interceptInstanceDetached(instance);71 instance.detached();72 expect(FluxDispatcher.instance.unregisterInstanceDispatcher).toHaveBeenCalled();73 });74 });75 });76 describe('with instance.detached', () => {77 it('intercepts detached method', () => {78 var detached = function () { };79 instance.detached = detached;80 LifecycleManager.interceptInstanceDetached(instance);81 expect(instance.detached).toBeDefined();82 expect(instance.detached).not.toBe(detached);83 });84 describe('intercepted detached method', () => {85 it('runs original detached method', () => {86 var detached = jasmine.createSpy('detached');87 instance.detached = detached;88 LifecycleManager.interceptInstanceDetached(instance);89 instance.detached();90 expect(detached).toHaveBeenCalled();91 });92 it('runs FluxDispatcher', () => {93 spyOn(FluxDispatcher.instance, 'unregisterInstanceDispatcher');94 var detached = function () { };95 instance.detached = detached;96 LifecycleManager.interceptInstanceDetached(instance);97 instance.detached();98 expect(FluxDispatcher.instance.unregisterInstanceDispatcher).toHaveBeenCalled();99 });100 });101 });102 });103 describe('interceptInstanceDeactivators', () => {104 var instance;105 beforeEach(() => {106 instance = {};107 });108 it('sets Symbols.deactivators on an instance when invoked', () => {109 expect(instance[Symbols.deactivators]).toBeUndefined();110 LifecycleManager.interceptInstanceDeactivators(instance);111 expect(instance[Symbols.deactivators]).toBeDefined();112 });113 it('runs LifecycleManager.interceptInstanceDeactivate', () => {114 spyOn(LifecycleManager, 'interceptInstanceDeactivate');115 LifecycleManager.interceptInstanceDeactivators(instance);116 expect(LifecycleManager.interceptInstanceDeactivate).toHaveBeenCalledWith(instance);117 });118 it('runs LifecycleManager.interceptInstanceDeactivate only once', () => {119 spyOn(LifecycleManager, 'interceptInstanceDeactivate');120 LifecycleManager.interceptInstanceDeactivators(instance);121 LifecycleManager.interceptInstanceDeactivators(instance);122 expect(LifecycleManager.interceptInstanceDeactivate.calls.count()).toEqual(1);123 });124 it('runs LifecycleManager.interceptInstanceDetached', () => {125 spyOn(LifecycleManager, 'interceptInstanceDetached');126 LifecycleManager.interceptInstanceDeactivators(instance);127 expect(LifecycleManager.interceptInstanceDetached).toHaveBeenCalledWith(instance);128 });129 it('runs LifecycleManager.interceptInstanceDetached only once', () => {130 spyOn(LifecycleManager, 'interceptInstanceDetached');131 LifecycleManager.interceptInstanceDeactivators(instance);132 LifecycleManager.interceptInstanceDeactivators(instance);133 expect(LifecycleManager.interceptInstanceDetached.calls.count()).toEqual(1);134 });135 });136 describe('interceptHtmlBehaviorResource', () => {137 describe('intercepted analyze method', () => {138 it('runs original method', () => {139 var analyze = jasmine.createSpy('analyze');140 HtmlBehaviorResource.prototype.analyze = analyze;141 LifecycleManager.interceptHtmlBehaviorResource();142 expect(HtmlBehaviorResource.prototype.analyze).not.toBe(analyze);143 function target() { };144 HtmlBehaviorResource.prototype.analyze(1, target, false);145 expect(analyze).toHaveBeenCalledWith(1, target, false);146 });147 it('adds detached method to a target with flux metadata', () => {148 function target() { }149 target.prototype[Symbols.metadata] = {150 handlers: {151 size: 123152 }153 };154 expect(target.prototype.detached).toBeUndefined();155 HtmlBehaviorResource.prototype.analyze = function () { };156 LifecycleManager.interceptHtmlBehaviorResource();157 HtmlBehaviorResource.prototype.analyze(null, target);158 expect(target.prototype.detached).toBeDefined();159 });160 it('doesn\'t add detached method to a target without flux metadata', () => {161 function target() { }162 expect(target.prototype.detached).toBeUndefined();163 HtmlBehaviorResource.prototype.analyze = function () { };164 LifecycleManager.interceptHtmlBehaviorResource();165 HtmlBehaviorResource.prototype.analyze(null, target);166 expect(target.prototype.detached).toBeUndefined();167 });168 });169 });170 describe('interceptClassActivator', () => {171 var invokeImpl,172 instance,173 origInstanceProto,174 instanceProto;175 176 beforeAll(() => { 177 instanceProto = {}; 178 }); 179 180 beforeEach(() => {181 instance = Object.create(instanceProto);182 invokeImpl = jasmine.createSpy('invoke').and.returnValue(instance);183 ClassActivator.instance.invoke = invokeImpl;184 });185 it('intercepts ClassActivator.instance.invoke', () => {186 LifecycleManager.interceptClassActivator();187 expect(ClassActivator.instance.invoke).not.toBe(invokeImpl);188 });189 describe('intercepted ClassActivator.instance.invoke', () => { 190 191 it('throws an exception when second argument is not an array', () => {192 LifecycleManager.interceptClassActivator();193 expect(() => ClassActivator.instance.invoke(null, "")).toThrowError('Unsupported version of ClassActivator');194 }); 195 196 // without dispatcher injected197 describe('without dispatcher injected', () => {198 it('runs original invoke method', () => {199 LifecycleManager.interceptClassActivator();200 ClassActivator.instance.invoke(null, []);201 expect(invokeImpl).toHaveBeenCalled();202 });203 it('returns proper instance', () => {204 LifecycleManager.interceptClassActivator();205 var result = ClassActivator.instance.invoke(null, []);206 expect(result).toBe(instance);207 });208 });209 ///////////////////////////////210 211 // with dispatcher injected212 describe('with dispatcher injected', () => {213 var dispatcher;214 beforeEach(() => {215 dispatcher = new Dispatcher();216 });217 it('runs original invoke method', () => {218 LifecycleManager.interceptClassActivator();219 ClassActivator.instance.invoke(null, [dispatcher]);220 expect(invokeImpl).toHaveBeenCalled();221 });222 it('returns proper instance', () => {223 LifecycleManager.interceptClassActivator();224 var result = ClassActivator.instance.invoke(null, [dispatcher]);225 expect(result).toBe(instance);226 });227 it('replaces injected Dispatcher with DispatcherProxy', (done) => {228 LifecycleManager.interceptClassActivator();229 var args = [dispatcher];230 ClassActivator.instance.invoke(null, args);231 expect(args[0] instanceof DispatcherProxy).toBe(true);232 args[0].inititalize.then(() => {233 expect(args[0].instance).toBe(instance);234 done();235 }, done.fail);236 });237 it('sets instance[Symbols.instanceDispatcher] to be new Dispatcher', () => {238 LifecycleManager.interceptClassActivator();239 expect(instance[Symbols.instanceDispatcher]).toBeUndefined();240 ClassActivator.instance.invoke(null, [dispatcher]);241 expect(instance[Symbols.instanceDispatcher]).toBeDefined();242 });243 244 it('intercepts instance deactivators', () => {245 spyOn(LifecycleManager, 'interceptInstanceDeactivators');246 LifecycleManager.interceptClassActivator();247 ClassActivator.instance.invoke(null, [dispatcher]);248 expect(LifecycleManager.interceptInstanceDeactivators).toHaveBeenCalledWith(instance);249 });250 }); 251 ///////////////////////////////252 253 describe('for instance prototype with metadata', () => { 254 255 beforeEach(() => {256 instanceProto[Symbols.metadata] = new Metadata();257 });258 259 it('runs instance Disptacher.registerMetadata', () => {260 spyOn(Dispatcher.prototype, 'registerMetadata');261 LifecycleManager.interceptClassActivator(); 262 ClassActivator.instance.invoke(null, []);263 expect(Dispatcher.prototype.registerMetadata).toHaveBeenCalled();264 });265 266 it('intercepts instance deactivators', () => {267 spyOn(LifecycleManager, 'interceptInstanceDeactivators');268 LifecycleManager.interceptClassActivator();269 ClassActivator.instance.invoke(null, []);270 expect(LifecycleManager.interceptInstanceDeactivators).toHaveBeenCalledWith(instance);271 }); 272 });273 274 });275 });...

Full Screen

Full Screen

general.spec.js

Source:general.spec.js Github

copy

Full Screen

1import { activeYear } from "../common/date"2import { closeTips } from "../common/dialog"3import { interceptAll, waitRequest } from "../common/http"4import { validErrorMsg, validSuccessMessage } from "../common/message"5import { activeSelect } from "../common/select"6import { elform } from "../mutual-result/mutual-item"7/**8 * 9 * @param {string} text 点击某个功能点10 */11const findPoint = (text) => {12 cy.get('.el-collapse-item__header').contains(text).click({13 force:true14 })15}16/**17 * 18 * @param {string} text 按键文本19 * @param {number} buttonIndex 按键索引 默认值为零20 */21const clickPonitButton = (text, buttonIndex = 0) => {22 cy.findAllByText(text).eq(buttonIndex).click({23 force:true24 })25}26/**27 * @param {string} text 功能点文案28 * @param {Function} option 在该功能点下的操作29 */30const withinPointOption = (text, option) => {31 cy.get('.el-collapse-item').contains(text).parents('.el-collapse-item').within(() => {32 option() && option()33 })34}35/**36 * 37 * @param {function} interceptFunction 拦截路由函数38 * @param {function} option 拦截路由前的操作39 * @param {boolean} closeCollapse 是否需要点击功能点关闭 默认不需要40 * @param {text} text 功能点文案41 */42const pointIsAvailable = (interceptFunction, option, closeCollapse = false, text) => {43 const waitOptions = {44 timeout: 9000045 }46 waitRequest({47 intercept: interceptFunction,48 waitOptions,49 onBefore: () => {50 option() && option51 },52 onSuccess: () => {53 validSuccessMessage()54 },55 onError: (msg) => {56 validErrorMsg(msg)57 }58 })59 if (closeCollapse === true) {60 findPoint(text)61 cy.wait(1000)62 }63}64const interceptPullEqa = () => {65 return interceptAll('service/mgr/eqa/importGdEqa?adminCclCode*', interceptPullEqa.name)66}67const interceptUpdateDataComprison = () => {68 return interceptAll('service/mgr/eqa/syncGdEqaItemCodeMap?adminCclCode*', interceptUpdateDataComprison.name)69}70const interceptSyncStandardData = () => {71 return interceptAll('service/mgr/code/sync*', interceptSyncStandardData.name)72}73const interceptUpdateLabGps = () => {74 return interceptAll('service/mgr/lab/updateAllNoGps', interceptUpdateLabGps.name)75}76const interceptPullPlan = () => {77 return interceptAll('service/v2/qi/pull-plan?*', interceptPullPlan.name)78}79const interceptPullEqaPlan = () => {80 return interceptAll('service/mgr/eqa/pullEqaPlan?*', interceptPullEqaPlan.name)81}82const interceptSyncReport = () => {83 return interceptAll('service/mgr/lab/report/monthdiff/syncReport?adminCclCode*', interceptSyncReport.name)84}85const interceptPullFeedbackReport = () => {86 return interceptAll('service/v2/report/EXT_KL_REF/pull?', interceptPullFeedbackReport.name)87}88const interceptPullPatientsReport = () => {89 return interceptAll('service/v2/report/EXT_KL_PAT/pull?reportType=EXT_KL_PAT', interceptPullPatientsReport.name)90}91const interceptPullLabFeedbackReport = () => {92 return interceptAll('service/v2/report/EXT_KL_QI/pull?reportType=EXT_KL_QI', interceptPullLabFeedbackReport.name)93}94context('通用功能', () => {95 before(() => {96 cy.loginCQB()97 cy.visit('/cqb-base-mgr-fe/app.html#/system-seting/general')98 })99 context('拉取科临报告', () => {100 before(() => {101 findPoint('拉取科临报告')102 cy.wait(1000)103 })104 it('001-参考区间调查报告', () => {105 pointIsAvailable(interceptSyncReport, () => {106 withinPointOption('拉取科临报告', () => {107 elform('adminCclCode').click({108 force:true109 })110 cy.wait(1000)111 activeSelect('佛山市临床检验质量控制中心')112 clickPonitButton('拉取')113 })114 })115 })116 it('002-患者数据调查报告', () => {117 pointIsAvailable(interceptPullPatientsReport, () => {118 withinPointOption('拉取科临报告', () => {119 cy.get('[placeholder="请选择"]').first().click()120 cy.wait(1000)121 activeSelect('患者数据调查反馈报告')122 clickPonitButton('拉取')123 })124 })125 })126 it('003-实验室质量指标调查反馈报告', () => {127 pointIsAvailable(interceptPullPatientsReport, () => {128 withinPointOption('拉取科临报告', () => {129 cy.get('[placeholder="请选择"]').first().click()130 cy.wait(1000)131 activeSelect('实验室质量指标调查反馈报告')132 clickPonitButton('拉取')133 }, true, '拉取科临报告')134 })135 })136 })137 context('差异性分析报告', () => {138 before(() => {139 findPoint('拉取差异性分析报告')140 cy.wait(1000)141 })142 it('004-拉取差异性分析报告', () => {143 pointIsAvailable(interceptSyncReport, () => {144 clickPonitButton('拉取')145 }, true, '拉取差异性分析报告')146 })147 })148 context('EQA数据处理', () => {149 it('005-拉取广东EQA数据', () => {150 findPoint('EQA数据处理')151 cy.wait(2000)152 pointIsAvailable(interceptPullEqa, () => {153 clickPonitButton('拉取', 1)154 })155 })156 it('006-更新对照数据', () => {157 cy.wait(1000)158 pointIsAvailable(interceptUpdateDataComprison, () => {159 clickPonitButton('更新对照数据')160 }, true, 'EQA数据处理')161 })162 })163 context('同步数据', () => {164 it('007-同步标准数据', () => {165 findPoint('同步标准数据')166 cy.wait(1000)167 pointIsAvailable(interceptSyncStandardData, () => {168 clickPonitButton('同步')169 closeTips('提示', '同步')170 }, true, '同步标准数据')171 })172 it('008-同步GPS坐标', () => {173 findPoint('实验室GPS坐标')174 cy.wait(1000)175 pointIsAvailable(interceptUpdateLabGps, () => {176 clickPonitButton('同步', 1)177 closeTips('提示', '同步')178 }, true, '实验室GPS坐标')179 })180 })181 context('省/部EQA计划拉取', () => {182 before(() => {183 findPoint('省/部EQA计划拉取')184 cy.wait(1000)185 })186 it('009-部EQA', () => {187 pointIsAvailable(interceptPullEqaPlan, () => {188 clickPonitButton('拉取', 2)189 })190 })191 it('0010-省EQA', () => {192 cy.wait(1000)193 pointIsAvailable(interceptPullEqaPlan, () => {194 cy.get('[type ="radio"]').check('0',{195 force:true196 })197 clickPonitButton('拉取', 2)198 }, true, '省/部EQA计划拉取')199 })200 })201 context('质量指标上报计划拉取', () => {202 before(() => {203 findPoint('质量指标上报计划拉取')204 cy.wait(1000)205 })206 it('011-质量指标上报计划拉取', () => {207 pointIsAvailable(interceptPullPlan, () => {208 withinPointOption('质量指标上报计划拉取', () => {209 elform('adminCclCode').click({210 force:true211 })212 cy.wait(1000)213 activeSelect('浙江直采测试')214 elform('year').click({215 force:true216 })217 activeYear('2020')218 })219 clickPonitButton('拉取', 3)220 })221 })222 })...

Full Screen

Full Screen

iqc.js

Source:iqc.js Github

copy

Full Screen

1import { clickButton } from "../common/button"2import { closeTips, confirmDelete } from "../common/dialog"3import { interceptAll, waitIntercept, waitRequest } from "../common/http"4import { validSuccessMessage } from "../common/message"5import { activeSelect } from "../common/select"6import { elform } from "../mutual-result/mutual-item"7import { clickSearch } from "../setting/report-monitor/report-monitor"8import { validData } from "./cert-year"9const interceptQueryIqcReport = () => {10 return interceptAll('service/mgr/iqc/month/new-page?areaId*', interceptQueryIqcReport.name)11}12export const interceptQueryLab = () => {13 return interceptAll('service/mgr/lab/pageWithRole?*', interceptQueryLab.name)14}15export const interceptPreviewIqc = (path) => {16 return interceptAll(`service/system/file/preview/${path}`, interceptPreviewIqc.name)17}18const interceptPushIqc = () => {19 return interceptAll('service/mgr/iqc/month/push?*', interceptPushIqc.name)20}21const interceptBatchPushIqc = () => {22 return interceptAll('service/mgr/iqc/month/batchPush', interceptBatchPushIqc.name)23}24/**25 * 26 * @param {string} text label标签名27 * @param {string} timeText 输入框名字28 */29export const findLabelTime = (text, timeText) => {30 cy.get('.el-form:visible')31 .find('label')32 .contains(text)33 .parent()34 .find(`[placeholder="${timeText}"]`)35 .click({36 force:true37 })38}39/**40 * 41 * @param {boolean} pushAll 是否是批量推送 默认不是批量推送42 * @param {string} buttonText 按键名称43 * @param {boolean} cancelPush 是否取消推送 默认不是44 */45export const pushIqcData = (pushAll = false, buttonText, cancelPush = false) => {46 waitIntercept(interceptQueryIqcReport, () => {47 clickSearch()48 }, data => {49 if (pushAll === false) {50 if (cancelPush === false) {51 if (data.total) {52 const rowIndex = data.data.findIndex(item => item.push === false)53 if (rowIndex !== -1) {54 let queryData55 waitIntercept(interceptPushIqc, () => {56 cy.get('.el-table__body').first().find('.el-table__row')57 .eq(rowIndex)58 .findAllByText(buttonText)59 .last()60 .click({61 force:true62 })63 closeTips('提示', '推送')64 queryData = interceptQueryIqcReport()65 },() => {66 validSuccessMessage()67 waitIntercept(queryData,() => {68 clickSearch()69 }, (data) => {70 expect(data.data[rowIndex].push).to.eq(true)71 })72 })73 }74 }75 } else {76 if (data.total) {77 const rowIndex = data.data.findIndex(item => item.push)78 if (rowIndex !== -1) {79 let queryData80 waitIntercept(interceptPushIqc, () => {81 cy.get('.el-table__body').first().find('.el-table__row')82 .eq(rowIndex)83 .findAllByText(buttonText)84 .last()85 .click({86 force:true87 })88 closeTips('提示', '推送')89 queryData = interceptQueryIqcReport()90 },() => {91 validSuccessMessage()92 waitIntercept(queryData,() => {93 clickSearch()94 }, (data) => {95 expect(data.data[rowIndex].push).to.eq(false)96 })97 })98 }99 }100 }101 } else {102 if (data.total) {103 if (cancelPush === false) {104 let queryData105 cy.get('.el-table__header').first().find('[type="checkbox"]').click({106 force:true107 })108 cy.wait(1000)109 waitIntercept(interceptBatchPushIqc, () => {110 clickButton(buttonText)111 closeTips('提示', '推送')112 queryData = interceptQueryIqcReport()113 }, () => {114 validSuccessMessage()115 waitIntercept(queryData, (data) => {116 data.data.map(item => expect(item.push).to.eq(true))117 })118 })119 } else {120 let queryData121 cy.get('.el-table__header').first().find('[type="checkbox"]').click({122 force:true123 })124 cy.wait(1000)125 waitIntercept(interceptBatchPushIqc, () => {126 clickButton(buttonText)127 closeTips('提示', '推送')128 queryData = interceptQueryIqcReport()129 }, () => {130 validSuccessMessage()131 waitIntercept(queryData, (data) => {132 data.data.map(item => expect(item.push).to.eq(false))133 })134 })135 }136 }137 }138 })139}140export const interceptDeleteIqcReport = () => {141 return interceptAll('service/mgr/iqc/month', interceptDeleteIqcReport.name)142}143export const deleteIqcReport = (rowIndex) => {144 waitRequest({145 intercept: interceptDeleteIqcReport,146 onBefore: () => {147 cy.get('.el-table__body').first().find('.el-table__row')148 .eq(rowIndex)149 .findAllByText('删除')150 .last()151 .click({152 force:true153 })154 confirmDelete()155 },156 onError: () => {157 console.log(123);158 },159 onSuccess: () => {160 validSuccessMessage()161 }162 })163}164/**165 * 166 * @param {string} area 地区 省167 * @param {string} keyword 实验室名称或者编码168 * @param {boolean} labCode 是否使用实验室编码169 */170export const searchIqcReport = (area, keyword, labCode = false) => {171 if (area) {172 elform('areaId').click({173 force:true174 })175 activeSelect(area)176 waitIntercept(interceptQueryIqcReport, () => {177 clickSearch()178 }, data => {179 validData(data)180 if (data.total) {181 data.data.map(item => expect(item.province).to.contain(area))182 }183 })184 }185 if (keyword) {186 elform('labName').clear().type(keyword)187 waitIntercept(interceptQueryIqcReport, () => {188 clickSearch()189 }, data => {190 validData(data)191 if (data.total) {192 if (labCode === false) {193 data.data.map(item => expect(item.labName).to.contain(keyword))194 } else {195 data.data.map(item => expect(item.labCode).to.contain(keyword))196 }197 }198 })199 }...

Full Screen

Full Screen

sunClass.js

Source:sunClass.js Github

copy

Full Screen

1class sun{2 constructor(lineNumber, width, height){3 this.originX = mouseX;4 this.originY = mouseY;5 this.rayNumber = lineNumber;6 this.screenWidth = width;7 this.screenHeight = height;8 this.screenEdges = [9 [0, 0, screenWidth, 0],10 [0, screenHeight, screenWidth, screenHeight],11 [0, 0, 0, screenHeight],12 [screenWidth, screenHeight, screenWidth, screenHeight]13 ];14 this.screenGradients = [0, 0, Number.NaN, Number.NaN];15 this.screenC = [0, screenHeight, Number.NaN, Number.NaN];16 this.screenX = [Number.NaN, Number.NaN, 0, screenWidth];17 this.intercepts = new Array(this.rayNumber);18 for(var i = 0; i < this.rayNumber; i++){19 this.intercepts[i] = new Array(2);20 }21 this.angles = new Array(this.rayNumber);22 this.gradients = new Array(this.rayNumber);23 this.angles[0] = 2 * Math.PI / this.rayNumber;24 this.gradients[0] = tan(this.angles[0]);25 for(var i = 1; i < this.rayNumber; i++){26 this.angles[i] = this.angles[i-1] + this.angles[0];27 if(this.angles[i] === 0.5 * Math.PI || this.angles[i] === 1.5 * Math.PI){28 this.gradients[i] = Number.NaN;29 }else{30 this.gradients[i] = tan(this.angles[i]);31 }32 }33 // console.log(this.angles);34 this.C = new Array(this.rayNumber);35 }36 update(){37 this.originX = mouseX;38 this.originY = mouseY;39 }40 findC(){41 for(var i = 0; i < this.rayNumber; i++){42 if(!isNaN(this.gradients[i])){43 this.C[i] = this.originY - this.gradients[i] * this.originX;44 }else{45 this.C[i] = Number.NaN;46 }47 }48 }49 interceptScreenEdges(){50 for(var i = 2; i < 4; i++){51 for(var j = 0; j < this.rayNumber; j++){52 if(!isNaN(this.gradients[j])){53 var interceptX = this.screenX[i];54 var interceptY = this.gradients[j] * interceptX + this.C[j];55 if((this.angles[j] < 0.5 * Math.PI || this.angles[j] > 1.5 * Math.PI) && 1){56 if(interceptX > this.originX){57 this.intercepts[j][0] = interceptX;58 this.intercepts[j][1] = interceptY;59 }60 }else61 if((this.angles[j] > 0.5 * Math.PI || this.angles[j] < 1.5 * Math.PI) && 1){62 if(interceptX < this.originX){63 this.intercepts[j][0] = interceptX;64 this.intercepts[j][1] = interceptY;65 }66 }67 }68 }69 }70 for(var i = 0; i < 2; i++){71 for(var j = 0; j < this.rayNumber; j++){72 if(!isNaN(this.gradients[j])){73 var interceptX = (this.C[j] - this.screenC[i]) / (this.screenGradients[i] - this.gradients[j]);74 var interceptY = this.screenC[i];75 if(this.angles[j] < 0.5 * Math.PI || this.angles[j] > 1.5 * Math.PI){76 if(interceptX > this.originX){77 if(interceptX < this.intercepts[j][0]){78 this.intercepts[j][0] = interceptX;79 this.intercepts[j][1] = interceptY;80 }81 }82 }else83 if(this.angles[j] > 0.5 * Math.PI || this.angles[j] < 1.5 * Math.PI){84 if(interceptX < this.originX){85 if(interceptX > this.intercepts[j][0]){86 this.intercepts[j][0] = interceptX;87 this.intercepts[j][1] = interceptY;88 }89 }90 }91 }else{92 if(this.angles[j] < Math.PI){93 this.intercepts[j][0] = this.originX;94 this.intercepts[j][1] = this.screenHeight;95 }else96 if(this.angles[j] > Math.PI){97 this.intercepts[j][0] = this.originX;98 this.intercepts[j][1] = 0;99 }100 }101 }102 }103 }104 findIntercept(lineConst){105 for(var j = 0; j < this.rayNumber; j++){106 if(!isNaN(this.gradients[j])){107 if(isFinite(lineConst[0])){108 var interceptX = (this.C[j] - lineConst[1]) / (lineConst[0] - this.gradients[j]);109 var interceptY = this.gradients[j] * interceptX + this.C[j];110 if(this.angles[j] < 0.5 * Math.PI || this.angles[j] > 1.5 * Math.PI){111 if(interceptX > this.originX){112 var dist = interceptX - lineConst[2]; 113 if(0 <= dist && dist < lineConst[3] - lineConst[2]){114 if(interceptX < this.intercepts[j][0]){115 this.intercepts[j][0] = interceptX;116 this.intercepts[j][1] = interceptY;117 }118 }119 }120 }else121 if(this.angles[j] > 0.5 * Math.PI || this.angles[j] < 1.5 * Math.PI){122 if(interceptX < this.originX){123 var dist = interceptX - lineConst[2]; 124 if(0 <= dist && dist < lineConst[3] - lineConst[2]){125 if(interceptX > this.intercepts[j][0]){126 this.intercepts[j][0] = interceptX;127 this.intercepts[j][1] = interceptY;128 }129 }130 }131 }132 }else{133 var interceptX = lineConst[2];134 var interceptY = this.gradients[j] * interceptX + this.C[j];135 if(this.angles[j] < 0.5 * Math.PI || this.angles[j] > 1.5 * Math.PI){136 if(interceptX > this.originX){137 var dist = abs(interceptY - lineConst[4]) + abs(interceptY - lineConst[5]); 138 if(dist === abs(lineConst[4] - lineConst[5])){139 if(interceptX < this.intercepts[j][0]){140 this.intercepts[j][0] = interceptX;141 this.intercepts[j][1] = interceptY;142 }143 }144 }145 }else146 if(this.angles[j] > 0.5 * Math.PI || this.angles[j] < 1.5 * Math.PI){147 if(interceptX < this.originX){148 var dist = abs(interceptY - lineConst[4]) + abs(interceptY - lineConst[5]); 149 if(dist === abs(lineConst[4] - lineConst[5])){150 if(interceptX > this.intercepts[j][0]){151 this.intercepts[j][0] = interceptX;152 this.intercepts[j][1] = interceptY;153 }154 }155 }156 }157 }158 }else{159 if(this.angles[j] < Math.PI){160 var interceptX = this.originX;161 var interceptY = lineConst[0] * interceptX + lineConst[1];162 var dist = interceptX - lineConst[2]; 163 if(0 <= dist && dist < lineConst[3] - lineConst[2]){164 if(this.originY < interceptY && interceptY < this.intercepts[j][1]){165 this.intercepts[j][0] = interceptX;166 this.intercepts[j][1] = interceptY;167 }168 }169 }else170 if(this.angles[j] > Math.PI){171 var interceptX = this.originX;172 var interceptY = lineConst[0] * interceptX + lineConst[1];173 var dist = interceptX - lineConst[2]; 174 if(0 <= dist && dist < lineConst[3] - lineConst[2]){175 if(this.originY > interceptY && interceptY > this.intercepts[j][1]){176 this.intercepts[j][0] = interceptX;177 this.intercepts[j][1] = interceptY;178 }179 }180 }181 }182 }183 }184 cast(){185 for(var i = 0; i < this.rayNumber; i++){186 line(this.originX, this.originY, this.intercepts[i][0], this.intercepts[i][1]);187 }188 }...

Full Screen

Full Screen

lifecycle-scripts.spec.js

Source:lifecycle-scripts.spec.js Github

copy

Full Screen

...27 const stderr = output.slice(ix1 + 1, output.length - 1);28 return { stdout, stderr };29 };30 it("should execute a script from package.json", () => {31 const intercept = xstdout.intercept(true);32 const promise = new LifecycleScripts(Path.join(__dirname, "../fixtures/lifecycle-scripts/f1"))33 .execute(["test"])34 .then(() => {35 intercept.restore();36 expect(intercept.stdout[2].trim()).to.equal("hello");37 })38 .catch(err => failRestore(err, intercept));39 return promise;40 });41 it("should silently execute a script from package.json", () => {42 const intercept = xstdout.intercept(true);43 const promise = new LifecycleScripts(Path.join(__dirname, "../fixtures/lifecycle-scripts/f1"))44 .execute("test1", true)45 .then(() => {46 intercept.restore();47 const output = extractOutput(intercept);48 expect(output.stdout[0]).to.equal("hello");49 expect(output.stderr[0]).to.equal("stderr foo");50 })51 .catch(err => failRestore(err, intercept));52 return promise;53 });54 it("should silently execute a script with empty output from package.json", () => {55 const intercept = xstdout.intercept(true);56 const promise = new LifecycleScripts(Path.join(__dirname, "../fixtures/lifecycle-scripts/f1"))57 .execute("test4", true)58 .then(() => {59 intercept.restore();60 const output = extractOutput(intercept);61 expect(output.stdout).to.be.empty;62 expect(output.stderr).to.be.empty;63 })64 .catch(err => failRestore(err, intercept));65 return promise;66 });67 it("should silently execute a fail script from package.json", () => {68 let error;69 const intercept = xstdout.intercept(true);70 const promise = new LifecycleScripts(Path.join(__dirname, "../fixtures/lifecycle-scripts/f1"))71 .execute("test3", true)72 .catch(err => {73 intercept.restore();74 error = err;75 })76 .then(() => {77 intercept.restore();78 expect(error).to.exist;79 const output = extractOutput(intercept);80 expect(output.stdout).to.be.empty;81 expect(output.stderr[0]).to.equal("stderr blah");82 expect(error.stack).includes("exit code 127");83 });84 return promise;85 });86 it("should silently execute a script with no output from package.json", () => {87 const intercept = xstdout.intercept(true);88 const promise = new LifecycleScripts(Path.join(__dirname, "../fixtures/lifecycle-scripts/f1"))89 .execute("test2", true)90 .then(() => {91 intercept.restore();92 expect(intercept.stdout[3].trim()).to.equal("> No output from f1@1.0.0 npm script test2");93 })94 .catch(err => failRestore(err, intercept));95 return promise;96 });97 it("should set vars from config in package.json", () => {98 const intercept = xstdout.intercept(true);99 const ls = new LifecycleScripts(Path.join(__dirname, "../fixtures/lifecycle-scripts/f3"));100 const promise = ls101 .execute("test", true)102 .then(() => {103 intercept.restore();104 const output = extractOutput(intercept);105 expect(output.stdout).includes("foo-bar");106 })107 .catch(err => failRestore(err, intercept));108 return promise;109 });110 it("should not execute a script not in package.json", () => {111 const promise = new LifecycleScripts({112 dir: Path.join(__dirname, "../fixtures/lifecycle-scripts/f2")...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1define(function(require) {2 var justep = require("$UI/system/lib/justep");3 require("css!$UI/system/components/bootstrap/lib/css/bootstrap").load();4 require("$UI/system/lib/cordova/cordova");require("css!$UI/system/components/justep/cordova/demo/cordova.css").load();5 require("$UI/system/components/justep/cordova/demo/www/cordova-incl");6 7 var Model = function() {8 this.callParent();9 this.on('onLoad', function() {10 var deviceReady = false;11 function interceptBackbutton() {12 eventOutput("Back button intercepted");13 }14 function interceptMenubutton() {15 eventOutput("Menu button intercepted");16 }17 function interceptSearchbutton() {18 eventOutput("Search button intercepted");19 }20 function interceptResume() {21 eventOutput("Resume event intercepted");22 }23 function interceptPause() {24 eventOutput("Pause event intercepted");25 }26 function interceptOnline() {27 eventOutput("Online event intercepted");28 }29 function interceptOffline() {30 eventOutput("Offline event intercepted");31 }32 var eventOutput = function(s) {33 var el = document.getElementById("results");34 el.innerHTML = el.innerHTML + s + "<br/>";35 };36 /**37 * Function called when page has finished loading.38 */39 function init() {40 document.addEventListener("deviceready", function() {41 deviceReady = true;42 console.log("Device="+device.platform+" "+device.version);43 eventOutput("deviceready event: "+device.platform+" "+device.version);44 }, false);45 window.setTimeout(function() {46 if (!deviceReady) {47 alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");48 }49 },5000);50 }51 addListenerToClass('interceptBackButton', function() {52 document.addEventListener('backbutton', interceptBackbutton, false);53 });54 addListenerToClass('stopInterceptOfBackButton', function() {55 document.removeEventListener('backbutton', interceptBackbutton, false);56 });57 addListenerToClass('interceptMenuButton', function() {58 document.addEventListener('menubutton', interceptMenubutton, false);59 });60 addListenerToClass('stopInterceptOfMenuButton', function() {61 document.removeEventListener('menubutton', interceptMenubutton, false);62 });63 addListenerToClass('interceptSearchButton', function() {64 document.addEventListener('searchbutton', interceptSearchbutton, false);65 });66 addListenerToClass('stopInterceptOfSearchButton', function() {67 document.removeEventListener('searchbutton', interceptSearchbutton, false);68 });69 addListenerToClass('interceptResume', function() {70 document.addEventListener('resume', interceptResume, false);71 });72 addListenerToClass('stopInterceptOfResume', function() {73 document.removeEventListener('resume', interceptResume, false);74 });75 addListenerToClass('interceptPause', function() {76 document.addEventListener('pause', interceptPause, false);77 });78 addListenerToClass('stopInterceptOfPause', function() {79 document.removeEventListener('pause', interceptPause, false);80 });81 addListenerToClass('interceptOnline', function() {82 document.addEventListener('online', interceptOnline, false);83 });84 addListenerToClass('stopInterceptOfOnline', function() {85 document.removeEventListener('online', interceptOnline, false);86 });87 addListenerToClass('interceptOffline', function() {88 document.addEventListener('offline', interceptOffline, false);89 });90 addListenerToClass('stopInterceptOfOffline', function() {91 document.removeEventListener('offline', interceptOffline, false);92 });93 addListenerToClass('backBtn', backHome);94 init();95 });96 };97 return Model;...

Full Screen

Full Screen

popup.js

Source:popup.js Github

copy

Full Screen

1'use strict';2const interceptOn = document.getElementById('interceptOn');3const interceptOnLive = document.getElementById('interceptOnLive');4const interceptOff = document.getElementById('interceptOff');5const interceptOnText = document.getElementById('interceptOnText');6const interceptOnLiveText = document.getElementById('interceptOnLiveText');7const interceptOffText = document.getElementById('interceptOffText');8chrome.storage.sync.get('owaIntercept', (data) => {9 console.log('data', data);10 if (data.owaIntercept === "on") {11 interceptOn.checked = true;12 interceptOnLive.checked = false;13 interceptOff.checked = false;14 interceptOnText.style.fontWeight = 'bold';15 interceptOnLive.style.fontWeight = 'normal';16 interceptOffText.style.fontWeight = 'normal';17 } else if (data.owaIntercept === "on_live") {18 interceptOn.checked = false;19 interceptOnLive.checked = true;20 interceptOff.checked = false;21 interceptOnText.style.fontWeight = 'normal';22 interceptOnLiveText.style.fontWeight = 'bold';23 interceptOffText.style.fontWeight = 'normal';24 } else {25 interceptOn.checked = false;26 interceptOnLive.checked = false;27 interceptOff.checked = true;28 interceptOnText.style.fontWeight = 'normal';29 interceptOnLiveText.style.fontWeight = 'normal';30 interceptOffText.style.fontWeight = 'bold';31 }32});33interceptOn.onclick = () => {34 chrome.storage.sync.set({owaIntercept: "on"}, () => {35 console.log('intercept on');36 interceptOn.checked = true;37 interceptOnLive.checked = false;38 interceptOff.checked = false;39 interceptOnText.style.fontWeight = 'bold';40 interceptOnLive.style.fontWeight = 'normal';41 interceptOffText.style.fontWeight = 'normal';42 });43}44interceptOnLive.onclick = () => {45 chrome.storage.sync.set({owaIntercept: "on_live"}, () => {46 console.log('intercept on_live');47 interceptOn.checked = false;48 interceptOnLive.checked = true;49 interceptOff.checked = false;50 interceptOnText.style.fontWeight = 'normal';51 interceptOnLiveText.style.fontWeight = 'bold';52 interceptOffText.style.fontWeight = 'normal';53 });54}55interceptOff.onclick = () => {56 chrome.storage.sync.set({owaIntercept: "off"}, () => {57 console.log('intercept off');58 interceptOn.checked = false;59 interceptOnLive.checked = false;60 interceptOff.checked = true;61 interceptOnText.style.fontWeight = 'normal';62 interceptOnLiveText.style.fontWeight = 'normal';63 interceptOffText.style.fontWeight = 'bold';64 });...

Full Screen

Full Screen

intercept.js

Source:intercept.js Github

copy

Full Screen

1import {assert} from './assert';2import {3 isIntercept, isRecordInvalidIntercept, isRecordRemovedIntercept, Intercept,4 RecordInvalidatedDuringProcessing, RecordRemovedDuringProcessing5} from '../intercept';6describe('record-store/intercept', () => {7 describe('#isIntercept', () => {8 it('should indicate if an object is an instance of an intercept class', () => {9 assert.isTrue(isIntercept(new Intercept()));10 assert.isTrue(isIntercept(new RecordInvalidatedDuringProcessing()));11 assert.isTrue(isIntercept(new RecordRemovedDuringProcessing()));12 assert.isFalse(isIntercept(new Error()));13 assert.isFalse(isIntercept({}));14 assert.isFalse(isIntercept());15 });16 });17 describe('#isRecordInvalidIntercept', () => {18 it('should indicate if an object is an instance of an intercept class', () => {19 assert.isFalse(isRecordInvalidIntercept(new Intercept()));20 assert.isTrue(isRecordInvalidIntercept(new RecordInvalidatedDuringProcessing()));21 assert.isFalse(isRecordInvalidIntercept(new RecordRemovedDuringProcessing()));22 assert.isFalse(isRecordInvalidIntercept(new Error()));23 assert.isFalse(isRecordInvalidIntercept({}));24 assert.isFalse(isRecordInvalidIntercept());25 });26 });27 describe('#isRecordRemovedIntercept', () => {28 it('should indicate if an object is an instance of an intercept class', () => {29 assert.isFalse(isRecordRemovedIntercept(new Intercept()));30 assert.isFalse(isRecordRemovedIntercept(new RecordInvalidatedDuringProcessing()));31 assert.isTrue(isRecordRemovedIntercept(new RecordRemovedDuringProcessing()));32 assert.isFalse(isRecordRemovedIntercept(new Error()));33 assert.isFalse(isRecordRemovedIntercept({}));34 assert.isFalse(isRecordRemovedIntercept());35 });36 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var page = require('webpage').create();2page.onResourceRequested = function (request) {3 console.log('Request ' + JSON.stringify(request, undefined, 4));4};5page.onResourceReceived = function (response) {6 console.log('Receive ' + JSON.stringify(response, undefined, 4));7};8 console.log("Status: " + status);9 if (status === "success") {10 page.render('google.png');11 }12 phantom.exit();13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3 if (err) {4 console.error(err);5 } else {6 console.log(data);7 }8});9test.intercept(data.data.testId, {intercept: 'true'}, function(err, data) {10 if (err) {11 console.error(err);12 } else {13 console.log(data);14 }15});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('WPT_API_KEY');3var options = {4 videoParams: {5 }6};7api.runTest(options, function(err, data) {8 if (err) return console.error(err);9 console.log('Test submitted. Polling for results.');10 api.waitForTestToFinish(data.data.testId, function(err, data) {11 if (err) return console.error(err);12 console.log('Test complete.');13 console.log(data.data);14 });15});16var wpt = require('webpagetest');17var api = new wpt('WPT_API_KEY');18var options = {19 videoParams: {20 }21};22api.runTest(options, function(err, data) {23 if (err) return console.error(err);24 console.log('Test submitted. Polling for results.');25 api.waitForTestToFinish(data.data.testId, function(err, data) {26 if (err) return console.error(err);27 console.log('Test complete.');28 console.log(data.data);29 });30});31var wpt = require('webpagetest');32var api = new wpt('WPT_API_KEY');33var options = {34 videoParams: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var page = require('webpage').create();2page.open(url, function(status) {3 if (status === 'success') {4 page.evaluate(function() {5 var xhr = new XMLHttpRequest();6 xhr.send();7 });8 page.onResourceReceived = function(response) {9 if (response.stage === "end") {10 console.log(response.url + " " + response.status);11 }12 };13 page.onResourceRequested = function(requestData, networkRequest) {14 console.log(requestData.url + " " + requestData.method);15 };16 }17 phantom.exit();18});19var page = require('webpage').create();20page.open(url, function(status) {21 if (status === 'success') {22 page.evaluate(function() {23 var xhr = new XMLHttpRequest();24 xhr.send();25 });26 page.onResourceReceived = function(response) {27 if (response.stage === "end") {28 console.log(response.url + " " + response.status);29 }30 };31 page.onResourceRequested = function(requestData, networkRequest) {32 console.log(requestData.url + " " + requestData.method);33 };34 }35 phantom.exit();36});37var page = require('webpage').create();38var system = require('system');39var url = system.args[1];40page.open(url, function(status) {41 if (status === 'success') {42 page.evaluate(function() {43 var xhr = new XMLHttpRequest();44 xhr.send();45 });46 page.onResourceReceived = function(response) {47 if (response.stage === "end") {48 console.log(response.url + " " + response.status);49 }50 };51 page.onResourceRequested = function(requestData, networkRequest) {52 console.log(requestData.url + " " + requestData.method);53 };54 }55 phantom.exit();56});57var page = require('webpage').create();58var system = require('system');59var url = system.args[1];60page.open(url, function(status) {61 if (status === 'success') {62 page.evaluate(function()

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var wp = new wptoolkit();3 if(err){4 console.log(err);5 return;6 }7 console.log(response);8});9var wptoolkit = require('wptoolkit');10var wp = new wptoolkit();11var options = {12 headers:{13 },14 data:{15 }16}17wp.intercept(options, function(err, response){18 if(err){19 console.log(err);20 return;21 }22 console.log(response);23});24var wptoolkit = require('wptoolkit');25var wp = new wptoolkit();26var options = {27 headers:{28 },29 data:{30 },31}32wp.intercept(options, function(err, response){33 if(err){34 console.log(err);35 return;36 }37 console.log(response);38});39var wptoolkit = require('wptoolkit');40var wp = new wptoolkit();41var options = {42 headers:{43 },44 data:{45 },46}47wp.intercept(options, function(err, response){48 if(err){49 console.log(err);50 return;51 }52 console.log(response);53});54var wptoolkit = require('wptoolkit');55var wp = new wptoolkit();56var options = {57 headers:{58 },59 data:{

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2var wpt = new WebPageTest('www.webpagetest.org','A.4e7d0c2e1b9e9f0d5b0d5d5c5f5f5f5f');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var options = {10 'headers': {11 },12};13wpt.intercept(options, function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19});20var options = {21 'headers': {22 },23};24wpt.intercept(options, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var options = {32 'headers': {33 },34};35wpt.intercept(options, function(err, data) {36 if (err) {37 console.log(err);38 } else {39 console.log(data);40 }41});42var options = {43 'headers': {44 },

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