workOrderLowPriceGuard.test.mjs
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import {
LOW_PRICE_ORDER_EDIT_MESSAGE,
isLowPriceOrder,
shouldBlockLowPriceOrderEdit
} from '../utils/workOrderLowPrice.helpers.js'
const read = relativePath =>
readFileSync(fileURLToPath(new URL(relativePath, import.meta.url)), 'utf8')
describe('work order low-price edit guard', () => {
it('recognizes numeric and string lowPriceFlag values', () => {
assert.equal(isLowPriceOrder({ lowPriceFlag: 1 }), true)
assert.equal(isLowPriceOrder({ lowPriceFlag: '1' }), true)
assert.equal(isLowPriceOrder({ lowPriceFlag: 0 }), false)
assert.equal(isLowPriceOrder(null), false)
})
it('blocks only an existing low-price order entering createOrder', () => {
const lowPriceOrder = { orderCode: 'LOW-001', lowPriceFlag: 1 }
assert.equal(
shouldBlockLowPriceOrderEdit(lowPriceOrder, 'createOrder'),
true
)
assert.equal(
shouldBlockLowPriceOrderEdit(lowPriceOrder, 'orderDetail'),
false
)
assert.equal(
shouldBlockLowPriceOrderEdit(lowPriceOrder, 'confirmOrder'),
false
)
assert.equal(shouldBlockLowPriceOrderEdit(undefined, 'createOrder'), false)
assert.equal(LOW_PRICE_ORDER_EDIT_MESSAGE, '低价单不可以编辑')
})
it('wires lowPriceFlag=0 from the create-order customer archive popup', () => {
const createOrderWxml = read(
'../tabWorkOrder/pages/createOrder/createOrder.wxml'
)
const customerInfoJs = read(
'../tabWorkOrder/components/CustomerInfo/CustomerInfo.js'
)
assert.match(
createOrderWxml,
/<customerInfo[\s\S]*?lowPriceFlag="\{\{ 0 \}\}"[\s\S]*?\/>/
)
assert.match(customerInfoJs, /buildCustomerListRequestParams/)
})
it('disables confirmation edits and hides customer-info edits on low-price details', () => {
const confirmWxml = read(
'../tabWorkOrder/pages/confirmOrder/confirmOrder.wxml'
)
const confirmJs = read(
'../tabWorkOrder/pages/confirmOrder/confirmOrder.js'
)
const detailWxml = read(
'../tabWorkOrder/pages/orderDetail/orderDetail.wxml'
)
const constructionDetailWxml = read(
'../tabWorkOrder/pages/constructionOrderDetail/constructionOrderDetail.wxml'
)
assert.match(confirmWxml, /low-price-disabled/)
assert.match(confirmWxml, /orderInfo\.lowPriceFlag != 1/)
assert.match(confirmJs, /isLowPriceOrder\(orderInfo\)/)
assert.match(detailWxml, /orderInfo\.lowPriceFlag == 1 \? 'isHide'/)
assert.match(
constructionDetailWxml,
/orderInfo\.lowPriceFlag != 1/
)
})
it('uses the shared guard in every registered list that can enter createOrder', () => {
const listFiles = [
'../pages/tabWorkOrder/pages/index/index.js',
'../tabWorkOrder/pages/tabWorkOrderRelevance/index.js',
'../tabWorkOrder/pages/technicianSearchList/pages/index/technicianSearchList.js'
]
listFiles.forEach(file => {
assert.match(read(file), /shouldBlockLowPriceOrderEdit\(item, name\)/)
})
})
})