simpleQuotationPage.contract.test.mjs 3.5 KB
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import { describe, it } from 'node:test'

const pageUrl = new URL(
  '../pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.js',
  import.meta.url
)
const firstStepUrl = new URL(
  '../pages/carQuotation/components/FirstStep/FirstStep.js',
  import.meta.url
)

describe('simple quotation page contract', () => {
  it('IT-EQ-SIMPLE-PAGE-001: keeps business transformations in local services without cross-package imports', async () => {
    const source = await readFile(pageUrl, 'utf8')

    assert.match(source, /simpleQuotationCatalog\.helpers\.js/)
    assert.match(source, /simpleQuotationRoute\.helpers\.js/)
    assert.match(source, /simpleQuotationValidation\.helpers\.js/)
    assert.match(source, /simpleQuotationFormConfig\.helpers\.js/)
    assert.doesNotMatch(source, /tabWorkOrder|packageEquityAI/)
  })

  it('IT-EQ-SIMPLE-PAGE-002: removes debug output and the disabled wait-order polling path', async () => {
    const source = await readFile(pageUrl, 'utf8')

    assert.doesNotMatch(source, /console\.log\s*\(/)
    assert.doesNotMatch(source, /\bwaitinputorder\b/)
    assert.doesNotMatch(source, /\bgetWaitOrder\b/)
    assert.doesNotMatch(source, /\bsetTime\s*\(/)
    assert.doesNotMatch(source, /\bupdateOrderStatus\b/)
  })

  it('IT-EQ-SIMPLE-PAGE-003: delegates checkout, total and car-selection lifecycle to local services', async () => {
    const source = await readFile(pageUrl, 'utf8')

    assert.match(source, /submitSimpleQuotationCheckout\s*\(/)
    assert.match(source, /calculateSimpleQuotationTotal\s*\(/)
    assert.match(source, /bindSimpleQuotationCarSelection\s*\(/)
    assert.match(source, /onUnload\s*\(\)[\s\S]*?_disposeCarSelection/)
    assert.doesNotMatch(source, /total\s*\/\s*100/)
    assert.doesNotMatch(source, /wx\.\$eventbus\.on\s*\(\s*['"]set_car_info/)
    assert.doesNotMatch(source, /\binit\s*\(\)\s*\{\s*\}/)
    assert.doesNotMatch(source, /onShareAppMessage\s*\(\)\s*\{\s*\}/)
  })

  it('IT-EQ-SIMPLE-PAGE-004: configures FirstStep through its public method', async () => {
    const [pageSource, firstStepSource] = await Promise.all([
      readFile(pageUrl, 'utf8'),
      readFile(firstStepUrl, 'utf8')
    ])

    assert.match(pageSource, /firstCom\.applyFormConfig\s*\(formConfig\)/)
    assert.doesNotMatch(pageSource, /firstCom\.setData\s*\(/)
    assert.match(firstStepSource, /async\s+applyFormConfig\s*\(config\s*=\s*\{\}\)/)
  })

  it('IT-EQ-SIMPLE-PAGE-005: keeps new services free of page, route and cross-package effects', async () => {
    for (const serviceName of [
      'simpleQuotationCheckout.workflow.js',
      'simpleQuotationTotal.helpers.js',
      'simpleQuotationLifecycle.js'
    ]) {
      const source = await readFile(
        new URL(`../pages/carQuotation/services/${serviceName}`, import.meta.url),
        'utf8'
      )
      assert.doesNotMatch(source, /\bwx\./, serviceName)
      assert.doesNotMatch(source, /\bsetData\s*\(/, serviceName)
      assert.doesNotMatch(source, /\$router/, serviceName)
      assert.doesNotMatch(source, /tabWorkOrder|packageEquityAI/, serviceName)
    }
  })

  it('IT-EQ-SIMPLE-PAGE-006: closes the payment-document popup before recording success feedback and delayed navigation', async () => {
    const source = await readFile(pageUrl, 'utf8')

    assert.match(
      source,
      /outcome\.status === ["']list["'] && context\.isRecording[\s\S]*?this\.setData\(outcome\.patch\)[\s\S]*?wx\.showToast[\s\S]*?setTimeout/
    )
  })
})