Best JavaScript code snippet using devicefarmer-stf
yuperrcheck.js
Source:yuperrcheck.js
1export function yupErrCheck (schema,field,linedata) {2 let mfield 3 try{schema.validateSync(linedata)4 switch(field) {5 case "confirm" : //1è¡ãã¹ã¦ã®ãã§ãã¯})6 linedata.confirm = null7 linedata.confirm_gridmessage = "doing"8 Object.keys(linedata).map((fd)=>{9 if(schema.fields[field]){ //対象ã¯å
¥åé
ç®ã®ã¿10 linedata = dataCheck7(schema,fd,linedata)11 if(linedata[`${fd}_gridmessage`] !== "ok"){12 linedata.confirm = false13 linedata.confirm_gridmessage = `err ${fd}ã${linedata[`${fd}_gridmessage`]}ã`14 }15 } 16 return linedata17 }18 )19 return linedata20 default: 21 dataCheck7(schema,linedata) 22 return linedata23 }24 } 25 catch(err){26 switch(field){27 case "confirm" : //1è¡ãã¹ã¦ã®ãã§ãã¯28 linedata.confirm = false29 mfield = err.path+"_gridmessage"30 linedata[mfield] = err.errors.join(",")31 linedata.confirm_gridmessage = `error ${err.path}ã${linedata[mfield]}ã`32 linedata["errPath"] = err.path33 return linedata34 default: 35 mfield = field+"_gridmessage"36 linedata[mfield] = " error " + err.errors.join(",")37 return linedata38 }39 }40} 41//æªå®æ½ãyupã§ã¯æ°å¤é
ç®ã§ã"ã¹ãã¼ã¹999" ãã¨ã©ã¼ã«ãªããªãã42// yupã§ã¯ã2019/12/32çãã¨ã©ã¼ã«ãªããªããã2020/01/01ã«ãªã£ã¦ãã¾ã43export function dataCheck7(schema,updateRow){ 44 let confirm_gridmessage 45 Object.keys(updateRow).map((field)=>{46 if(schema.fields[field]){47 switch(schema.fields[field]["_type"]){48 case "date" :49 let moment = require('moment');50 let yyyymmdd = updateRow[field].split(/-|\/|\s/)51 if(yyyymmdd[1] === undefined){updateRow[`${field}_gridmessage`] = "error not date type yyyy/mm/dd or yyyy-mm-dd"52 confirm_gridmessage = updateRow[`${field}_gridmessage`] + confirm_gridmessage}53 else54 {55 if(yyyymmdd[1].length===1){yyyymmdd[1] = "0"+yyyymmdd[1]}56 if(yyyymmdd[2] === undefined ){yyyymmdd[2] = "01"57 updateRow[field] = yyyymmdd[0]+"-"+yyyymmdd[1]+"-"+yyyymmdd[2]}58 //if(/(\d){4}\/|-\d+\d+\/|-\d+\d+/.test(updateRow[field])){ // "/"ã2019-2-30 ã ã¨ãããå¹´çã®ãã§ãã¯ãã§ããªãã59 if(yyyymmdd.length===3){ // 60 if(moment(yyyymmdd[0]+"-"+yyyymmdd[1]+"-"+yyyymmdd[2]).isValid()){61 updateRow[`${field}_gridmessage`] = "ok"62 }else{63 updateRow[`${field}_gridmessage`] = "error not date "64 confirm_gridmessage = updateRow[`${field}_gridmessage`] + confirm_gridmessage65 }66 }else67 {68 if(yyyymmdd.length===4){69 let hhmiss = updateRow[field].split(":")70 if(hhmiss[0].length===1){hhmiss[0] = "0"+hhmiss[0]}71 if(/^[0-2][0-4]$/.test(hhmiss[0])){72 if(hhmiss[1]===undefined){73 updateRow[`${field}_gridmessage`] = "ok"74 }else75 {76 if(hhmiss[1].length===1){hhmiss[1] = "0"+hhmiss[1]}77 if(/^[0-5][0-9]$/.test(hhmiss[1])){78 if(hhmiss[2]===undefined){79 updateRow[`${field}_gridmessage`] = "ok"80 }else81 {82 if(/^[0-5][0-9]$/.test(hhmiss[2])){83 updateRow[`${field}_gridmessage`] = "ok"84 }else85 {86 updateRow[`${field}_gridmessage`] = "error not date type ss>=00 and ss<60"87 }88 }89 }else90 {91 updateRow[`${field}_gridmessage`] = "error not date type hh>=00 and hh<=24"92 confirm_gridmessage = updateRow[`${field}_gridmessage`] + confirm_gridmessage}93 }94 }else95 {96 updateRow[`${field}_gridmessage`] = "error not date type hh>=00 and hh<=24"97 confirm_gridmessage = updateRow[`${field}_gridmessage`] + confirm_gridmessage98 }99 }else100 {//length>4101 updateRow[`${field}_gridmessage`] = "error not date type yyyy/mm/dd or yyyy/mm/dd hh:mi:ss"102 confirm_gridmessage = updateRow[`${field}_gridmessage`] + confirm_gridmessage103 } 104 } 105 } 106 break 107 default:108 switch(field){109 case "screen_rowlist": //ä¸ç»é¢ã«è¡¨ç¤ºã§ããè¡æ°ãã»ããããé
ç®ã®æå®ãæ£ããã§ãã¦ãããï¼110 updateRow[field].split(',').map((rowcnt)=>{111 if(isNaN(rowcnt)){ 112 updateRow[`${field}_gridmessage`] = "error must be xxx,yyy,zzz :xxx-->numeric"113 confirm_gridmessage = updateRow[`${field}_gridmessage`] + confirm_gridmessage114 }else{115 if(updateRow[`${field}_gridmessage`]){116 if(/error/.test(updateRow[`${field}_gridmessage`])){}117 else{updateRow[`${field}_gridmessage`] = "ok"}118 }119 else{updateRow[`${field}_gridmessage`] = "ok"}120 } //ã¨ã©ã¼ã»ãã121 return updateRow122 })123 break124 case "screenfield_indisp": //tipãæ©è½ããªãã125 if(/_code/.test(updateRow["pobject_code_sfd"])&updateRow["screenfield_editable"]!=="0")126 {if(updateRow["screenfield_indisp"]==="1")127 {updateRow[`${field}_gridmessage`] = "ok"}128 else{updateRow["screenfield_indisp_gridmessage"] = "error! must be Required"129 confirm_gridmessage = updateRow[`${field}_gridmessage`] + confirm_gridmessage}130 }else{131 updateRow[`${field}_gridmessage`] = "ok"}132 break133 default:134 updateRow[`${field}_gridmessage`] = "ok"135 }136 }137 }else{ //yupã«ç»é²ããã¦ãªãã¨ã138 updateRow[`${field}_gridmessage`] = `error field:${field} not exists in yupschema. please creat 'yupschema' by yup button `139 } 140 return updateRow 141 })142 143 updateRow["confirm_gridmessage"] = confirm_gridmessage144 return updateRow ...
ItemRow.spec.jsx
Source:ItemRow.spec.jsx
1// Libs2import React from 'react';3import renderer from 'react-test-renderer';4import { mount } from 'enzyme';5// Component6import { ItemRow } from '../ItemRow.jsx';7// Mocks8const actions = true;9const addItem = jest.fn();10const hasHandler = true;11const item = {12 id: '638fd7e3-217b-4a29-87f7-5ec539f73af9',13 description: 'iPhone X',14 price: 999,15 quantity: 1,16 subtotal: 999,17};18const removeRow = jest.fn();19const updateRow = jest.fn();20const t = jest.fn();21describe('Renders correctly to the DOM', () => {22 let wrapper;23 beforeEach(() => {24 wrapper = mount(25 <ItemRow26 t={t}27 actions={actions}28 addItem={addItem}29 hasHandler={hasHandler}30 item={item}31 removeRow={removeRow}32 updateRow={updateRow}33 />34 );35 });36 // PROPS & STATE37 it('receives correct props', () => {38 expect(wrapper.prop('actions')).toEqual(true);39 expect(wrapper.prop('actions')).not.toEqual(false);40 expect(wrapper.prop('hasHandler')).toEqual(true);41 expect(wrapper.prop('hasHandler')).not.toEqual(false);42 expect(wrapper.prop('item')).toEqual(item);43 expect(wrapper.prop('removeRow')).toEqual(removeRow);44 expect(wrapper.prop('updateRow')).toEqual(updateRow);45 });46 // RENDER47 it('renders necessary element', () => {48 expect(wrapper.find('input')).toHaveLength(3);49 expect(wrapper.find('a')).toHaveLength(1);50 });51 // LIFE CYCLE EVENTS52 it('set local state as item prop value', () => {53 expect(wrapper.state()).toEqual(item);54 });55 // PRIVATE METHOD56 it('handle text input change correctly', () => {57 // Setup58 const spy = jest.spyOn(ItemRow.prototype, 'handleTextInputChange');59 const wrap = mount(60 <ItemRow61 t={t}62 actions={actions}63 addItem={addItem}64 hasHandler={hasHandler}65 item={item}66 removeRow={removeRow}67 updateRow={updateRow}68 />69 );70 // Execute71 const textChange = {72 target: {73 name: 'description',74 value: 'iPhoneX',75 },76 };77 const descriptionInput = wrap.find('input').first();78 descriptionInput.simulate('change', textChange);79 // Assert80 expect(spy).toHaveBeenCalled();81 });82 it('handle number input change correctly', () => {83 const spy = jest.spyOn(ItemRow.prototype, 'handleNumberInputChange');84 const wrap = mount(85 <ItemRow86 t={t}87 actions={actions}88 addItem={addItem}89 hasHandler={hasHandler}90 item={item}91 removeRow={removeRow}92 updateRow={updateRow}93 />94 );95 // Execute96 const priceChange = {97 target: {98 name: 'price',99 value: '999',100 },101 };102 const priceInput = wrap.find('input').at(1);103 const quantityInput = wrap.find('input').last();104 priceInput.simulate('change', priceChange);105 // Assertion106 expect(spy).toHaveBeenCalled();107 });108 it('add new row when press enter', () => {109 const spy = jest.spyOn(ItemRow.prototype, 'handleKeyDown');110 const wrap = mount(111 <ItemRow112 t={t}113 actions={actions}114 addItem={addItem}115 hasHandler={hasHandler}116 item={item}117 removeRow={removeRow}118 updateRow={updateRow}119 />120 );121 // Execute122 const keyChange = {123 which: 13,124 };125 const descriptionInput = wrap.find('input').first();126 descriptionInput.simulate('keyDown', keyChange);127 // Assertion128 expect(spy).toHaveBeenCalled();129 expect(addItem).toHaveBeenCalled();130 });131 it('updateSubtotal when price and quantity change', () => {132 const spy = jest.spyOn(ItemRow.prototype, 'updateSubtotal');133 const wrap = mount(134 <ItemRow135 t={t}136 actions={actions}137 addItem={addItem}138 hasHandler={hasHandler}139 item={item}140 removeRow={removeRow}141 updateRow={updateRow}142 />143 );144 // Execute145 const priceChange = {146 target: {147 name: 'price',148 value: '799',149 },150 };151 const priceInput = wrap.find('input').at(1);152 priceInput.simulate('change', priceChange);153 // Assertion154 expect(spy).toHaveBeenCalled();155 });156 it('handle removeRow correctly', () => {157 const removeBtn = wrapper.find('a');158 removeBtn.simulate('click');159 expect(removeRow).toHaveBeenCalled();160 });161 // SNAPSHOT162 it('matches snapshot', () => {163 const tree = renderer164 .create(165 <ItemRow166 t={t}167 actions={actions}168 addItem={addItem}169 hasHandler={hasHandler}170 item={item}171 removeRow={removeRow}172 updateRow={updateRow}173 />174 )175 .toJSON();176 expect(tree).toMatchSnapshot();177 });...
Update.js
Source:Update.js
1/** @flow */2import moment from 'moment';3import { NotFoundError } from '../errors';4import { encodeId } from '../identifiers';5import type { GraphQLContext } from './context';6import type { UpdateRow, TargetRow } from '../rows';7export default {8 id(updateRow: UpdateRow): string {9 return encodeId('UPD', updateRow.id);10 },11 display(updateRow: UpdateRow): string {12 const friendlyTime = moment(updateRow.created_at).format(13 'dddd, MMMM Do YYYY, h:mm:ss a'14 );15 if (updateRow.user_id) {16 return `Manual decision made on ${friendlyTime}`;17 } else {18 return `Automated decision made on ${friendlyTime}`;19 }20 },21 event(updateRow: UpdateRow): string {22 return updateRow.event;23 },24 args(updateRow: UpdateRow): Object {25 return updateRow.args;26 },27 label(updateRow: UpdateRow): ?string {28 return updateRow.label;29 },30 score(updateRow: UpdateRow): ?number {31 return updateRow.score;32 },33 reasons(updateRow: UpdateRow): Array<string> {34 return updateRow.reasons;35 },36 state(updateRow: UpdateRow): ?Object {37 return updateRow.state;38 },39 aliases(updateRow: UpdateRow): Array<string> {40 return updateRow.aliases || [];41 },42 webhookStatus(updateRow: UpdateRow): ?number {43 return updateRow.webhook_status;44 },45 webhookAt(updateRow: UpdateRow): ?Date {46 return updateRow.webhook_at;47 },48 createdAt(updateRow: UpdateRow): Date {49 return updateRow.created_at;50 },51 async target(52 updateRow: UpdateRow,53 args: {},54 { loaders }: GraphQLContext55 ): Promise<TargetRow> {56 const targetRow = await loaders.target.load(updateRow.target_id);57 if (targetRow) {58 return targetRow;59 } else {60 throw new NotFoundError('target not found');61 }62 }...
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2deviceFarmer.updateRow('device', {serial: 'emulator-5554'}, {present: false}, function(err, result) {3 if (err) {4 console.log(err);5 }6 else {7 console.log(result);8 }9});10var devicefarmer = require('devicefarmer-stf');11deviceFarmer.updateRow('device', {serial: 'emulator-5554'}, {present: false}, function(err, result) {12 if (err) {13 console.log(err);14 }15 else {16 console.log(result);17 }18});19var devicefarmer = require('devicefarmer-stf');20deviceFarmer.updateRow('device', {serial: 'emulator-5554'}, {present: false}, function(err, result) {21 if (err) {22 console.log(err);23 }24 else {25 console.log(result);26 }27});28var devicefarmer = require('devicefarmer-stf');29deviceFarmer.updateRow('device', {serial: 'emulator-5554'}, {present: false}, function(err, result) {30 if (err) {31 console.log(err);32 }33 else {34 console.log(result);35 }36});37var devicefarmer = require('devicefarmer-st
Using AI Code Generation
1var devicefarmerStf = require('devicefarmer-stf');2var options = {3};4stf.updateRow(options, function (err, data) {5 if (err) {6 console.log('error: ', err);7 } else {8 console.log('data: ', data);9 }10});
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf-client');2var device = deviceFarmer.device;3var deviceSerial = 'emulator-5554';4var rowId = 'rowId';5var rowData = {6};7device.updateRow(deviceSerial, rowId, rowData).then(function(res) {8 console.log(res);9}).catch(function(err) {10 console.log(err);11});12var DeviceFarmer = require('devicefarmer-stf-client');13var device = deviceFarmer.device;14var deviceSerial = 'emulator-5554';15var rowId = 'rowId';16device.deleteRow(deviceSerial, rowId).then(function(res) {17 console.log(res);18}).catch(function(err) {19 console.log(err);20});21var DeviceFarmer = require('devicefarmer-stf-client');22var device = deviceFarmer.device;23var deviceSerial = 'emulator-5554';24var rowData = {25};26device.createRow(deviceSerial, rowData).then(function(res) {27 console.log(res);28}).catch(function(err) {29 console.log(err);30});31var DeviceFarmer = require('devicefarmer-stf-client');32var device = deviceFarmer.device;33var deviceSerial = 'emulator-5554';34device.getRows(deviceSerial).then(function(res) {35 console.log(res);36}).catch(function(err) {37 console.log(err);38});39var DeviceFarmer = require('devicefarmer-stf-client');40var device = deviceFarmer.device;41var deviceSerial = 'emulator-5554';
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf-client');2var device = client.getDevice('c4c4b0b0');3device.updateRow(1, 1, 1);4device.updateRow(2, 2, 2);5device.updateRow(3, 3, 3);6device.updateRow(4, 4, 4);7var DeviceFarmer = require('devicefarmer-stf-client');8var device = client.getDevice('c4c4b0b0');9device.updateRow(1, 1, 1);10device.updateRow(2, 2, 2);11device.updateRow(3, 3, 3);12device.updateRow(4, 4, 4);13var DeviceFarmer = require('devicefarmer-stf-client');14var device = client.getDevice('c4c4b0b0');15device.updateRow(1, 1, 1);16device.updateRow(2, 2, 2);17device.updateRow(3, 3, 3);18device.updateRow(4, 4, 4);19var DeviceFarmer = require('devicefarmer-stf-client');20var device = client.getDevice('c4c4b0b0');21device.updateRow(1, 1, 1);22device.updateRow(2, 2, 2);23device.updateRow(3, 3, 3);24device.updateRow(4, 4, 4);25var DeviceFarmer = require('devicefarmer-stf-client');26var device = client.getDevice('c4c4b0b0');27device.updateRow(1, 1, 1);28device.updateRow(2, 2, 2);29device.updateRow(3, 3, 3);30device.updateRow(4, 4, 4);
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2var db = new devicefarmer.Database();3db.updateRow('test', 'id', '1', 'name', 'test1', function(err, response) {4 if (err) {5 console.log(err);6 } else {7 console.log(response);8 }9});10var devicefarmer = require('devicefarmer-stf');11var db = new devicefarmer.Database();12db.deleteRow('test', 'id', '1', function(err, response) {13 if (err) {14 console.log(err);15 } else {16 console.log(response);17 }18});19var devicefarmer = require('devicefarmer-stf');20var db = new devicefarmer.Database();21db.deleteTable('test', function(err, response) {22 if (err) {23 console.log(err);24 } else {25 console.log(response);26 }27});28var devicefarmer = require('devicefarmer-stf');29var db = new devicefarmer.Database();30db.createTable('test', function(err, response) {31 if (err) {32 console.log(err);33 } else {34 console.log(response);35 }36});37var devicefarmer = require('devicefarmer-stf');38var db = new devicefarmer.Database();39db.addRow('test', 'id', '1', 'name', 'test1', function(err, response
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!!