quotationFirstStep.events.test.mjs 1.97 KB
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'

const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const read = relativePath => readFileSync(path.join(projectRoot, relativePath), 'utf8')

test('FirstStep reports explicit owner, order, scene, customer and goods-reset events', () => {
  const source = read('packageEquity/pages/carQuotation/components/FirstStep/FirstStep.js')
  assert.doesNotMatch(source, /getPageInstance\s*\(/)
  for (const eventName of [
    'ownerChange',
    'orderChange',
    'sceneChange',
    'customerSelected',
    'resetGoodsRequested'
  ]) {
    assert.match(source, new RegExp(`triggerEvent\\(['"]${eventName}['"]`), eventName)
  }
})

test('standard and simple pages bind every FirstStep state event', () => {
  for (const relativePath of [
    'packageEquity/pages/carQuotation/createOrderCarQuotation/createOrderCarQuotation.wxml',
    'packageEquity/pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.wxml'
  ]) {
    const template = read(relativePath)
    for (const [eventName, handler] of [
      ['ownerChange', 'handleOwnerChange'],
      ['orderChange', 'handleOrderChange'],
      ['sceneChange', 'handleSceneChange'],
      ['customerSelected', 'handleCustomerSelected'],
      ['resetGoodsRequested', 'handleResetGoodsRequested']
    ]) {
      assert.match(template, new RegExp(`bind:${eventName}="${handler}"`), relativePath)
    }
  }
})

test('GLForm includes the changed value so FirstStep never reads stale parent props', () => {
  const formSource = read('packageEquity/components/GLForm/GLForm.js')
  const firstStepSource = read(
    'packageEquity/pages/carQuotation/components/FirstStep/FirstStep.js'
  )
  assert.match(formSource, /triggerEvent\(['"]inputEvent['"],\s*\{\s*attr,\s*value\s*\}/s)
  assert.match(firstStepSource, /const value = e\.detail\.value/)
})