How to use onloadFn method in Cypress

Best JavaScript code snippet using cypress

list-data-manager-props.test.js

Source:list-data-manager-props.test.js Github

copy

Full Screen

1/**2 * Copyright (C) 2021 Unicorn a.s.3 *4 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public5 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later6 * version.7 *8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied9 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at10 * <https://gnu.org/licenses/> for more details.11 *12 * You may obtain additional information at <https://unicorn.com> or contact Unicorn a.s. at address: V Kapslovne 2767/2,13 * Praha 3, Czech Republic or at the email: info@unicorn.com.14 */15import React from "react";16import UU5 from "uu5g04";17import regeneratorRuntime from "regenerator-runtime";18const { mount, shallow, wait } = UU5.Test.Tools;19const loadTest = async (key, wrapper, childrenFn, onLoadFn, dataProp, dataReturn) => {20 // load render21 expect(childrenFn).toHaveBeenCalledTimes(1);22 let childrenParams1 = childrenFn.mock.calls[0][0];23 expect(childrenParams1).toMatchObject({24 viewState: "load",25 errorState: null,26 errorData: null,27 data: null,28 });29 expect(typeof childrenParams1.handleLoad).toBe("function");30 expect(typeof childrenParams1.handleReload).toBe("function");31 expect(typeof childrenParams1.handleCreate).toBe("function");32 expect(typeof childrenParams1.handleUpdate).toBe("function");33 expect(typeof childrenParams1.handleDelete).toBe("function");34 expect(typeof childrenParams1.handleBulkCreate).toBe("function");35 expect(typeof childrenParams1.handleBulkUpdate).toBe("function");36 expect(typeof childrenParams1.handleBulkDelete).toBe("function");37 // props.onLoad38 expect(onLoadFn).toHaveBeenCalledTimes(1);39 let onLoadFnParams1 = onLoadFn.mock.calls[0][0];40 let onLoadFnResult1 = onLoadFn.mock.results[0].value;41 dataProp === null ? expect(onLoadFnParams1).toBeNull() : expect(onLoadFnParams1).toMatchObject(dataProp);42 expect(onLoadFnResult1).toBeInstanceOf(Promise);43 // waiting for loading44 await onLoadFnResult1;45 wrapper.update();46 // ready render47 expect(childrenFn).toHaveBeenCalledTimes(2);48 let childrenParams2 = childrenFn.mock.calls[1][0];49 expect(childrenParams2).toMatchObject({50 viewState: "ready",51 errorState: null,52 errorData: null,53 data: dataReturn,54 });55 expect(typeof childrenParams2.handleLoad).toBe("function");56 expect(typeof childrenParams2.handleReload).toBe("function");57 expect(typeof childrenParams1.handleCreate).toBe("function");58 expect(typeof childrenParams1.handleUpdate).toBe("function");59 expect(typeof childrenParams1.handleDelete).toBe("function");60 expect(typeof childrenParams1.handleBulkCreate).toBe("function");61 expect(typeof childrenParams1.handleBulkUpdate).toBe("function");62 expect(typeof childrenParams1.handleBulkDelete).toBe("function");63 onLoadFn.mockClear();64 childrenFn.mockClear();65 return childrenParams2;66};67const testHandle = async (68 key,69 wrapper,70 childrenFn,71 fn,72 childrenFnCalledTimes,73 paramsData,74 resultData1,75 resultData276) => {77 expect(fn).toHaveBeenCalledTimes(1);78 let fnParams1 = fn.mock.calls[0][0];79 let fnParams2 = fn.mock.calls[0][1];80 let fnResult = fn.mock.results[0].value;81 expect(fnResult).toBeInstanceOf(Promise);82 if (key === "load" || key === "reload" || key === "create") {83 expect(fnParams1).toMatchObject(paramsData);84 } else if (key === "update") {85 expect(fnParams1).toBe(paramsData.id);86 expect(fnParams2).toMatchObject(paramsData);87 } else if (key === "delete") {88 expect(fnParams1).toBe(paramsData);89 } else if (key === "bulkCreate") {90 expect(fnParams1).toMatchObject(paramsData);91 } else if (key === "bulkUpdate") {92 expect(fnParams1).toMatchObject(paramsData.map((it) => it.id));93 expect(fnParams2).toMatchObject(paramsData);94 } else if (key === "bulkDelete") {95 expect(fnParams1).toMatchObject(paramsData);96 }97 // waiting for fn98 await fnResult;99 wrapper.update();100 // ready || load101 expect(childrenFn).toHaveBeenCalledTimes(childrenFnCalledTimes);102 let childrenParams3 = childrenFn.mock.calls[0][0];103 expect(childrenParams3).toMatchObject({104 viewState: wrapper.props().pessimistic ? key : "ready",105 errorState: null,106 errorData: null,107 data: resultData1,108 });109 expect(typeof childrenParams3.handleLoad).toBe("function");110 expect(typeof childrenParams3.handleReload).toBe("function");111 expect(typeof childrenParams3.handleCreate).toBe("function");112 expect(typeof childrenParams3.handleUpdate).toBe("function");113 expect(typeof childrenParams3.handleDelete).toBe("function");114 expect(typeof childrenParams3.handleBulkCreate).toBe("function");115 expect(typeof childrenParams3.handleBulkUpdate).toBe("function");116 expect(typeof childrenParams3.handleBulkDelete).toBe("function");117 if (resultData2) {118 // load -> ready119 let childrenParams4 = childrenFn.mock.calls[1][0];120 expect(childrenParams4).toMatchObject({121 viewState: "ready",122 errorState: null,123 errorData: null,124 data: resultData2,125 });126 expect(typeof childrenParams4.handleLoad).toBe("function");127 expect(typeof childrenParams4.handleReload).toBe("function");128 expect(typeof childrenParams4.handleCreate).toBe("function");129 expect(typeof childrenParams4.handleUpdate).toBe("function");130 expect(typeof childrenParams4.handleDelete).toBe("function");131 expect(typeof childrenParams4.handleBulkCreate).toBe("function");132 expect(typeof childrenParams4.handleBulkUpdate).toBe("function");133 expect(typeof childrenParams4.handleBulkDelete).toBe("function");134 }135 childrenFn.mockClear();136 fn.mockClear();137};138const data = [139 { id: "1", name: "A" },140 { id: "2", name: "B" },141 { id: "3", name: "C" },142];143const dataProp = { dtoIn: "data" };144const loadFn = () => new Promise((resolve, reject) => resolve(data));145const getChildrenFn = () => "test";146describe(`UU5.Common.ListDataManager onLoad`, () => {147 const loadDataParams = { param: "load" };148 it("optimistic", async () => {149 let onLoadFn = jest.fn().mockImplementation(loadFn);150 let childrenFn = jest.fn().mockImplementation(getChildrenFn);151 const wrapper = mount(152 <UU5.Common.ListDataManager onLoad={onLoadFn} data={dataProp}>153 {childrenFn}154 </UU5.Common.ListDataManager>155 );156 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);157 // handleLoad158 childrenParams.handleLoad(loadDataParams);159 // onLoad160 await testHandle("load", wrapper, childrenFn, onLoadFn, 1, loadDataParams, data);161 });162 it("pessimistic", async () => {163 let onLoadFn = jest.fn().mockImplementation(loadFn);164 let childrenFn = jest.fn().mockImplementation(getChildrenFn);165 const wrapper = mount(166 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} data={dataProp}>167 {childrenFn}168 </UU5.Common.ListDataManager>169 );170 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);171 // handleLoad172 childrenParams.handleLoad(loadDataParams);173 // onLoad174 await testHandle("load", wrapper, childrenFn, onLoadFn, 2, loadDataParams, data, data);175 });176});177describe(`UU5.Common.ListDataManager onReload`, () => {178 const dataReload = [{ id: "2", name: "B" }];179 const reloadDataParams = { param: "reload" };180 const reloadFn = () => new Promise((resolve, reject) => resolve(dataReload));181 it("optimistic", async () => {182 let onLoadFn = jest.fn().mockImplementation(loadFn);183 let childrenFn = jest.fn().mockImplementation(getChildrenFn);184 let onReloadFn = jest.fn().mockImplementation(reloadFn);185 const wrapper = mount(186 <UU5.Common.ListDataManager onLoad={onLoadFn} onReload={onReloadFn} data={dataProp}>187 {childrenFn}188 </UU5.Common.ListDataManager>189 );190 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);191 // handleReload192 childrenParams.handleReload(reloadDataParams);193 // onReload194 await testHandle("reload", wrapper, childrenFn, onReloadFn, 1, reloadDataParams, dataReload);195 });196 it("pessimistic", async () => {197 let onLoadFn = jest.fn().mockImplementation(loadFn);198 let childrenFn = jest.fn().mockImplementation(getChildrenFn);199 let onReloadFn = jest.fn().mockImplementation(reloadFn);200 const wrapper = mount(201 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} onReload={onReloadFn} data={dataProp}>202 {childrenFn}203 </UU5.Common.ListDataManager>204 );205 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);206 // handleReload207 childrenParams.handleReload(reloadDataParams);208 // onReload209 await testHandle("reload", wrapper, childrenFn, onReloadFn, 2, reloadDataParams, data, dataReload);210 });211});212describe(`UU5.Common.ListDataManager onUpdate`, () => {213 const dataUpdate = { id: "1", name: "C" };214 const dataUpdateFromServer = { ...dataUpdate, name: dataUpdate.name + "X" };215 const updateFn = () => new Promise((resolve, reject) => resolve(dataUpdateFromServer));216 it("optimistic", async () => {217 let onLoadFn = jest.fn().mockImplementation(loadFn);218 let childrenFn = jest.fn().mockImplementation(getChildrenFn);219 let onUpdateFn = jest.fn().mockImplementation(updateFn);220 const wrapper = mount(221 <UU5.Common.ListDataManager onLoad={onLoadFn} onUpdate={onUpdateFn}>222 {childrenFn}223 </UU5.Common.ListDataManager>224 );225 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);226 // update227 childrenParams.handleUpdate(dataUpdate.id, dataUpdate);228 // onUpdate229 let expectedData = data.map((it) => (it.id === dataUpdate.id ? dataUpdate : it));230 let expectedFinalData = data.map((it) => (it.id === dataUpdateFromServer.id ? dataUpdateFromServer : it));231 await testHandle("update", wrapper, childrenFn, onUpdateFn, 2, dataUpdate, expectedData, expectedFinalData);232 });233 it("pessimistic", async () => {234 let onLoadFn = jest.fn().mockImplementation(loadFn);235 let childrenFn = jest.fn().mockImplementation(getChildrenFn);236 let onUpdateFn = jest.fn().mockImplementation(updateFn);237 const wrapper = mount(238 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} onUpdate={onUpdateFn}>239 {childrenFn}240 </UU5.Common.ListDataManager>241 );242 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);243 // update244 childrenParams.handleUpdate(dataUpdate.id, dataUpdate);245 // onUpdate246 let expectedFinalData = data.map((it) => (it.id === dataUpdateFromServer.id ? dataUpdateFromServer : it));247 await testHandle("update", wrapper, childrenFn, onUpdateFn, 2, dataUpdate, data, expectedFinalData);248 });249});250describe(`UU5.Common.ListDataManager onCreate`, () => {251 const dataCreate = { id: "4", name: "D" };252 const dataCreateFromServer = { ...dataCreate, name: dataCreate.name + "X" };253 const createFn = () => new Promise((resolve, reject) => resolve(dataCreateFromServer));254 it("optimistic", async () => {255 let onLoadFn = jest.fn().mockImplementation(loadFn);256 let childrenFn = jest.fn().mockImplementation(getChildrenFn);257 let onCreateFn = jest.fn().mockImplementation(createFn);258 const wrapper = mount(259 <UU5.Common.ListDataManager onLoad={onLoadFn} onCreate={onCreateFn}>260 {childrenFn}261 </UU5.Common.ListDataManager>262 );263 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);264 // create265 childrenParams.handleCreate(dataCreate);266 // onCreate267 let expectedData = [...data, dataCreate];268 let expectedFinalData = [...data, dataCreateFromServer];269 await testHandle("create", wrapper, childrenFn, onCreateFn, 2, dataCreate, expectedData, expectedFinalData);270 });271 it("pessimistic", async () => {272 let onLoadFn = jest.fn().mockImplementation(loadFn);273 let childrenFn = jest.fn().mockImplementation(getChildrenFn);274 let onCreateFn = jest.fn().mockImplementation(createFn);275 const wrapper = mount(276 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} onCreate={onCreateFn}>277 {childrenFn}278 </UU5.Common.ListDataManager>279 );280 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);281 // create282 childrenParams.handleCreate(dataCreate);283 // onCreate284 let expectedFinalData = [...data, dataCreateFromServer];285 await testHandle("create", wrapper, childrenFn, onCreateFn, 2, dataCreate, data, expectedFinalData);286 });287});288describe(`UU5.Common.ListDataManager onDelete`, () => {289 const dataDelete = { id: "1", name: "A" };290 const deleteFn = () => new Promise((resolve, reject) => resolve(dataDelete));291 it("optimistic", async () => {292 let onLoadFn = jest.fn().mockImplementation(loadFn);293 let childrenFn = jest.fn().mockImplementation(getChildrenFn);294 let onDeleteFn = jest.fn().mockImplementation(deleteFn);295 const wrapper = mount(296 <UU5.Common.ListDataManager onLoad={onLoadFn} onDelete={onDeleteFn}>297 {childrenFn}298 </UU5.Common.ListDataManager>299 );300 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);301 // delete302 childrenParams.handleDelete(dataDelete.id);303 // onDelete304 let expectedData = data.filter((it) => it.id !== dataDelete.id);305 await testHandle("delete", wrapper, childrenFn, onDeleteFn, 2, dataDelete.id, expectedData);306 });307 it("pessimistic", async () => {308 let onLoadFn = jest.fn().mockImplementation(loadFn);309 let childrenFn = jest.fn().mockImplementation(getChildrenFn);310 let onDeleteFn = jest.fn().mockImplementation(deleteFn);311 const wrapper = mount(312 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} onDelete={onDeleteFn}>313 {childrenFn}314 </UU5.Common.ListDataManager>315 );316 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);317 // delete318 childrenParams.handleDelete(dataDelete.id);319 // onDelete320 let expectedData = data.filter((it) => it.id !== dataDelete.id);321 await testHandle("delete", wrapper, childrenFn, onDeleteFn, 2, dataDelete.id, data, expectedData);322 });323});324describe(`UU5.Common.ListDataManager onBulkUpdate`, () => {325 const dataUpdate = [326 { id: "3", name: "A" },327 { id: "1", name: "C" },328 ];329 const dataUpdateFromServer = dataUpdate.map((it) => ({ ...it, name: it.name + "X" }));330 const updateFn = () => new Promise((resolve, reject) => resolve(dataUpdateFromServer));331 it("optimistic", async () => {332 let onLoadFn = jest.fn().mockImplementation(loadFn);333 let childrenFn = jest.fn().mockImplementation(getChildrenFn);334 let onBulkUpdateFn = jest.fn().mockImplementation(updateFn);335 const wrapper = mount(336 <UU5.Common.ListDataManager onLoad={onLoadFn} onBulkUpdate={onBulkUpdateFn}>337 {childrenFn}338 </UU5.Common.ListDataManager>339 );340 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);341 // bulkUpdate342 childrenParams.handleBulkUpdate(343 dataUpdate.map((it) => it.id),344 dataUpdate345 );346 // onBulkUpdate347 let expectedData = data.map((it) => dataUpdate.find((upIt) => upIt.id === it.id) || it);348 let expectedFinalData = data.map((it) => dataUpdateFromServer.find((upIt) => upIt.id === it.id) || it);349 await testHandle("bulkUpdate", wrapper, childrenFn, onBulkUpdateFn, 2, dataUpdate, expectedData, expectedFinalData);350 });351 it("pessimistic", async () => {352 let onLoadFn = jest.fn().mockImplementation(loadFn);353 let childrenFn = jest.fn().mockImplementation(getChildrenFn);354 let onBulkUpdateFn = jest.fn().mockImplementation(updateFn);355 const wrapper = mount(356 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} onBulkUpdate={onBulkUpdateFn}>357 {childrenFn}358 </UU5.Common.ListDataManager>359 );360 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);361 // bulkUpdate362 childrenParams.handleBulkUpdate(363 dataUpdate.map((it) => it.id),364 dataUpdate365 );366 // onBulkUpdate367 let expectedFinalData = data.map((it) => dataUpdateFromServer.find((upIt) => upIt.id === it.id) || it);368 await testHandle("bulkUpdate", wrapper, childrenFn, onBulkUpdateFn, 2, dataUpdate, data, expectedFinalData);369 });370});371describe(`UU5.Common.ListDataManager onBulkCreate`, () => {372 const dataCreate = [373 { id: "4", name: "D" },374 { id: "5", name: "E" },375 ];376 const dataCreateFromServer = dataCreate.map((it) => ({ ...it, name: it.name + "X" }));377 const createFn = () => new Promise((resolve, reject) => resolve(dataCreateFromServer));378 it("optimistic", async () => {379 let onLoadFn = jest.fn().mockImplementation(loadFn);380 let childrenFn = jest.fn().mockImplementation(getChildrenFn);381 let onBulkCreateFn = jest.fn().mockImplementation(createFn);382 const wrapper = mount(383 <UU5.Common.ListDataManager onLoad={onLoadFn} onBulkCreate={onBulkCreateFn}>384 {childrenFn}385 </UU5.Common.ListDataManager>386 );387 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);388 // bulkCreate389 childrenParams.handleBulkCreate(dataCreate);390 // onBulkCreate391 let expectedData = [...data, ...dataCreate];392 let expectedFinalData = [...data, ...dataCreateFromServer];393 await testHandle("bulkCreate", wrapper, childrenFn, onBulkCreateFn, 2, dataCreate, expectedData, expectedFinalData);394 });395 it("pessimistic", async () => {396 let onLoadFn = jest.fn().mockImplementation(loadFn);397 let childrenFn = jest.fn().mockImplementation(getChildrenFn);398 let onBulkCreateFn = jest.fn().mockImplementation(createFn);399 const wrapper = mount(400 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} onBulkCreate={onBulkCreateFn}>401 {childrenFn}402 </UU5.Common.ListDataManager>403 );404 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);405 // bulkCreate406 childrenParams.handleBulkCreate(dataCreate);407 // onBulkCreate408 let expectedFinalData = [...data, ...dataCreateFromServer];409 await testHandle("bulkCreate", wrapper, childrenFn, onBulkCreateFn, 2, dataCreate, data, expectedFinalData);410 });411});412describe(`UU5.Common.ListDataManager onBulkDelete`, () => {413 const dataDelete = [414 { id: "3", name: "C" },415 { id: "1", name: "A" },416 ];417 const deleteFn = () => new Promise((resolve, reject) => resolve(dataDelete));418 it("optimistic", async () => {419 let onLoadFn = jest.fn().mockImplementation(loadFn);420 let childrenFn = jest.fn().mockImplementation(getChildrenFn);421 let onBulkDeleteFn = jest.fn().mockImplementation(deleteFn);422 const wrapper = mount(423 <UU5.Common.ListDataManager onLoad={onLoadFn} onBulkDelete={onBulkDeleteFn}>424 {childrenFn}425 </UU5.Common.ListDataManager>426 );427 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);428 // bulkDelete429 let ids = dataDelete.map((it) => it.id);430 childrenParams.handleBulkDelete(ids);431 // onBulkDelete432 let expectedData = data.filter((it) => !dataDelete.some((upIt) => upIt.id === it.id));433 await testHandle("bulkDelete", wrapper, childrenFn, onBulkDeleteFn, 2, ids, expectedData);434 });435 it("pessimistic", async () => {436 let onLoadFn = jest.fn().mockImplementation(loadFn);437 let childrenFn = jest.fn().mockImplementation(getChildrenFn);438 let onBulkDeleteFn = jest.fn().mockImplementation(deleteFn);439 const wrapper = mount(440 <UU5.Common.ListDataManager pessimistic onLoad={onLoadFn} onBulkDelete={onBulkDeleteFn}>441 {childrenFn}442 </UU5.Common.ListDataManager>443 );444 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);445 // bulkDelete446 let ids = dataDelete.map((it) => it.id);447 childrenParams.handleBulkDelete(ids);448 // onBulkDelete449 let expectedData = data.filter((it) => !dataDelete.some((upIt) => upIt.id === it.id));450 await testHandle("bulkDelete", wrapper, childrenFn, onBulkDeleteFn, 2, ids, data, expectedData);451 });...

Full Screen

Full Screen

data-manager-props.test.js

Source:data-manager-props.test.js Github

copy

Full Screen

1/**2 * Copyright (C) 2021 Unicorn a.s.3 *4 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public5 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later6 * version.7 *8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied9 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at10 * <https://gnu.org/licenses/> for more details.11 *12 * You may obtain additional information at <https://unicorn.com> or contact Unicorn a.s. at address: V Kapslovne 2767/2,13 * Praha 3, Czech Republic or at the email: info@unicorn.com.14 */15import regeneratorRuntime from "regenerator-runtime";16import React from "react";17import UU5 from "uu5g04";18const { mount, shallow, wait } = UU5.Test.Tools;19const loadTest = async (key, wrapper, childrenFn, onLoadFn, dataProp, dataReturn) => {20 // load render21 expect(childrenFn).toHaveBeenCalledTimes(1);22 let childrenParams1 = childrenFn.mock.calls[0][0];23 expect(childrenParams1).toMatchObject({24 viewState: "load",25 errorState: null,26 errorData: null,27 data: null,28 });29 expect(typeof childrenParams1.handleLoad).toBe("function");30 expect(typeof childrenParams1.handleReload).toBe("function");31 expect(typeof childrenParams1.handleUpdate).toBe("function");32 // props.onLoad33 expect(onLoadFn).toHaveBeenCalledTimes(1);34 let onLoadFnParams1 = onLoadFn.mock.calls[0][0];35 let onLoadFnResult1 = onLoadFn.mock.results[0].value;36 dataProp === null ? expect(onLoadFnParams1).toBeNull() : expect(onLoadFnParams1).toMatchObject(dataProp);37 expect(onLoadFnResult1).toBeInstanceOf(Promise);38 // waiting for loading39 await onLoadFnResult1;40 wrapper.update();41 // ready render42 expect(childrenFn).toHaveBeenCalledTimes(2);43 let childrenParams2 = childrenFn.mock.calls[1][0];44 expect(childrenParams2).toMatchObject({45 viewState: "ready",46 errorState: null,47 errorData: null,48 data: dataReturn,49 });50 expect(typeof childrenParams2.handleLoad).toBe("function");51 expect(typeof childrenParams2.handleReload).toBe("function");52 expect(typeof childrenParams2.handleUpdate).toBe("function");53 return childrenParams2;54};55const testHandle = async (key, wrapper, childrenFn, fn, calledTimes, paramsData, resultData1, resultData2) => {56 expect(fn).toHaveBeenCalledTimes(calledTimes);57 let fnParams = fn.mock.calls[calledTimes - 1][0];58 let fnResult = fn.mock.results[calledTimes - 1].value;59 expect(fnParams).toMatchObject(paramsData);60 expect(fnResult).toBeInstanceOf(Promise);61 // waiting for fn62 await fnResult;63 wrapper.update();64 // load -> ready -> ready || load65 expect(childrenFn).toHaveBeenCalledTimes(resultData2 ? 4 : 3);66 let childrenParams3 = childrenFn.mock.calls[2][0];67 expect(childrenParams3).toMatchObject({68 viewState: resultData2 ? key : "ready",69 errorState: null,70 errorData: null,71 data: resultData1,72 });73 expect(typeof childrenParams3.handleLoad).toBe("function");74 expect(typeof childrenParams3.handleReload).toBe("function");75 expect(typeof childrenParams3.handleUpdate).toBe("function");76 if (resultData2) {77 // load -> ready -> load -> ready78 let childrenParams4 = childrenFn.mock.calls[3][0];79 expect(childrenParams4).toMatchObject({80 viewState: "ready",81 errorState: null,82 errorData: null,83 data: resultData2,84 });85 expect(typeof childrenParams4.handleLoad).toBe("function");86 expect(typeof childrenParams4.handleReload).toBe("function");87 expect(typeof childrenParams4.handleUpdate).toBe("function");88 }89};90const data = { name: "AppName" };91const dataProp = { dtoIn: "data" };92const loadFn = () => new Promise((resolve, reject) => resolve(data));93const getChildrenFn = () => "test";94describe(`UU5.Common.DataManager onLoad`, () => {95 const loadDataParams = { param: "load" };96 it("optimistic", async () => {97 let onLoadFn = jest.fn().mockImplementation(loadFn);98 let childrenFn = jest.fn().mockImplementation(getChildrenFn);99 const wrapper = mount(100 <UU5.Common.DataManager onLoad={onLoadFn} data={dataProp}>101 {childrenFn}102 </UU5.Common.DataManager>103 );104 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);105 // handleLoad106 childrenParams.handleLoad(loadDataParams);107 // onLoad108 await testHandle("load", wrapper, childrenFn, onLoadFn, 2, loadDataParams, data);109 });110 it("pessimistic", async () => {111 let onLoadFn = jest.fn().mockImplementation(loadFn);112 let childrenFn = jest.fn().mockImplementation(getChildrenFn);113 const wrapper = mount(114 <UU5.Common.DataManager pessimistic onLoad={onLoadFn} data={dataProp}>115 {childrenFn}116 </UU5.Common.DataManager>117 );118 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);119 // handleLoad120 childrenParams.handleLoad(loadDataParams);121 // onLoad122 await testHandle("load", wrapper, childrenFn, onLoadFn, 2, loadDataParams, data, data);123 });124});125describe(`UU5.Common.DataManager onReload`, () => {126 const dataReload = { name: "AppNameReload" };127 const reloadDataParams = { param: "reload" };128 const reloadFn = () => new Promise((resolve, reject) => resolve(dataReload));129 it("optimistic", async () => {130 let onLoadFn = jest.fn().mockImplementation(loadFn);131 let childrenFn = jest.fn().mockImplementation(getChildrenFn);132 let onReloadFn = jest.fn().mockImplementation(reloadFn);133 const wrapper = mount(134 <UU5.Common.DataManager onLoad={onLoadFn} onReload={onReloadFn} data={dataProp}>135 {childrenFn}136 </UU5.Common.DataManager>137 );138 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);139 // handleReload140 childrenParams.handleReload(reloadDataParams);141 // onReload142 await testHandle("reload", wrapper, childrenFn, onReloadFn, 1, reloadDataParams, dataReload);143 });144 it("pessimistic", async () => {145 let onLoadFn = jest.fn().mockImplementation(loadFn);146 let childrenFn = jest.fn().mockImplementation(getChildrenFn);147 let onReloadFn = jest.fn().mockImplementation(reloadFn);148 const wrapper = mount(149 <UU5.Common.DataManager pessimistic onLoad={onLoadFn} onReload={onReloadFn} data={dataProp}>150 {childrenFn}151 </UU5.Common.DataManager>152 );153 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, dataProp, data);154 // handleReload155 childrenParams.handleReload(reloadDataParams);156 // onReload157 await testHandle("reload", wrapper, childrenFn, onReloadFn, 1, reloadDataParams, data, dataReload);158 });159});160describe(`UU5.Common.DataManager onUpdate`, () => {161 const dataUpdate = { name: "AppNameUpdate" };162 const updateFn = () => new Promise((resolve, reject) => resolve(dataUpdate));163 it("optimistic", async () => {164 let onLoadFn = jest.fn().mockImplementation(loadFn);165 let childrenFn = jest.fn().mockImplementation(getChildrenFn);166 let onUpdateFn = jest.fn().mockImplementation(updateFn);167 const wrapper = mount(168 <UU5.Common.DataManager onLoad={onLoadFn} onUpdate={onUpdateFn}>169 {childrenFn}170 </UU5.Common.DataManager>171 );172 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);173 // update174 childrenParams.handleUpdate(dataUpdate);175 // onUpdate176 await testHandle("update", wrapper, childrenFn, onUpdateFn, 1, dataUpdate, dataUpdate);177 });178 it("pessimistic", async () => {179 let onLoadFn = jest.fn().mockImplementation(loadFn);180 let childrenFn = jest.fn().mockImplementation(getChildrenFn);181 let onUpdateFn = jest.fn().mockImplementation(updateFn);182 const wrapper = mount(183 <UU5.Common.DataManager pessimistic onLoad={onLoadFn} onUpdate={onUpdateFn}>184 {childrenFn}185 </UU5.Common.DataManager>186 );187 let childrenParams = await loadTest("onLoad", wrapper, childrenFn, onLoadFn, null, data);188 // update189 childrenParams.handleUpdate(dataUpdate);190 // onUpdate191 await testHandle("update", wrapper, childrenFn, onUpdateFn, 1, dataUpdate, data, dataUpdate);192 });...

Full Screen

Full Screen

simpleSpec.js

Source:simpleSpec.js Github

copy

Full Screen

1/*jshint browser: true, laxbreak: true, plusplus: false, undef: true, unused: true, smarttabs: true */2/*global require */3define(4 [5 'src/conditional'6 ], function (conditional) {7 'use strict';8 describe('conditional.js', function() {9 it('should load', function() {10 expect(conditional).toBeDefined();11 });12 function mockNormalize(moduleName) {13 return moduleName;14 }15 describe('normalize()', function () {16 it('should turn "load" string into an array of one string', function () {17 var obj = {18 test: "boolVar",19 load: "lib/some_polyfill"20 };21 var input = JSON.stringify(obj);22 var normInput = conditional.normalize(input, mockNormalize);23 expect(typeof normInput).toBe('string');24 var parsed = JSON.parse(normInput);25 expect(typeof parsed.load).toBeDefined('object');26 expect(parsed.load.length).toBe(1);27 expect(parsed.load[0]).toBe(obj.load);28 });29 it('should call provided normalize function on every load entry', function () {30 var spyNormalize, obj, input, normInput, parsed;31 spyNormalize = jasmine.createSpy('normalize');32 spyNormalize.and.callFake(function (instr) {33 return instr.toUpperCase();34 });35 obj = {36 test: "numberFn",37 load: ["lib/mod1", "lib/mod2", 'lib/mod3']38 };39 input = JSON.stringify(obj);40 normInput = conditional.normalize(input, spyNormalize);41 expect(typeof normInput).toBe('string');42 parsed = JSON.parse(normInput);43 expect(typeof parsed.load).toBeDefined('object');44 expect(parsed.load.length).toBe(3);45 expect(parsed.load[0]).toBe(obj.load[0].toUpperCase());46 expect(parsed.load[1]).toBe(obj.load[1].toUpperCase());47 expect(parsed.load[2]).toBe(obj.load[2].toUpperCase());48 expect(spyNormalize).toHaveBeenCalledWith("lib/mod1");49 expect(spyNormalize).toHaveBeenCalledWith("lib/mod2");50 expect(spyNormalize).toHaveBeenCalledWith("lib/mod3");51 });52 });53 describe('load()', function () {54 it('should pick from an array of choices when given a function to invoke', function() {55 var onLoadFn, loadedModule, requireFn, obj, input, numberToReturn, requireConfig;56 obj = {57 test: "numberFn",58 load: ["lib/mod1", "lib/mod2", 'lib/mod3']59 };60 input = JSON.stringify(obj);61 numberToReturn = 0;62 requireConfig = {63 config: {64 conditional: {65 numberFn: jasmine.createSpy('numberFn').and.callFake(66 function () {67 return numberToReturn;68 }69 )70 }71 }72 };73 requireFn = jasmine.createSpy('requireFn').and.callFake(74 function (deps, callbackFn) {75 callbackFn(loadedModule);76 }77 );78 loadedModule = { foo: 'bar' };79 onLoadFn = jasmine.createSpy('onLoadFn');80 conditional.load(input, requireFn, onLoadFn, requireConfig);81 expect(requireConfig.config.conditional.numberFn).toHaveBeenCalled();82 expect(requireFn).toHaveBeenCalled();83 expect(requireFn.calls.mostRecent().args[0]).toEqual([ obj.load[numberToReturn] ]);84 expect(onLoadFn).toHaveBeenCalledWith(loadedModule);85 requireFn.calls.reset();86 onLoadFn.calls.reset();87 requireConfig.config.conditional.numberFn.calls.reset();88 numberToReturn = 2;89 loadedModule = [ 'brick', 'bat' ];90 conditional.load(input, requireFn, onLoadFn, requireConfig);91 expect(requireConfig.config.conditional.numberFn).toHaveBeenCalled();92 expect(requireFn).toHaveBeenCalled();93 expect(requireFn.calls.mostRecent().args[0]).toEqual([ obj.load[numberToReturn] ]);94 expect(onLoadFn).toHaveBeenCalledWith(loadedModule);95 });96 it('should load/not load a file in the "load" key when given a boolean var', function() {97 var onLoadFn;98 var loadedModule;99 var requireFn;100 var obj, input, requireConfig;101 obj = {102 test: 'boolProp',103 load: ["lib/mod1"]104 };105 input = JSON.stringify(obj);106 requireConfig = {107 config: {108 conditional: {109 boolProp: false110 }111 }112 };113 requireFn = jasmine.createSpy('requireFn1').and.callFake(114 function (deps, callbackFn) {115 callbackFn(loadedModule);116 }117 );118 loadedModule = { foo: 'bar' };119 onLoadFn = jasmine.createSpy('onLoadFn1');120 onLoadFn.error = function () {121 throw arguments;122 };123 conditional.load(input, requireFn, onLoadFn, requireConfig);124 expect(requireFn).not.toHaveBeenCalled();125 expect(onLoadFn).toHaveBeenCalledWith();126 requireFn.calls.reset();127 onLoadFn.calls.reset();128 requireConfig.config.conditional.boolProp = true;129 input = JSON.stringify(obj);130 conditional.load(input, requireFn, onLoadFn, requireConfig);131 expect(requireFn).toHaveBeenCalled();132 expect(requireFn.calls.mostRecent().args[0]).toEqual( obj.load );133 expect(onLoadFn).toHaveBeenCalledWith(loadedModule);134 });135 it('should treat a test function returning boolean as a 0/1 index if a load array is given', function () {136 var onLoadFn, loadedModule, requireFn, obj, input, boolToReturn, requireConfig;137 obj = {138 test: "boolFn",139 load: ["lib/mod1", "lib/mod2", 'lib/mod3']140 };141 input = JSON.stringify(obj);142 boolToReturn = false;143 requireConfig = {144 config: {145 conditional: {146 boolFn: jasmine.createSpy('boolFn').and.callFake(147 function () {148 return boolToReturn;149 }150 )151 }152 }153 };154 requireFn = jasmine.createSpy('requireFn').and.callFake(155 function (deps, callbackFn) {156 callbackFn(loadedModule);157 }158 );159 loadedModule = { foo: 'bar' };160 onLoadFn = jasmine.createSpy('onLoadFn');161 conditional.load(input, requireFn, onLoadFn, requireConfig);162 expect(requireConfig.config.conditional.boolFn).toHaveBeenCalled();163 expect(requireFn).toHaveBeenCalled();164 expect(requireFn.calls.mostRecent().args[0]).toEqual([ obj.load[0] ]);165 expect(onLoadFn).toHaveBeenCalledWith(loadedModule);166 requireFn.calls.reset();167 onLoadFn.calls.reset();168 requireConfig.config.conditional.boolFn.calls.reset();169 boolToReturn = true;170 loadedModule = [ 'brick', 'bat' ];171 conditional.load(input, requireFn, onLoadFn, requireConfig);172 expect(requireConfig.config.conditional.boolFn).toHaveBeenCalled();173 expect(requireFn).toHaveBeenCalled();174 expect(requireFn.calls.mostRecent().args[0]).toEqual([ obj.load[1] ]);175 expect(onLoadFn).toHaveBeenCalledWith(loadedModule);176 });177 it('should not do anything if isBuild is true', function () {178 var requireFn = jasmine.createSpy('requireFn1');179 var onLoadFn = jasmine.createSpy('onLoadFn1');180 conditional.load('{"test": "thing","load":"bogus"}', requireFn, onLoadFn, {isBuild:true});181 expect(requireFn).not.toHaveBeenCalled();182 expect(onLoadFn).toHaveBeenCalledWith();183 });184 });185 });186 }...

Full Screen

Full Screen

titleImg.js

Source:titleImg.js Github

copy

Full Screen

...11 //注册裁剪组件12 cropper = $('#main__photo').cropbox(options);13 var onloadFn = cropper.image.onload;14 cropper.image.onload = function () {15 onloadFn();16 //初始化头像17 imgHtml();18 }19 })20 // 完成上传 图片为base6421 $("#main__submit").click(function () {22 if (base === "") {23 base ==="";24 var formData = new FormData();25 formData.append('photo', document.getElementById('upload').files[0]);26 $.ajax({27 url: "/file/upload",28 contentType: "multipart/form-data",29 type: 'POST',30 cache: false, //不必须31 data: {formData,"userId":$("#userInfoId").val()},32 processData: false,//必须33 contentType: false,//必须34 success: function (data) {35 $(".titleImg img").attr("src", data)36 $(".clear-list img").attr("src", data)37 }38 });39 }else {40 base ==="";41 $.ajax({42 url: "/file/uploads",43 type: 'POST',44 cache: false, //不必须45 data: {"base": base,"userId":$("#userInfoId").val()},46 success: function (data) {47 $(".titleImg img").attr("src", data)48 $(".clear-list img").attr("src", data)49 }50 })51 }52 var ahis = $(this);53 ahis.hide();54 // $.post("/url", {data: cropper.getDataURL()}, function(data) {55 ahis.show();56 ahis.html("OK");57 // });58 })59 Webcam.set({60 width: 320,61 height: 240,62 image_format: 'jpeg',63 jpeg_quality: 9064 });65 Webcam.attach('#open-power');66 const options = {67 thumbBox: '.main__upload-left--thumbBox',68 spinner: '.main__upload-left--spinner',69 imgSrc: ''70 }71 let cropper = null;72 $("#main__confirm").click(function () {73 Webcam.freeze();74 Webcam.snap(function (data_uri) {75 options.imgSrc = data_uri;76 //注册裁剪组件77 cropper = $('#main__photo').cropbox(options);78 var onloadFn = cropper.image.onload;79 cropper.image.onload = function () {80 onloadFn();81 //初始化头像82 imgHtml();83 }84 });85 })86 $("#main__rop").on('click', function () {87 imgHtml();88 })89 $('#main__boost').on('click', function () {90 cropper.zoomIn();91 })92 $('#main__lessen').on('click', function () {93 cropper.zoomOut();94 })95 function imgHtml() {96 //加载右侧图像97 var img = cropper.getDataURL();98 base = img;99 var imgObj = $('.main__upload-right');100 imgObj.html('');101 imgObj.append('<img class="main__lager-photo" src="' + img + '" align="absmiddle"><p>180px*180px</p>');102 imgObj.append('<img class="main__small-photo" src="' + img + '" align="absmiddle"><p>128px*128px</p>');103 imgObj.append('<img class="main__mini-photo" src="' + img + '" align="absmiddle"><p>64px*64px</p>');104 $('#main__submit').show();105 }106 //默认加载107 options.imgSrc = $(".titleImg img").attr("src");108 //注册裁剪组件109 cropper = $('#main__photo').cropbox(options);110 var onloadFn = cropper.image.onload;111 cropper.image.onload = function () {112 onloadFn();113 //初始化头像114 imgHtml();115 }...

Full Screen

Full Screen

javascriptLoader.js

Source:javascriptLoader.js Github

copy

Full Screen

...20 scriptTag.onload = function() {21 console.debug(`Loaded script ${script['name']} from ${script['url']}`);22 var onloadFn = script['onload'];23 if (onloadFn) {24 onloadFn();25 }26 if (scriptList.length > 0) {27 JavascriptLoader.loadScript(scriptList);28 }29 };30 scriptTag.onerror = function() {31 console.error(`Failed to load script ${script['name']} from ${script['url']}`);32 var onerrorFn = script['onerror'];33 if (onerrorFn) {34 onerrorFn();35 }36 };37 document.body.appendChild(scriptTag);38 }39 else {40 console.debug(`Script ${script['name']} from ${script['url']} is already loaded.`);41 var onloadFn = script['onload'];42 if (onloadFn) {43 onloadFn();44 }45 if (scriptList.length > 0) {46 JavascriptLoader.loadScript(scriptList);47 }48 }49 }50 //Dynamically unloads/removes <script> tags. See loadScript method for the definition of the objects provided in scriptList parameter.51 static unloadScript(scriptList) {52 scriptList.forEach(function(script, index) {53 var scriptTag = document.querySelector(`script#${script['name']}`);54 if (scriptTag) {55 document.body.removeChild(scriptTag);56 console.debug(`Unloaded script ${script['name']} from ${script['url']}`);57 }...

Full Screen

Full Screen

PhotoPicker-test.js

Source:PhotoPicker-test.js Github

copy

Full Screen

1import React, { Component } from 'react';2import PhotoPicker from '../../src/Widget/PhotoPicker';3import Picker from '../../src/Widget/Picker';4describe('PhotoPicker test', () => {5 describe('render test', () => {6 test('render with previewSrc', () => {7 const wrapper = shallow(<PhotoPicker/>);8 wrapper.setState({previewSrc: true});9 expect(wrapper).toMatchSnapshot();10 });11 test('render without previewSrc', () => {12 const wrapper = shallow(<PhotoPicker/>);13 wrapper.setState({previewSrc: false});14 expect(wrapper).toMatchSnapshot();15 });16 });17 describe('interaction test', () => {18 test('Picker pick test', () => {19 const spyon = jest.spyOn(PhotoPicker.prototype, 'handlePick').mockImplementationOnce(() => {20 return;21 });22 const wrapper = shallow(<PhotoPicker/>);23 wrapper.find(Picker).simulate('pick');24 expect(spyon).toBeCalled();25 });26 });27 describe('hanldePick test', () => {28 test('happy case', () => {29 const spyon = jest.spyOn(FileReader.prototype, 'readAsDataURL').mockImplementationOnce(() => {30 return;31 });32 const onPickFn = jest.fn();33 const onLoadFn = jest.fn();34 const data = {35 file: 'file',36 name: 'name',37 size: 'size',38 type: 'type'39 }40 const props = {41 preview: true,42 onPick: onPickFn,43 onLoad: onLoadFn44 }45 const wrapper = shallow(<PhotoPicker/>);46 const photoPicker = wrapper.instance();47 wrapper.setProps(props);48 photoPicker.handlePick(data);49 expect(onPickFn).toBeCalled();50 expect(spyon).toBeCalledWith('file');51 spyon.mockClear();52 });53 test('with no onPick and no preview', () => {54 const spyon = jest.spyOn(FileReader.prototype, 'readAsDataURL').mockImplementationOnce(() => {55 return;56 });57 const onLoadFn = jest.fn();58 const data = {59 file: 'file',60 name: 'name',61 size: 'size',62 type: 'type'63 }64 const props = {65 preview: false,66 onLoad: onLoadFn67 }68 const wrapper = shallow(<PhotoPicker/>);69 const photoPicker = wrapper.instance();70 wrapper.setProps(props);71 photoPicker.handlePick(data);72 expect(spyon).not.toBeCalledWith('file');73 spyon.mockClear();74 });75 });...

Full Screen

Full Screen

TextPicker-test.js

Source:TextPicker-test.js Github

copy

Full Screen

1import React, { Component } from 'react';2import TextPicker from '../../src/Widget/TextPicker';3import Picker from '../../src/Widget/Picker';4describe('TextPicker test', () => {5 describe('render test', () => {6 test('render with previewSrc', () => {7 const wrapper = shallow(<TextPicker/>);8 wrapper.setState({previewText: true});9 expect(wrapper).toMatchSnapshot();10 });11 test('render without previewText', () => {12 const wrapper = shallow(<TextPicker/>);13 wrapper.setState({previewText: false});14 expect(wrapper).toMatchSnapshot();15 });16 });17 describe('interaction test', () => {18 test('Picker pick test', () => {19 const spyon = jest.spyOn(TextPicker.prototype, 'handlePick').mockImplementationOnce(() => {20 return;21 });22 const wrapper = shallow(<TextPicker/>);23 wrapper.find(Picker).simulate('pick');24 expect(spyon).toBeCalled();25 });26 });27 describe('hanldePick test', () => {28 test('happy case', () => {29 const spyon = jest.spyOn(FileReader.prototype, 'readAsText').mockImplementationOnce(() => {30 return;31 });32 const onPickFn = jest.fn();33 const onLoadFn = jest.fn();34 const data = {35 file: 'file',36 name: 'name',37 size: 'size',38 type: 'type'39 }40 const props = {41 preview: true,42 onPick: onPickFn,43 onLoad: onLoadFn44 }45 const wrapper = shallow(<TextPicker/>);46 const textPicker = wrapper.instance();47 wrapper.setProps(props);48 textPicker.handlePick(data);49 expect(onPickFn).toBeCalled();50 expect(spyon).toBeCalledWith('file');51 spyon.mockClear();52 });53 test('with no onPick and no preview', () => {54 const spyon = jest.spyOn(FileReader.prototype, 'readAsText').mockImplementationOnce(() => {55 return;56 });57 const onLoadFn = jest.fn();58 const data = {59 file: 'file',60 name: 'name',61 size: 'size',62 type: 'type'63 }64 const props = {65 preview: false,66 onLoad: onLoadFn67 }68 const wrapper = shallow(<TextPicker/>);69 const textPicker = wrapper.instance();70 wrapper.setProps(props);71 textPicker.handlePick(data);72 expect(spyon).not.toBeCalledWith('file');73 spyon.mockClear();74 });75 });...

Full Screen

Full Screen

jsonp.js

Source:jsonp.js Github

copy

Full Screen

1var isIE = !!window.ActiveXObject;2JSONP = {3 start: null,4 end:null,5 getScript: function (url, callback, scriptId) {//script脚本延迟载入工具6 var script = document.createElement('script');7 script.type = 'text/javascript';8 if (scriptId != undefined && typeof scriptId == 'string') {9 script.setAttribute('id', scriptId);10 }11 var onloadfn = callback;//回调函数12 if (isIE) { //for IE13 script.onreadystatechange = function () {14 if (script.readyState == 'loaded' || script.readyState == 'complete') {15 script.onreadystatechange = null;16 if (onloadfn) {17 setTimeout(onloadfn, 100);18 }19 }20 };21 } else {22 script.onerror = function () {23 script.onerror = null;24 if (onloadfn)25 onloadfn();26 };27 }28 script.src = url;29 document.body.appendChild(script);30 },31 getJSONP: function (obj) { //跨域通信,script标签方式,兼容IE和FF\CHROME32 if (JSONP.start) {33 JSONP.start();34 }35 var url = obj.url,36 success = obj.success,37 error = obj.error;38 var defCallfn = obj.callbackName;39 if (url.indexOf('?') > -1) {40 url += '&';41 } else {42 url += '?';43 }44 if (!defCallfn)45 defCallfn = "fun" + uuid();46 url += "callback=" + defCallfn + "&q=" + new Date().getTime();47 var scriptId = uuid() + '-' + new Date().getTime();48 window[defCallfn] = function () {49 document.getElementById(scriptId).setAttribute('guid', scriptId);50 success.apply(null, arguments);51 window[defCallfn] = null;52 if (JSONP.end) {53 JSONP.end();54 }55 if (!isIE) {56 $('#'+scriptId).remove();57 }58 };59 var JSONPLoaded = function () {60 if (isIE) {//IE61 if (document.getElementById(scriptId).getAttribute('guid') != scriptId) {62 error();63 if (JSONP.end) {64 JSONP.end();65 }66 }67 } else {68 error();69 if (JSONP.end) {70 JSONP.end();71 }72 }73 window[defCallfn] = null;74 $('#'+scriptId).remove();75 };76 JSONP.getScript(url, JSONPLoaded, scriptId);77 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('Login').click()4 cy.get('#username').type('admin')5 cy.get('#password').type('admin')6 cy.get('#login').click()7 cy.contains('Dashboard').click()8 cy.contains('Users').click()9 cy.contains('Add User').click()10 cy.get('#name').type('test')11 cy.get('#username').type('test')12 cy.get('#password').type('test')13 cy.get('#role').select('ADMIN')14 cy.get('#save').click()15 cy.get('#name').type('test')16 cy.get('#username').type('test')17 cy.get('#password').type('test')18 cy.get('#role').select('ADMIN')19 cy.get('#save').click()20 cy.get('#name').type('test')21 cy.get('#username').type('test')22 cy.get('#password').type('test')23 cy.get('#role').select('ADMIN')24 cy.get('#save').click()25 cy.get('#name').type('test')26 cy.get('#username').type('test')27 cy.get('#password').type('test')28 cy.get('#role').select('ADMIN')29 cy.get('#save').click()30 cy.get('#name').type('test')31 cy.get('#username').type('test')32 cy.get('#password').type('test')33 cy.get('#role').select('ADMIN')34 cy.get('#save').click()35 cy.get('#name').type('test')36 cy.get('#username').type('test')37 cy.get('#password').type('test')38 cy.get('#role').select('ADMIN')39 cy.get('#save').click()40 cy.get('#name').type('test')41 cy.get('#username').type('test')42 cy.get('#password').type('test')43 cy.get('#role').select('ADMIN')44 cy.get('#save').click()45 cy.get('#name').type('test')46 cy.get('#username').type('test')47 cy.get('#password').type('test')48 cy.get('#role').select('ADMIN')49 cy.get('#save').click()50 cy.get('#name').type('test')51 cy.get('#username').type('test')

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add("onloadFn", (fn) => {2 cy.window().then((win) => {3 cy.stub(win, "onload", fn);4 });5});6Cypress.Commands.add("onloadFn", (fn) => {7 cy.window().then((win) => {8 cy.stub(win, "onload", fn);9 });10});11Cypress.Commands.add("onloadFn", (fn) => {12 cy.window().then((win) => {13 cy.stub(win, "onload", fn);14 });15});16Cypress.Commands.add("onloadFn", (fn) => {17 cy.window().then((win) => {18 cy.stub(win, "onload", fn);19 });20});21Cypress.Commands.add("onloadFn", (fn) => {22 cy.window().then((win) => {23 cy.stub(win, "onload", fn);24 });25});26Cypress.Commands.add("onloadFn", (fn) => {27 cy.window().then((win) => {28 cy.stub(win, "onload", fn);29 });30});31Cypress.Commands.add("onloadFn", (fn) => {32 cy.window().then((win) => {33 cy.stub(win, "onload", fn);34 });35});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.wait(2000)4 cy.get('input').type('test')5 cy.get('button').click()6 cy.wait(2000)7 cy.get('input').type('test')8 cy.get('button').click()9 cy.wait(2000)10 cy.get('input').type('test')11 cy.get('button').click()12 cy.wait(2000)13 cy.get('input').type('test')14 cy.get('button').click()15 cy.wait(2000)16 cy.get('input').type('test')17 cy.get('button').click()18 cy.wait(2000)19 cy.get('input').type('test')20 cy.get('button').click()21 cy.wait(2000)22 cy.get('input').type('test')23 cy.get('button').click()24 cy.wait(2000)25 cy.get('input').type('test')26 cy.get('button').click()27 cy.wait(2000)28 cy.get('input').type('test')29 cy.get('button').click()30 cy.wait(2000)31 cy.get('input').type('test')32 cy.get('button').click()33 cy.wait(2000)34 })35})36describe('My First Test', function() {37 it('Does not do much!', function() {38 cy.wait(2000)39 cy.get('input').type('test')40 cy.get('button').click()41 cy.wait(2000)42 cy.get('input').type('test')43 cy.get('button').click()44 cy.wait(2000)45 })46})47describe('My First Test', function() {48 it('Does not do much!', function() {49 cy.wait(2000)50 cy.get('input').type('test')

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

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