confirm-order-wechat-action.test.mjs 1.66 KB
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { describe, it } from 'node:test'

const template = readFileSync(
  new URL(
    '../../tabWorkOrder/pages/confirmOrder/confirmOrder.wxml',
    import.meta.url
  ),
  'utf8'
)
const styles = readFileSync(
  new URL(
    '../../tabWorkOrder/pages/confirmOrder/confirmOrder.wxss',
    import.meta.url
  ),
  'utf8'
)

describe('confirmOrder confirmation action', () => {
  it('always renders exactly one confirmation action independent of payment type and role', () => {
    const confirmationActions = template.match(/bindtap="next"/g) || []
    assert.equal(confirmationActions.length, 1)
    assert.match(template, /<view class="btn-box confirm-btn/)

    const footer = template.slice(template.indexOf('<view class="btn-box confirm-btn'))
    assert.doesNotMatch(footer, /wx:if="\{\{ orderInfo\.selectPayType/)
    assert.doesNotMatch(
      footer,
      /wx:if="\{\{ !perm\.hasPermission\.isSuper\(userInfo\)/
    )
  })

  it('keeps order editing inside the original operator permission gate', () => {
    assert.match(
      template,
      /<block wx:if="\{\{ orderInfo\.status == 1 && !perm\.hasPermission\.isSuper\(userInfo\) && userInfo\.userType == 2 \}\}">\s*<view class="btn text-center change" bindtap="edit">修改<\/view>/
    )
    assert.equal((template.match(/bindtap="edit"/g) || []).length, 1)
  })

  it('reserves the bottom safe area and renders a lone action full width', () => {
    assert.match(template, /isFullSucreen \? 'isFullSucreenCom' : ''/)
    assert.match(
      styles,
      /\.confirm-btn \.single-confirm-btn \{\s*width: calc\(100% - var\(--fontSize64\)\);\s*\}/
    )
  })
})