customerDailyFields.ui.test.mjs 9.82 KB
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'

const read = relativePath =>
  readFileSync(fileURLToPath(new URL(relativePath, import.meta.url)), 'utf8')

describe('boutique customer daily field UI contract', () => {
  it('IT-WO-DAILY-UI-001: create page renders optional fields and multi-select popup', () => {
    const wxml = read('../createOrder.wxml')
    assert.match(wxml, /label="日报标签"/)
    assert.match(wxml, /label="实际交付日期"/)
    assert.match(wxml, /customerTagsPopup/)
    assert.match(wxml, /onConfirmCustomerTags/)
    assert.match(wxml, /mode="date"/)
  })

  it('IT-WO-DAILY-UI-011: delivery date picker prevents selecting a future local date', () => {
    const js = read('../createOrder.js')
    const wxml = read('../createOrder.wxml')

    assert.match(
      wxml,
      /<picker\s+wx:if="\{\{ showActualDeliveryDate \}\}"\s+mode="date"\s+value="\{\{ orderObj\.customer\.actualDeliveryDate \}\}"\s+end="\{\{ actualDeliveryDateMax \}\}"\s+bindchange="onCustomerDeliveryDateChange"\s*>/
    )
    assert.match(
      js,
      /import timeUtil from '~\/utils\/timeFormat\/time-utils\.js'/
    )
    assert.match(js, /actualDeliveryDateMax:\s*timeUtil\.getTodayDateStr\(\)/)
  })

  it('IT-WO-DAILY-UI-012: visible delivery date shows required state and blocks an empty submit', () => {
    const js = read('../createOrder.js')
    const validation = read('../services/orderValidation.helpers.js')
    const wxml = read('../createOrder.wxml')

    assert.match(js, /validateBoutiqueRequiredFields/)
    assert.match(validation, /isBoutiqueActualDeliveryDateMissing/)
    assert.match(
      validation,
      /isBoutiqueActualDeliveryDateMissing\(\s*input\.showActualDeliveryDate,\s*customer\.actualDeliveryDate\s*\)/
    )
    assert.match(js, /actualDeliveryDate:\s*'实际交付日期不能为空'/)
    assert.match(validation, /errorKey:\s*["']actualDeliveryDate["']/)
    assert.match(
      wxml,
      /<gl-cell[\s\S]*?class="actualDeliveryDate"[\s\S]*?label="实际交付日期"[\s\S]*?required[\s\S]*?requiredAfter[\s\S]*?\/>/
    )
  })

  it('IT-WO-DAILY-UI-002: removed dormant count request cannot return to the create page', () => {
    const js = read('../createOrder.js')
    assert.doesNotMatch(js, /waitinputorder\(/)
  })

  it('IT-WO-DAILY-UI-003: confirm and detail show tags and delivery date', () => {
    const confirm = read('../../confirmOrder/confirmOrder.wxml')
    const detail = read('../../orderDetail/orderDetail.wxml')
    ;[confirm, detail].forEach(source => {
      assert.match(source, /日报标签/)
      assert.match(source, /实际交付日期/)
      assert.match(source, /customerTagLabels/)
    })
  })

  it('IT-WO-DAILY-UI-004: create and submit retain scene and merchant-brand context', () => {
    const page = read('../createOrder.js')
    const submitStrategy = read('../submitStrategy.js')
    assert.match(page, /customerDailyFieldMerchantBrands/)
    assert.match(
      page,
      /baseSceneName:[\s\S]*baseSceneCode:[\s\S]*merchantBrands:/
    )
    assert.match(
      submitStrategy,
      /merchantBrands:\s*data\.customerDailyFieldMerchantBrands/
    )
  })

  it('IT-WO-DAILY-UI-005: list conditionally renders each response display value', () => {
    const listWxml = read('../../tabWorkOrderRelevance/index.wxml')

    assert.match(listWxml, /li\.customerDailyDisplay\.showCustomerTags/)
    assert.match(listWxml, /li\.customerDailyDisplay\.customerTagsText/)
    assert.match(listWxml, /li\.customerDailyDisplay\.showActualDeliveryDate/)
    assert.match(listWxml, /li\.customerDailyDisplay\.actualDeliveryDate/)
  })

  it('IT-WO-DAILY-UI-007: detail conditionally renders each response display value', () => {
    const detailWxml = read('../../orderDetail/orderDetail.wxml')

    assert.match(detailWxml, /orderInfo\.showCustomerTags/)
    assert.match(detailWxml, /customerTagLabels/)
    assert.match(detailWxml, /orderInfo\.showActualDeliveryDate/)
    assert.match(detailWxml, /orderInfo\.actualDeliveryDateDisplay/)
  })

  it('IT-WO-DAILY-UI-008: confirm conditionally renders each response display value', () => {
    const confirmWxml = read('../../confirmOrder/confirmOrder.wxml')

    assert.match(confirmWxml, /orderInfo\.showCustomerTags/)
    assert.match(confirmWxml, /customerTagLabels/)
    assert.match(confirmWxml, /orderInfo\.showActualDeliveryDate/)
    assert.match(confirmWxml, /orderInfo\.actualDeliveryDateDisplay/)
  })

  it('IT-WO-DAILY-UI-009: construction detail renders returned daily fields independently', () => {
    const detailJs = read(
      '../../constructionOrderDetail/constructionOrderDetail.js'
    )
    const detailWxml = read(
      '../../constructionOrderDetail/constructionOrderDetail.wxml'
    )
    const detailSass = read(
      '../../constructionOrderDetail/constructionOrderDetail.sass'
    )

    assert.match(detailJs, /buildBoutiqueCustomerDailyDisplay/)
    assert.match(
      detailJs,
      /buildBoutiqueCustomerDailyDisplay\(\s*data\.customer\s*\)/
    )
    assert.match(detailJs, /data\.showCustomerTags/)
    assert.match(detailJs, /data\.showActualDeliveryDate/)
    assert.match(detailJs, /customerTagLabels:\s*data\.customerTagLabels/)
    assert.match(detailWxml, /orderInfo\.showCustomerTags/)
    assert.match(detailWxml, /customerTagLabels/)
    assert.match(detailWxml, /orderInfo\.showActualDeliveryDate/)
    assert.match(detailWxml, /orderInfo\.actualDeliveryDateDisplay/)
    assert.match(
      detailSass,
      /\.daily-tag-list\s*\{[\s\S]*?gap:\s*var\(--fontSize12\);[\s\S]*?\}/
    )
    assert.match(
      detailSass,
      /\.daily-tag\s*\{[\s\S]*?padding:\s*var\(--fontSize6\)\s+var\(--fontSize14\);[\s\S]*?background:\s*#F2F6FF;[\s\S]*?border:\s*var\(--fontSize1\)\s+solid\s+#9BBCFF;[\s\S]*?\}/
    )
  })

  it('IT-WO-DAILY-UI-010: boutique read-only pages resolve the phone from the full response', () => {
    const orderDetail = read('../../orderDetail/orderDetail.js')
    const constructionDetail = read(
      '../../constructionOrderDetail/constructionOrderDetail.js'
    )
    const confirmOrder = read('../../confirmOrder/confirmOrder.js')

    ;[orderDetail, constructionDetail, confirmOrder].forEach(source => {
      assert.match(source, /resolveBoutiqueDetailCustomerPhone\(data\)/)
    })
  })

  it('IT-WO-DAILY-UI-006: create popup has no clear action', () => {
    const wxml = read('../createOrder.wxml')

    assert.doesNotMatch(wxml, /bindtap="onClearCustomerTags">清空/)
    assert.match(wxml, /onCancelCustomerTags/)
    assert.match(wxml, /onConfirmCustomerTags/)
  })

  it('IT-WO-DAILY-UI-013: create echo uses the tested two-phase coordinator and request guard', () => {
    const page = read('../createOrder.js')
    const hydration = read('../services/orderHydration.helpers.js')

    assert.match(page, /buildBoutiqueOrderHydration/)
    assert.match(hydration, /coordinateBoutiqueCustomerDailyFieldsEcho/)
    assert.match(page, /coordinateBoutiqueCustomerDailyFieldsEcho/)
    assert.match(
      hydration,
      /orderObj\.customer\s*=\s*coordinateBoutiqueCustomerDailyFieldsEcho\(\{[\s\S]*?phase:\s*["']pending["'][\s\S]*?customer:\s*orderObj\.customer[\s\S]*?\}\)/
    )
    assert.match(
      page,
      /coordinateBoutiqueCustomerDailyFieldsEcho\(\{[\s\S]*?phase:\s*'resolved'[\s\S]*?requestMerchantId[\s\S]*?currentMerchantId[\s\S]*?requestId[\s\S]*?currentRequestId[\s\S]*?\}\)/
    )
    assert.match(
      page,
      /applyBoutiqueCustomerDailyFields\([\s\S]*?this\._boutiqueCustomerDailyFieldsEchoPending[\s\S]*?coordinateBoutiqueCustomerDailyFieldsEcho\(\{[\s\S]*?phase:\s*'pending'[\s\S]*?return/
    )
    assert.ok(
      (page.match(/phase:\s*'resolved'/g) || []).length >= 2,
      'brand setData callback must re-check the resolved request before applying customer data'
    )
  })

  it('IT-WO-DAILY-UI-014: boutique main list builds and conditionally renders daily fields', () => {
    const mainListJs = read(
      '../../../../pages/tabWorkOrder/pages/index/index.js'
    )
    const mainListWxml = read(
      '../../../../pages/tabWorkOrder/pages/index/index.wxml'
    )

    assert.match(mainListJs, /buildBoutiqueCustomerDailyListDisplay/)
    assert.match(
      mainListJs,
      /from '~\/utils\/boutiqueCustomerDailyDisplay\.helpers\.js'/
    )
    assert.doesNotMatch(mainListJs, /from '~\/tabWorkOrder\//)
    assert.match(
      mainListJs,
      /e\.customerDailyDisplay\s*=\s*buildBoutiqueCustomerDailyListDisplay\(e\)/
    )
    assert.match(mainListWxml, /li\.customerDailyDisplay\.showCustomerTags/)
    assert.match(mainListWxml, /li\.customerDailyDisplay\.customerTagsText/)
    assert.match(
      mainListWxml,
      /li\.customerDailyDisplay\.showActualDeliveryDate/
    )
    assert.match(mainListWxml, /li\.customerDailyDisplay\.actualDeliveryDate/)

    const orderListStart = mainListWxml.indexOf('<view class="order-list">')
    const orderPayTypeStart = mainListWxml.indexOf(
      '<view class="order-payType"'
    )
    const dailyTagStart = mainListWxml.indexOf(
      'li.customerDailyDisplay.showCustomerTags'
    )
    const deliveryDateStart = mainListWxml.indexOf(
      'li.customerDailyDisplay.showActualDeliveryDate'
    )
    assert.ok(
      orderListStart < dailyTagStart && dailyTagStart < orderPayTypeStart
    )
    assert.ok(
      orderListStart < deliveryDateStart &&
        deliveryDateStart < orderPayTypeStart
    )
  })

  it('IT-WO-DAILY-UI-015: customer source picker remounts with the current source index', () => {
    const wxml = read('../createOrder.wxml')
    const sourcePopup = wxml.match(
      /<van-popup show="\{\{ showSource \}\}"[\s\S]*?<\/van-popup>/
    )?.[0]

    assert.ok(sourcePopup, 'customer source popup must exist')
    assert.match(sourcePopup, /<van-picker[\s\S]*?wx:if="\{\{ showSource \}\}"/)
    assert.match(
      sourcePopup,
      /default-index="\{\{ customerSourcePickerIndex \}\}"/
    )
  })
})