customerProfileOnlyTemplate.test.mjs 3.67 KB
import { readFileSync } from 'node:fs'
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'

const template = readFileSync(
  new URL('../createOrder.wxml', import.meta.url),
  'utf8'
)
const constantsSource = readFileSync(
  new URL('../constants.js', import.meta.url),
  'utf8'
)
const start = template.indexOf('<view class="customerName">')
const end = template.indexOf(
  '\n\t\t<view class="box" wx:if="{{ orderObj.userId && orderObj.baseSceneCode }}">',
  start
)
const customerSection = template.slice(start, end)

describe('createOrder customer information template', () => {
  it('keeps archive fields read-only while allowing VIN and plate input', () => {
    assert.ok(start >= 0)
    assert.ok(end > start)
    assert.match(customerSection, /bindtitleClick="showCustomPop"/)
    assert.match(customerSection, /label="车主姓名"/)
    assert.match(customerSection, /iconSrc="\{\{ recordIcon \}\}"/)
    assert.match(
      constantsSource,
      /RECORD_ICON: `\$\{CDN_BASE\}\/miniProgram\/record\.png`/
    )
    assert.match(customerSection, /labelWidth="var\(--fontSize290\)"/)
    assert.match(customerSection, /orderObj\.customer\.customerName \|\| '请通过选择客户档案'/)
    assert.equal(customerSection.match(/请通过选择客户档案/g)?.length, 1)
    assert.doesNotMatch(customerSection, /请通过客户档案选择/)
    assert.match(customerSection, /label="客户来源"/)
    assert.match(customerSection, /value="\{\{ filter\.getSalesTypeName\(Sourcecolumns, orderObj\.customer\.salesType\) \}\}"/)
    assert.match(
      customerSection,
      /label="客户来源"[\s\S]*bindclick="toSelectCustomerSource"/
    )
    assert.match(template, /default-index="\{\{ sourceDefaultIndex \}\}"/)
    assert.match(customerSection, /label="性别"/)
    assert.match(customerSection, /orderObj\.customer\.customerSex == 1 \? '男' : \(orderObj\.customer\.customerSex == 2 \? '女' : ''\)/)
    assert.match(customerSection, /label="手机号"/)
    assert.match(customerSection, /value="\{\{ orderObj\.customer\.customerPhone \}\}"/)
    assert.match(customerSection, /label="选择车型"/)
    assert.match(customerSection, /orderObj\.customer\.carSeriesName \? orderObj\.customer\.carBrand \+ ' - ' \+ orderObj\.customer\.carChildsBrandName \+ ' - ' \+ orderObj\.customer\.carSeriesName : ''/)
    assert.match(customerSection, /label="车架号\( VIN \)"/)
    assert.match(customerSection, /value="\{\{ orderObj\.customer\.standNo \}\}"/)
    assert.match(customerSection, /data-name="customer\.standNo"/)
    assert.match(customerSection, /label="车牌号"/)
    assert.match(customerSection, /value="\{\{ orderObj\.customer\.plateNumber \}\}"/)
    assert.match(customerSection, /data-name="customer\.plateNumber"/)
    assert.match(customerSection, /label="是否体验"/)
    assert.match(customerSection, /orderObj\.customer\.experienceFlag == 'Y' \? '是' : \(orderObj\.customer\.experienceFlag == 'N' \? '否' : ''\)/)
    assert.equal(customerSection.match(/<input/g)?.length, 2)
    assert.doesNotMatch(customerSection, /bind:click="toSelectCustomerSource"/)
    assert.doesNotMatch(customerSection, /bindtap="changeGender"/)
    assert.doesNotMatch(customerSection, /data-show-name="carBrandBox"/)
    assert.equal(customerSection.match(/bindtitleClick="navOcr"/g)?.length, 2)
    assert.doesNotMatch(customerSection, /bindtap="changeExperience"/)
  })

  it('queries customer archives with the 4S store selected before order creation', () => {
    assert.match(template, /<customerInfo[\s\S]*merchantId="\{\{ orderObj\.merchantId \|\| 0 \}\}"/)
    assert.doesNotMatch(template, /<customerInfo[\s\S]*merchantId="\{\{ workOrderUserContext\.shopMerchantId \|\| 0 \}\}"/)
  })
})