quotationSecondStep.events.test.mjs
3.99 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
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('quotation step components never obtain or mutate a parent page instance', () => {
for (const relativePath of [
'packageEquity/pages/carQuotation/components/FirstStep/FirstStep.js',
'packageEquity/pages/carQuotation/components/SecondStep/SecondStep.js',
'packageEquity/pages/carQuotation/components/SecondStepSimple/SecondStep.js'
]) {
assert.doesNotMatch(read(relativePath), /getPageInstance\s*\(/, relativePath)
}
})
test('both SecondStep components publish order patches', () => {
for (const relativePath of [
'packageEquity/pages/carQuotation/components/SecondStep/SecondStep.js',
'packageEquity/pages/carQuotation/components/SecondStepSimple/SecondStep.js'
]) {
assert.match(read(relativePath), /triggerEvent\(['"]orderChange['"],\s*\{\s*patch:/, relativePath)
}
})
test('standard and simple pages bind SecondStep order patches', () => {
for (const relativePath of [
'packageEquity/pages/carQuotation/createOrderCarQuotation/createOrderCarQuotation.wxml',
'packageEquity/pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.wxml'
]) {
assert.match(read(relativePath), /<second-step[\s\S]*bind:orderChange="handleOrderChange"/)
}
})
test('simple quotation goods components report selection through events instead of mutating a page instance', () => {
const goodsPackage = read(
'packageEquity/pages/carQuotation/components/GoodsPackage/Goods.js'
)
const skuGoods = read('packageEquity/components/SkuGoods/Goods.js')
for (const source of [goodsPackage, skuGoods]) {
assert.doesNotMatch(source, /getPageInstance\s*\(/)
assert.match(source, /triggerEvent\(['"]confirm['"]/)
assert.match(source, /triggerEvent\(['"]cancel['"]/)
}
assert.match(goodsPackage, /triggerEvent\(['"]refreshRequested['"]/)
assert.match(goodsPackage, /triggerEvent\(['"]skuRequested['"]/)
assert.match(skuGoods, /triggerEvent\(['"]visibilityChange['"]/)
})
test('simple quotation owns goods events and boutique consumes the shared sku payload', () => {
const simpleStep = read(
'packageEquity/pages/carQuotation/components/SecondStepSimple/SecondStep.js'
)
const simpleStepTemplate = read(
'packageEquity/pages/carQuotation/components/SecondStepSimple/SecondStep.wxml'
)
const simplePage = read(
'packageEquity/pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.js'
)
const simplePageTemplate = read(
'packageEquity/pages/carQuotation/createOrderCarQuotationSimple/createOrderCarQuotationSimple.wxml'
)
const boutiquePage = read('tabWorkOrder/pages/createOrder/createOrder.js')
assert.match(simpleStepTemplate, /bind:refreshRequested="onGoodsRefreshRequested"/)
assert.match(simpleStepTemplate, /bind:skuRequested="onGoodsSkuRequested"/)
assert.match(simpleStepTemplate, /<goods[\s\S]*bind:cancel="onGoodsCancel"/)
assert.match(simpleStepTemplate, /<sku-goods[\s\S]*bindconfirm="onSkuGoodsConfirm"/)
assert.match(simpleStepTemplate, /<sku-goods[\s\S]*bindcancel="onSkuGoodsCancel"/)
assert.match(simpleStepTemplate, /<sku-goods[\s\S]*bind:visibilityChange="onSkuVisibilityChange"/)
assert.match(simpleStep, /triggerEvent\(['"]catalogRefreshRequested['"]/)
assert.match(simpleStep, /triggerEvent\(['"]popupVisibilityChange['"]/)
assert.match(simplePageTemplate, /bind:catalogRefreshRequested="handleCatalogRefreshRequested"/)
assert.match(simplePageTemplate, /bind:popupVisibilityChange="handlePopupVisibilityChange"/)
assert.match(simplePage, /handleCatalogRefreshRequested\s*\(/)
assert.match(simplePage, /handlePopupVisibilityChange\s*\(/)
assert.match(boutiquePage, /onSkuGoodsConfirm\s*\(e\)[\s\S]*e\.detail[\s\S]*setGoodsTotal/)
})