quotationCustomerDailyFields.ui.test.mjs 6.26 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('quotation customer daily field UI contract', () => {
  it('IT-EQ-DAILY-UI-001: standard and simple forms contain both optional fields', () => {
    const config = read('../pages/carQuotation/components/constant/stepData.js')
    const wxml = read('../pages/carQuotation/components/FirstStep/FirstStep.wxml')
    assert.equal((config.match(/label: "日报标签"/g) || []).length, 2)
    assert.equal((config.match(/label: "实际交付日期"/g) || []).length, 2)
    assert.match(wxml, /equityCustomerTagsPopup/)
    assert.match(wxml, /onConfirmEquityCustomerTags/)
    assert.match(wxml, /mode="date"/)
  })

  it('IT-EQ-DAILY-UI-009: delivery date picker prevents selecting a future local date', () => {
    const js = read('../pages/carQuotation/components/FirstStep/FirstStep.js')
    const wxml = read('../pages/carQuotation/components/FirstStep/FirstStep.wxml')

    assert.match(
      wxml,
      /<picker\s+slot="actualDeliveryDate"\s+mode="date"\s+value="\{\{ actualDeliveryDateText \}\}"\s+end="\{\{ actualDeliveryDateMax \}\}"\s+disabled="\{\{ disable \}\}"\s+bindchange="onEquityDeliveryDateChange"\s*>/
    )
    assert.match(
      js,
      /var timeUtil = require\('~\/utils\/timeFormat\/time-utils\.js'\)/
    )
    assert.match(
      js,
      /actualDeliveryDateMax:\s*timeUtil\.getTodayDateStr\(\)/
    )
  })

  it('IT-EQ-DAILY-UI-010: visible delivery date shows required state and blocks an empty next step', () => {
    const config = read('../pages/carQuotation/components/constant/stepData.js')
    const js = read('../pages/carQuotation/components/FirstStep/FirstStep.js')
    const requiredDateFields = config.match(
      /name: "actualDeliveryDate",[\s\S]*?required: true,[\s\S]*?requiredAfter: true,[\s\S]*?isShowObj:/g
    ) || []

    assert.equal(requiredDateFields.length, 2)
    assert.match(js, /isEquityActualDeliveryDateMissing/)
    assert.match(
      js,
      /isEquityActualDeliveryDateMissing\(\s*dailyFieldVisibility\.actualDeliveryDate,\s*owner\.actualDeliveryDate\s*\)/
    )
    assert.match(js, /wx\.\$util\.showToast\('实际交付日期不能为空'\)/)
  })

  it('IT-EQ-DAILY-UI-002: required certificate config no longer relies on index', () => {
    const page = read(
      '../pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.js'
    )
    const formConfig = read(
      '../pages/carQuotation/services/simpleQuotationFormConfig.helpers.js'
    )
    assert.match(page, /buildSimpleQuotationFormConfig/)
    assert.doesNotMatch(formConfig, /customerFormList\[6\]/)
    assert.match(formConfig, /findIndex\([\s\S]*certificateNo/)
  })

  it('IT-EQ-DAILY-UI-003: payment detail shows stored daily fields', () => {
    const detail = read(
      '../pages/carQuotation/CarQuotationDetail/CarQuotationDetail.wxml'
    )
    assert.match(detail, /日报标签/)
    assert.match(detail, /实际交付日期/)
    assert.match(detail, /customerTagLabels/)
  })

  it('IT-EQ-DAILY-UI-004: add, update and additional recording share owner formatting', () => {
    const standard = read(
      '../pages/carQuotation/createOrderCarQuotation/createOrderCarQuotation.js'
    )
    const simple = read(
      '../pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.js'
    )
    assert.match(standard, /getOwnerInfo\(\)[\s\S]*buildOwnerPayload/)
    assert.match(
      standard,
      /orderInfo\.owner = owner[\s\S]*submitStandardQuotation\([\s\S]*quotationAdd,[\s\S]*updateQuotation/
    )
    assert.match(simple, /getOwnerInfo\(\)[\s\S]*buildOwnerPayload/)
    assert.match(
      simple,
      /setQuotationRecording\(preparedOrderInfo\)[\s\S]*preparedOrderInfo \|\| this\.getInsurance\(\)[\s\S]*recordSimpleQuotationOrder/
    )
    assert.match(
      simple,
      /const insurance = this\.getInsurance\(\)[\s\S]*submitSimpleQuotationCheckout\([\s\S]*quotationAdd,[\s\S]*updateQuotation,[\s\S]*errorOrderById/
    )
  })

  it('IT-EQ-DAILY-UI-005: FirstStep hides the whole date row through GLForm visibility context', () => {
    const form = read('../components/GLForm/GLForm.wxml')
    const firstStep = read(
      '../pages/carQuotation/components/FirstStep/FirstStep.wxml'
    )
    assert.match(form, /visibilityMap/)
    assert.match(firstStep, /visibilityMap="\{\{ dailyFieldVisibility \}\}"/)
  })

  it('IT-EQ-DAILY-UI-006: standard and simple submitters pass order scene context', () => {
    const standard = read(
      '../pages/carQuotation/createOrderCarQuotation/createOrderCarQuotation.js'
    )
    const simple = read(
      '../pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.js'
    )
    assert.match(
      standard,
      /buildOwnerPayload\([\s\S]*this\.data\.needChangeList,[\s\S]*orderInfo[\s\S]*\)/
    )
    assert.match(
      simple,
      /buildOwnerPayload\([\s\S]*this\.data\.needChangeList,[\s\S]*this\.data\.orderInfo[\s\S]*\)/
    )
  })

  it('IT-EQ-DAILY-UI-007: quotation list renders normalized response fields conditionally', () => {
    const listJs = read('../pages/carQuotation/index/index.js')
    const listWxml = read('../pages/carQuotation/index/index.wxml')

    assert.match(listJs, /buildEquityCustomerDailyListDisplay/)
    assert.match(
      listJs,
      /item\.customerDailyDisplay\s*=\s*buildEquityCustomerDailyListDisplay\(item\)/
    )
    assert.doesNotMatch(
      listJs,
      /item\.customerDailyDisplay\s*=\s*buildEquityCustomerDailyDisplay\(item\)/
    )
    assert.match(listWxml, /item\.customerDailyDisplay\.showCustomerTags/)
    assert.match(listWxml, /item\.customerDailyDisplay\.customerTagsText/)
    assert.match(listWxml, /item\.customerDailyDisplay\.showActualDeliveryDate/)
    assert.match(listWxml, /item\.customerDailyDisplay\.actualDeliveryDate/)
  })

  it('IT-EQ-DAILY-UI-008: FirstStep popup has no clear action', () => {
    const wxml = read('../pages/carQuotation/components/FirstStep/FirstStep.wxml')

    assert.doesNotMatch(wxml, /bindtap="onClearEquityCustomerTags">清空/)
    assert.match(wxml, /onCancelEquityCustomerTags/)
    assert.match(wxml, /onConfirmEquityCustomerTags/)
  })
})