Best JavaScript code snippet using best
PreviewModel.js
Source:PreviewModel.js  
1import { PHOTO_VERSION } from '@/utils/enumerate'2const completePhoto = [PHOTO_VERSION.FIRST_PHOTO]3export default class PreviewModel {4  id = ''5  version = 'original_photo'6  path = ''7  mode = 'original'8  storePartReworkReason = [] // å±é¨é®é¢æ ç¾å¯¹è±¡9  storeReworkReason = []10  storeReworkReasonManage = [] // æ´ä½é®é¢æ ç¾å¯¹è±¡11  storeReworkNote = []12  hasStoreReturnTag = false13  commitInfo = {}14  hasCommitInfo = false15  versionCache = null16  constructor (photoItem) {17    this.id = photoItem.id18    this.version = photoItem.version19    this.path = photoItem.path20    this.getStoreReaseon(photoItem)21    this.getHasStoreReturnTag()22    this.getCommitInfo(photoItem)23    this.getMode()24    this.getVersionCache(photoItem)25  }26  // è·åé¨åºéåä¿¡æ¯27  getStoreReaseon (photoItem) {28    if (!photoItem.tags) return29    const newStorePartReworkReason = _.get(photoItem, 'tags.values.origin_return_labels.store_part_rework_reason')30    const oldStorePartReworkReason = _.get(photoItem, 'tags.values.store_part_rework_reason')31    let storePartReworkReason = newStorePartReworkReason || oldStorePartReworkReason || []32    storePartReworkReason = storePartReworkReason.map(labelItem => {33      const createData = labelItem34      const labelTop = createData.location[0]35      const labelLeft = createData.location[1]36      // 夿æ è®°å¨åªä¸ªè±¡é37      if (labelTop <= 50) createData.labelClass = labelLeft <= 50 ? 'top-left' : 'top-right'38      if (labelTop > 50) createData.labelClass = labelLeft <= 50 ? 'bottom-left' : 'bottom-right'39      // 2.12ä¹åæ°çå±é¨æ ç¾å¨å¨labelsä¸é¢40      if (createData.labels) {41        createData.reason = createData.labels.map(labelItem => labelItem.name)42        createData.reasonManage = [] // å¯ä»¥è¿è¡æä½çreason43        createData.labels.forEach(label => {44          const reasonObj = {45            id: label.id,46            name: label.name,47            cancel: false,48            isDel: label.is_del49          }50          if (label.is_del) {51            reasonObj.cancel = true52          }53          createData.reasonManage.push(reasonObj)54        })55      } else {56        createData.reasonManage = [] // å¯ä»¥è¿è¡æä½çreason57        createData.reason = typeof labelItem.reason === 'string' ? labelItem.reason.split('+') : labelItem.reason58        createData.reason.forEach(reasonItem => {59          const reasonObj = {60            name: reasonItem,61            cancel: false62          }63          createData.reasonManage.push(reasonObj)64        })65      }66      createData.isNeedDownIndex = false // ç¨äºå¤çé®é¢æ è®°éå çæ
åµ67      return createData68    })69    this.storePartReworkReason = storePartReworkReason70    const originReturnLabels = _.get(photoItem, 'tags.values.origin_return_labels')71    if (originReturnLabels) {72      // æ´ä½å¤æ³¨73      this.storeReworkNote = _.get(photoItem, 'tags.values.origin_return_labels.store_rework_note') || '-'74      // æ´ä½éåæ è®°75      const originReturnLabelsLabels = originReturnLabels.labels76      if (!originReturnLabelsLabels) {77        const storeReworkReason = originReturnLabels.store_rework_reason78        this.storeReworkReason = storeReworkReason ? storeReworkReason.split('+') : []79        this.storeReworkReason.forEach(storeReworkReasonItem => {80          const reasonObj = {81            name: storeReworkReasonItem,82            cancel: false83          }84          this.storeReworkReasonManage.push(reasonObj)85        })86      } else {87        const storeReworkReason = originReturnLabels.labels || ''88        this.storeReworkReason = storeReworkReason.map(reasonItem => reasonItem.name)89        storeReworkReason.forEach(reasonItem => {90          const reasonObj = {91            id: reasonItem.id,92            name: reasonItem.name,93            cancel: false,94            isDel: reasonItem.is_del95          }96          if (reasonItem.is_del) {97            reasonObj.cancel = true98          }99          this.storeReworkReasonManage.push(reasonObj)100        })101      }102    } else {103      const storeReworkReason = _.get(photoItem, 'tags.values.store_rework_reason') || ''104      this.storeReworkReason = storeReworkReason ? storeReworkReason.split('+') : []105      this.storeReworkReason.forEach(storeReworkReasonItem => {106        const reasonObj = {107          name: storeReworkReasonItem,108          cancel: false109        }110        this.storeReworkReasonManage.push(reasonObj)111      })112      // æ´ä½å¤æ³¨113      this.storeReworkNote = _.get(photoItem, 'tags.values.store_rework_note') || '-'114    }115  }116  // 夿æ¯å¦æ¾ç¤ºéåæ ç¾117  getHasStoreReturnTag () {118    const hasStorePartReworkReason = Boolean(this.storePartReworkReason.length)119    const hasStoreReworkReason = Boolean(this.storeReworkReason.length)120    this.hasStoreReturnTag = hasStorePartReworkReason || hasStoreReworkReason121  }122  // è·åäºå¦é¢è¯ä»· 123  getCommitInfo (photoItem) {124    if (completePhoto.includes(this.version)) {125      this.commitInfo = photoItem.commitInfo || {}126    }127    this.hasCommitInfo = Boolean(Object.keys(this.commitInfo).length)128  }129  // è·å模å¼130  getMode () {131    if (this.version === 'store_rework' && this.hasStoreReturnTag) {132      this.mode = 'complete'133    } else if (completePhoto.includes(this.version) && this.hasCommitInfo) {134      this.mode = 'cloudLabel'135    }136  }137  getVersionCache (photoItem) {138    if (this.hasStoreReturnTag || this.hasCommitInfo) {139      this.versionCache = photoItem.versionCache140    }141  }...commitInfo.js
Source:commitInfo.js  
...15    }16    get hasError() {17        return this.commitInfo.hasOwnProperty('error');18    }19    get hasCommitInfo() {20        return this.commitInfo && Object.keys(this.commitInfo).length > 0;21    }22    get styleTag() {23        return `transform: translate(${this.left}px, ${this.top}px)`;24    }25    get classNames() {26        return this.hidden ? 'hidden commit-info' : 'commit-info';27    }28    get compareButtonText() {29        return this.pendingcompare ? 'Uncompare' : 'Compare';30    }31    close() {32        this.dispatchEvent(33            new CustomEvent('close', {...Using AI Code Generation
1var CommitInfo = require('./lib/commitInfo');2var BestPractice = require('./lib/bestPractice');3var bestPractice = new BestPractice();4var commitInfo = new CommitInfo();5bestPractice.hasCommitInfo(commitInfo);6var CommitInfo = require('./lib/commitInfo');7var BestPractice = require('./lib/bestPractice');8var bestPractice = new BestPractice();9var commitInfo = new CommitInfo();10bestPractice.hasCommitInfo(commitInfo);Using AI Code Generation
1const BestCommit = require('./bestCommit.js');2let bestCommit = new BestCommit();3const BestCommit = require('./bestCommit.js');4let bestCommit = new BestCommit();5const BestCommit = require('./bestCommit.js');6let bestCommit = new BestCommit();7const BestCommit = require('./bestCommit.js');8let bestCommit = new BestCommit();9const BestCommit = require('./bestCommit.js');10let bestCommit = new BestCommit();11const BestCommit = require('./bestCommit.js');12let bestCommit = new BestCommit();13const BestCommit = require('./bestCommit.js');14let bestCommit = new BestCommit();15const BestCommit = require('./bestCommit.js');16let bestCommit = new BestCommit();17const BestCommit = require('./bestCommit.js');18let bestCommit = new BestCommit();Using AI Code Generation
1var BestPractice = require("./BestPractice");2var bestPractice = new BestPractice();3var result = bestPractice.hasCommitInfo("test");4console.log(result);5var BestPractice = require("./BestPractice");6var bestPractice = new BestPractice();7var result = bestPractice.hasCommitInfo("test");8console.log(result);9var BestPractice = require("./BestPractice");10var bestPractice = new BestPractice();11var result = bestPractice.hasCorrectFileNames("test");12console.log(result);13var BestPractice = require("./BestPractice");14var bestPractice = new BestPractice();15var result = bestPractice.hasCorrectNamingConventions("test");16console.log(result);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!!
