test_store.uts
1.38 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
import store from '@/store/index.uts'
import { watch } from 'vue'
export function testStore() {
console.log("=== 开始 Store 测试 ===")
// 1. 初始状态检查
const initVal = store.state.customerKey
console.log(`初始 customerKey: '${initVal}'`)
// 2. 设置监听器 (模拟 RecordService)
const stopWatch = watch(
() => store.state.customerKey,
(newVal, oldVal) => {
console.log(`[Watch] customerKey 发生变化: '${oldVal}' -> '${newVal}'`)
},
{ immediate: false }
)
// 3. 执行 Commit
console.log("执行 commit('updateCustomerKey', 'TEST_KEY_123')...")
store.commit('updateCustomerKey', 'TEST_KEY_123')
// 4. 验证状态
// 验证扁平化访问
const flatState = store.state.customerKey
const flatPass = flatState === 'TEST_KEY_123'
console.log(`验证扁平化访问: ${flatPass ? 'PASS' : 'FAIL'} (期望: 'TEST_KEY_123', 实际: '${flatState}')`)
// 验证模块化访问
const moduleState = store.state.reception.customerKey
const modulePass = moduleState === 'TEST_KEY_123'
console.log(`验证模块化访问: ${modulePass ? 'PASS' : 'FAIL'} (期望: 'TEST_KEY_123', 实际: '${moduleState}')`)
// 5. 清理
stopWatch()
// 恢复状态 (可选)
// store.commit('updateCustomerKey', initVal)
console.log("=== Store 测试结束 ===")
}