quotationFirstStep.events.test.mjs
1.97 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
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/)
})