@tbox.cn/app-module-parking 0.2.0 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/AGENTS.md +16 -0
  2. package/README.md +58 -11
  3. package/dist/chunk-O4W4A6TQ.js +2696 -0
  4. package/dist/chunk-QSHINO4B.js +1073 -0
  5. package/dist/client/index.d.ts +17 -3
  6. package/dist/client/index.js +4 -2
  7. package/dist/index.d.ts +4 -3
  8. package/dist/index.js +14 -4
  9. package/dist/parking-BC2TJ5GU.css +1306 -0
  10. package/dist/server/index.d.ts +1216 -72
  11. package/dist/server/index.js +11 -3
  12. package/package.json +24 -16
  13. package/skills/parking/SKILL.md +165 -0
  14. package/skills/parking/references/payment-safety.md +25 -0
  15. package/src/client/cards/index.ts +8 -0
  16. package/src/client/cards/parking-info/index.tsx +41 -0
  17. package/src/client/cards/parking-payment/benefit-selection.ts +79 -0
  18. package/src/client/cards/parking-payment/index.tsx +435 -0
  19. package/src/client/cards/parking-payment-records/index.tsx +259 -0
  20. package/src/client/cards/parking-payment-result/index.tsx +83 -0
  21. package/src/client/cards/parking-vehicle-management/PlateKeyboard.tsx +106 -0
  22. package/src/client/cards/parking-vehicle-management/index.tsx +344 -0
  23. package/src/client/cards/parking-vehicle-management/plate-keyboard.ts +113 -0
  24. package/src/client/cards/view.ts +83 -0
  25. package/src/client/index.ts +19 -4
  26. package/src/client/styles/parking.css +1306 -0
  27. package/src/client/types/css.d.ts +2 -0
  28. package/src/server/actions.ts +975 -0
  29. package/src/server/cards/index.ts +14 -0
  30. package/src/server/cards/parking-info/meta.ts +19 -0
  31. package/src/server/cards/parking-info/samples.ts +50 -0
  32. package/src/server/cards/parking-payment/meta.ts +29 -0
  33. package/src/server/cards/parking-payment/samples.ts +311 -0
  34. package/src/server/cards/parking-payment-records/meta.ts +32 -0
  35. package/src/server/cards/parking-payment-records/samples.ts +86 -0
  36. package/src/server/cards/parking-payment-result/meta.ts +21 -0
  37. package/src/server/cards/parking-payment-result/samples.ts +84 -0
  38. package/src/server/cards/parking-vehicle-management/meta.ts +20 -0
  39. package/src/server/cards/parking-vehicle-management/samples.ts +73 -0
  40. package/src/server/domain.ts +279 -0
  41. package/src/server/handler.ts +65 -16
  42. package/src/server/index.ts +120 -18
  43. package/src/server/intent-context.ts +14 -0
  44. package/src/server/ports.ts +59 -0
  45. package/src/server/service.ts +474 -45
  46. package/src/server/tools.ts +846 -0
  47. package/tbox.module.json +107 -0
  48. package/tests/benefit-selection.test.ts +70 -0
  49. package/tests/cards-render.test.tsx +645 -0
  50. package/tests/dispatcher-flow.test.ts +256 -0
  51. package/tests/payment-flow.test.ts +420 -0
  52. package/tests/plate-keyboard.test.ts +158 -0
  53. package/tests/ports-resolve.test.ts +113 -0
  54. package/tests/pretool-parking-fee.test.ts +104 -0
  55. package/tests/samples.test.ts +44 -0
  56. package/tests/skills.test.ts +37 -0
  57. package/tests/snapshot-service.test.ts +87 -0
  58. package/tests/tools-gate.test.ts +237 -0
  59. package/tests/tools-membership.test.ts +91 -0
  60. package/tests/view.test.ts +61 -0
  61. package/tsup.config.ts +9 -1
  62. package/dist/chunk-BYD3C6NE.js +0 -140
  63. package/dist/chunk-QQLBZY6D.js +0 -55
  64. package/src/client/cards/parking-fee/index.tsx +0 -59
  65. package/src/server/cards/parking-fee/meta.ts +0 -26
  66. package/src/server/tool.ts +0 -36
  67. package/tbox.component.json +0 -20
  68. package/tests/service.test.ts +0 -49
@@ -0,0 +1,645 @@
1
+ /**
2
+ * module-parking 客户端卡片渲染测试(0.4.0 D9:happy-dom + createRoot/flushSync)。
3
+ * 范式卡 parking-payment:会员状态 / 积分与直接支付双入口 / isHistory 与 token 门禁。
4
+ * 源数据:契约 sampleData 语义(VISUAL_RESTORE 纪律)。
5
+ */
6
+ // @vitest-environment happy-dom
7
+ import { describe, expect, it, vi } from 'vitest';
8
+ import { createRoot } from 'react-dom/client';
9
+ import { act } from 'react-dom/test-utils';
10
+ import { sendCardAction } from '@tbox.cn/app-sdk/client';
11
+ import {
12
+ ParkingPaymentCard,
13
+ ParkingPaymentRecordsCard,
14
+ ParkingPaymentResultCard,
15
+ ParkingVehicleManagementCard,
16
+ } from '../src/client/cards';
17
+
18
+ vi.mock('@tbox.cn/app-sdk/client', async (importOriginal) => {
19
+ const actual =
20
+ await importOriginal<typeof import('@tbox.cn/app-sdk/client')>();
21
+ return { ...actual, sendCardAction: vi.fn() };
22
+ });
23
+
24
+ const baseData = {
25
+ quoteRef: 'q1',
26
+ revision: 1,
27
+ plateNo: '浙A12345',
28
+ durationText: '2 小时 15 分',
29
+ entryAtText: '08-12 09:30',
30
+ feeItems: [
31
+ { name: '首小时', amountText: '¥6' },
32
+ { name: '后续时长', amountText: '¥9' },
33
+ ],
34
+ totalText: '¥15',
35
+ payableText: '¥13.50',
36
+ membership: { state: 'active', availablePoints: 1200 },
37
+ paymentOptions: {
38
+ direct: { payableText: '¥15', benefitRefs: ['member-discount'] },
39
+ points: {
40
+ kind: 'exact',
41
+ pointsToUse: 500,
42
+ payableText: '¥10',
43
+ benefitRefs: ['member-discount', 'points-offset'],
44
+ },
45
+ },
46
+ appliedBenefits: [{ benefitRef: 'b1', title: '会员 9 折', discountText: '¥1.50' }],
47
+ selectableBenefits: [
48
+ { benefitRef: 'b1', title: '会员 9 折', autoSelected: true },
49
+ { benefitRef: 'b2', title: '商场满减券', autoSelected: false },
50
+ ],
51
+ caveats: ['以商场停车系统实时结算为准'],
52
+ };
53
+
54
+ function render(ui: React.ReactElement) {
55
+ const host = document.createElement('div');
56
+ document.body.appendChild(host);
57
+ const root = createRoot(host);
58
+ act(() => {
59
+ root.render(ui);
60
+ });
61
+ return { host, root };
62
+ }
63
+
64
+ describe('ParkingPaymentCard(范式卡)', () => {
65
+ it('按商场停车服务卡层级渲染完整车牌、摘要与账单', () => {
66
+ const { host } = render(
67
+ <ParkingPaymentCard
68
+ data={baseData as never}
69
+ cardId="c1"
70
+ isHistory={false}
71
+ actionTokens={{
72
+ 'parking.confirm-payment': 'tok',
73
+ 'parking.reprice': 'tok',
74
+ }}
75
+ />,
76
+ );
77
+ // 素材变量链(主题轨 T-2.3):装饰主视觉 img → CSS background(--tbox-asset-parking-hero),容器保留、img 不再渲染
78
+ expect(host.querySelector('.parking-payment__hero')).not.toBeNull();
79
+ expect(host.querySelector('.parking-payment__hero-image')).toBeNull();
80
+ expect(host.querySelector('.parking-payment__hero-main')?.textContent).toContain('浙A12345');
81
+ expect(host.querySelector('.parking-payment__summary')?.textContent).toContain('2 小时 15 分');
82
+ expect(host.querySelector('.parking-payment__billing')?.textContent).toContain('¥13.50');
83
+ // 车辆管理归 parking-vehicle-management 卡,缴费卡保持纯粹(不再有「我的车辆」区块)
84
+ expect(host.querySelector('.parking-payment__vehicle')).toBeNull();
85
+ });
86
+
87
+ it('按钮金额取当前报价,不读服务端投影的 paymentOptions', () => {
88
+ const { host } = render(
89
+ <ParkingPaymentCard
90
+ data={baseData as never}
91
+ cardId="c1"
92
+ isHistory={false}
93
+ actionTokens={{
94
+ 'parking.confirm-payment': 'tok',
95
+ 'parking.reprice': 'tok',
96
+ }}
97
+ />,
98
+ );
99
+ expect(host.querySelector('.parking-payment__member-guide')).toBeNull();
100
+ // paymentOptions.points 给的是 ¥10、direct 给的是 ¥15,按钮都不采信——只报当前应付。
101
+ // 用不用积分由上方勾选决定(勾选触发 reprice,报价回来后这个数字才变)。
102
+ expect(host.querySelector('.parking-payment__action--primary')?.textContent).toContain('支付 ¥13.50');
103
+ expect(host.querySelector('.parking-payment__action--text')).toBeNull();
104
+ });
105
+
106
+ it('未入会:展示入会引导且不展示积分入口', () => {
107
+ const { host } = render(
108
+ <ParkingPaymentCard
109
+ data={{ ...baseData, membership: { state: 'not_enrolled' }, paymentOptions: { direct: baseData.paymentOptions.direct } } as never}
110
+ cardId="c1"
111
+ isHistory={false}
112
+ actionTokens={{
113
+ 'parking.confirm-payment': 'tok',
114
+ 'parking.reprice': 'tok',
115
+ }}
116
+ />,
117
+ );
118
+ expect(host.querySelector('.parking-payment__member-guide')?.textContent).toContain('立即入会');
119
+ expect(host.querySelector('.parking-payment__action--text')).toBeNull();
120
+ expect(host.querySelector('.parking-payment__action--primary')?.textContent).toContain('支付 ¥13.50');
121
+ });
122
+
123
+ it('支付提交当前生效的权益组合(与按钮金额同源),不再暴露重算按钮与直付副入口', () => {
124
+ vi.mocked(sendCardAction).mockClear();
125
+ const { host } = render(
126
+ <ParkingPaymentCard
127
+ data={baseData as never}
128
+ cardId="payment-card"
129
+ isHistory={false}
130
+ actionTokens={{
131
+ 'parking.confirm-payment': 'confirm-token',
132
+ }}
133
+ />,
134
+ );
135
+ const confirm = host.querySelector(
136
+ '.parking-payment__action--primary',
137
+ ) as HTMLButtonElement;
138
+ expect(host.querySelector('.parking-payment__action--secondary')).toBeNull();
139
+ act(() => confirm.click());
140
+ expect(sendCardAction).toHaveBeenNthCalledWith(
141
+ 1,
142
+ 'payment-card',
143
+ {
144
+ type: 'moduleAction',
145
+ actionId: 'parking.confirm-payment',
146
+ contextToken: 'confirm-token',
147
+ },
148
+ // 与 payableText ¥13.50 同源:提交 appliedBenefits,服务端比对一致即直接建单不重算
149
+ { quoteRef: 'q1', revision: '1', benefitRefs: ['b1'] },
150
+ );
151
+ // 提交只此一条路径:直付副入口已收敛,避免「勾着积分却点不花积分」的矛盾态
152
+ expect(sendCardAction).toHaveBeenCalledTimes(1);
153
+ });
154
+
155
+ it('应付为零:按钮转说明态并禁用,但页脚提示保留', () => {
156
+ const { host } = render(
157
+ <ParkingPaymentCard
158
+ data={{ ...baseData, payableText: '0.00 元', caveats: ['免费时段内出场不收费'] } as never}
159
+ cardId="c-free"
160
+ isHistory={false}
161
+ actionTokens={{ 'parking.confirm-payment': 'tok', 'parking.reprice': 'tok' }}
162
+ />,
163
+ );
164
+ const primary = host.querySelector<HTMLButtonElement>('.parking-payment__action--primary');
165
+ expect(primary?.textContent).toContain('无需支付停车费用');
166
+ expect(primary?.disabled).toBe(true);
167
+ // 「支付」语义不成立,但「以出场实际计费为准」此刻反而最要紧——现在免费不等于出场时免费
168
+ expect(host.querySelector('.parking-payment__foot')?.textContent).toContain('免费时段内出场不收费');
169
+ });
170
+
171
+ it('应付非零:按钮与免责声明保持原样(零费用判定不得误伤正常场景)', () => {
172
+ const { host } = render(
173
+ <ParkingPaymentCard
174
+ data={{ ...baseData, payableText: '9.25 元' } as never}
175
+ cardId="c-paid"
176
+ isHistory={false}
177
+ actionTokens={{ 'parking.confirm-payment': 'tok', 'parking.reprice': 'tok' }}
178
+ />,
179
+ );
180
+ const primary = host.querySelector<HTMLButtonElement>('.parking-payment__action--primary');
181
+ expect(primary?.textContent).not.toContain('无需支付');
182
+ expect(primary?.disabled).toBe(false);
183
+ expect(host.querySelector('.parking-payment__foot')).not.toBeNull();
184
+ });
185
+
186
+
187
+
188
+
189
+ it('等级权益不进优惠区,作为费用明细的减项呈现', () => {
190
+ const { host } = render(
191
+ <ParkingPaymentCard
192
+ data={{
193
+ ...baseData,
194
+ selectableBenefits: [
195
+ { benefitRef: 'lv1', title: '金卡 95 折', kind: 'discount', autoSelected: true },
196
+ { benefitRef: 'c1', title: '商场满减券', kind: 'coupon', autoSelected: false },
197
+ ],
198
+ appliedBenefits: [{ benefitRef: 'lv1', title: '金卡 95 折', discountText: '¥0.75' }],
199
+ } as never}
200
+ cardId="c-level"
201
+ isHistory={false}
202
+ actionTokens={{ 'parking.confirm-payment': 'tok', 'parking.reprice': 'tok' }}
203
+ />,
204
+ );
205
+ // 够等级就自动生效,用户对它没有决策权 → 不出现在可勾选列表
206
+ const options = host.querySelectorAll('.parking-payment__benefit-option');
207
+ expect(options.length).toBe(1);
208
+ expect(options[0]?.textContent).toContain('商场满减券');
209
+ // 改由费用明细陈述
210
+ expect(host.querySelector('.parking-payment__fees')?.textContent).toContain('金卡 95 折');
211
+ expect(host.querySelector('.parking-payment__fees')?.textContent).toContain('-¥0.75');
212
+ });
213
+
214
+ it('优惠减免金额统一带单个负号', () => {
215
+ const { host } = render(
216
+ <ParkingPaymentCard
217
+ data={{ ...baseData, discountText: '¥1.50' } as never}
218
+ cardId="c-discount-sign"
219
+ isHistory={false}
220
+ actionTokens={{ 'parking.confirm-payment': 'tok', 'parking.reprice': 'tok' }}
221
+ />,
222
+ );
223
+ expect(host.querySelector('.parking-payment__summary-item--benefit strong')?.textContent).toBe('-¥1.50');
224
+ expect(host.querySelector('.parking-payment__fee--discount dd')?.textContent).toBe('-¥1.50');
225
+ expect(host.querySelector('.parking-payment__benefit-amount')?.textContent).toBe('-¥1.50');
226
+
227
+ const { host: negativeHost } = render(
228
+ <ParkingPaymentCard
229
+ data={{
230
+ ...baseData,
231
+ discountText: '-¥1.50',
232
+ appliedBenefits: [{ benefitRef: 'b1', title: '会员 9 折', discountText: '¥-1.50' }],
233
+ } as never}
234
+ cardId="c-existing-discount-sign"
235
+ isHistory={false}
236
+ actionTokens={{ 'parking.confirm-payment': 'tok', 'parking.reprice': 'tok' }}
237
+ />,
238
+ );
239
+ expect(negativeHost.querySelector('.parking-payment__summary-item--benefit strong')?.textContent).toBe('-¥1.50');
240
+ expect(negativeHost.querySelector('.parking-payment__benefit-amount')?.textContent).toBe('-¥1.50');
241
+ expect(negativeHost.textContent).not.toContain('--¥1.50');
242
+ });
243
+
244
+ it('等级权益 autoSelected=false 仍可勾选,不能凭空消失', () => {
245
+ const { host } = render(
246
+ <ParkingPaymentCard
247
+ data={{
248
+ ...baseData,
249
+ // 三元权益的一种下发形态:等级权益标 discount 但默认不生效,需用户主动选
250
+ selectableBenefits: [
251
+ { benefitRef: 'lv1', title: '会员权益·金卡', kind: 'discount', autoSelected: false },
252
+ { benefitRef: 'c1', title: '商场满减券', kind: 'coupon', autoSelected: false },
253
+ ],
254
+ appliedBenefits: [],
255
+ } as never}
256
+ cardId="c-level-optional"
257
+ isHistory={false}
258
+ actionTokens={{ 'parking.confirm-payment': 'tok', 'parking.reprice': 'tok' }}
259
+ />,
260
+ );
261
+ // 「自动生效」的判据是 autoSelected 而非 kind——厂商说要用户选的,就得给他选
262
+ const options = [...host.querySelectorAll('.parking-payment__benefit-option')];
263
+ expect(options.map((o) => o.textContent)).toEqual(
264
+ expect.arrayContaining([expect.stringContaining('会员权益·金卡')]),
265
+ );
266
+ });
267
+
268
+ it('勾选券时 reprice 带上自动生效的等级权益,不把它撤掉', () => {
269
+ vi.mocked(sendCardAction).mockClear();
270
+ const { host } = render(
271
+ <ParkingPaymentCard
272
+ data={{
273
+ ...baseData,
274
+ selectableBenefits: [
275
+ { benefitRef: 'lv1', title: '金卡 95 折', kind: 'discount', autoSelected: true },
276
+ { benefitRef: 'c1', title: '商场满减券', kind: 'coupon', autoSelected: false },
277
+ ],
278
+ appliedBenefits: [{ benefitRef: 'lv1', title: '金卡 95 折', discountText: '¥0.75' }],
279
+ } as never}
280
+ cardId="c-reprice"
281
+ isHistory={false}
282
+ actionTokens={{ 'parking.confirm-payment': 'tok', 'parking.reprice': 'reprice-token' }}
283
+ />,
284
+ );
285
+ // checkbox 走 click:React 的 onChange 对 checkbox 实际挂在 click 上,dispatch change 不触发
286
+ const checkbox = host.querySelector('.parking-payment__benefit-option input') as HTMLInputElement;
287
+ act(() => checkbox.click());
288
+ // 服务端 reprice 只应用传入的 refs——漏掉 lv1 等于替用户撤销会员折扣
289
+ expect(sendCardAction).toHaveBeenCalledWith(
290
+ 'c-reprice',
291
+ { type: 'moduleAction', actionId: 'parking.reprice', contextToken: 'reprice-token' },
292
+ { quoteRef: 'q1', revision: '1', benefitRefs: ['lv1', 'c1'] },
293
+ );
294
+ });
295
+
296
+ it('isHistory 或缺 token:全部交互禁用', () => {
297
+ const { host } = render(
298
+ <ParkingPaymentCard
299
+ data={baseData as never}
300
+ cardId="c1"
301
+ isHistory={true}
302
+ actionTokens={undefined}
303
+ />,
304
+ );
305
+ expect((host.querySelector('.parking-payment__member-guide > button') as HTMLButtonElement | null)?.disabled ?? true).toBe(true);
306
+ const actions = host.querySelectorAll('.parking-payment__action');
307
+ actions.forEach((a) =>
308
+ expect((a as HTMLButtonElement).disabled).toBe(true),
309
+ );
310
+ });
311
+ });
312
+
313
+ describe('ParkingPaymentRecordsCard 展开收起 + 状态色', () => {
314
+ const records = (n: number) =>
315
+ Array.from({ length: n }, (_, i) => ({
316
+ recordRef: `r${i}`,
317
+ plateNo: '浙A12345',
318
+ amountText: `¥${i}`,
319
+ paidAtText: '08-12 10:00',
320
+ status: i % 2 === 0 ? 'PAID' : 'REFUNDED',
321
+ }));
322
+
323
+ it('≤5 条不渲染开关;>5 渲染前 5 + 展开', () => {
324
+ const a = render(
325
+ <ParkingPaymentRecordsCard
326
+ data={
327
+ { items: records(3), total: 3, hasMore: false, caveats: [] } as never
328
+ }
329
+ />,
330
+ );
331
+ expect(a.host.querySelector('.parking-records__more')).toBeNull();
332
+ a.host.remove();
333
+
334
+ const b = render(
335
+ <ParkingPaymentRecordsCard
336
+ data={
337
+ { items: records(7), total: 7, hasMore: false, caveats: [] } as never
338
+ }
339
+ />,
340
+ );
341
+ expect(b.host.querySelectorAll('.parking-records__row').length).toBe(5);
342
+ const more = b.host.querySelector(
343
+ '.parking-records__more',
344
+ ) as HTMLButtonElement;
345
+ act(() => more.click());
346
+ expect(b.host.querySelectorAll('.parking-records__row').length).toBe(7);
347
+ b.host.remove();
348
+ });
349
+
350
+ it('状态色类 + 展开详情', () => {
351
+ const { host } = render(
352
+ <ParkingPaymentRecordsCard
353
+ data={
354
+ {
355
+ items: [
356
+ {
357
+ recordRef: 'r1',
358
+ plateNo: '浙A12345',
359
+ amountText: '¥12',
360
+ paidAtText: '08-12',
361
+ status: 'PAID',
362
+ entryAtText: '09:00',
363
+ },
364
+ ],
365
+ total: 1,
366
+ hasMore: false,
367
+ caveats: [],
368
+ } as never
369
+ }
370
+ />,
371
+ );
372
+ expect(host.querySelector('.parking-records__status--paid')).not.toBeNull();
373
+ const more = host.querySelector('.parking-records__more');
374
+ expect(more).toBeNull();
375
+ host.remove();
376
+ });
377
+
378
+ it('三轮修复:isHistory 全量展示 + 不渲染折叠开关(B2 历史禁交互)', () => {
379
+ const { host } = render(
380
+ <ParkingPaymentRecordsCard
381
+ data={
382
+ { items: records(7), total: 7, hasMore: false, caveats: [] } as never
383
+ }
384
+ isHistory={true}
385
+ />,
386
+ );
387
+ expect(host.querySelectorAll('.parking-records__row').length).toBe(7);
388
+ expect(host.querySelector('.parking-records__more')).toBeNull();
389
+ host.remove();
390
+ });
391
+
392
+ it('按记录渲染详情/开票动作,并仅提交不透明 recordRef', () => {
393
+ vi.mocked(sendCardAction).mockClear();
394
+ const { host } = render(
395
+ <ParkingPaymentRecordsCard
396
+ data={
397
+ {
398
+ items: [
399
+ {
400
+ recordRef: 'record-safe-1',
401
+ plateNo: '浙A12345',
402
+ amountText: '¥12',
403
+ paidAtText: '08-12',
404
+ status: 'PAID',
405
+ orderCompleted: true,
406
+ invoiceEligible: true,
407
+ invoiceIssued: false,
408
+ },
409
+ ],
410
+ total: 1,
411
+ hasMore: false,
412
+ caveats: [],
413
+ } as never
414
+ }
415
+ cardId="records-card"
416
+ isHistory={false}
417
+ actionTokens={{
418
+ 'parking.open-record-detail': 'detail-token',
419
+ 'parking.apply-invoice': 'invoice-token',
420
+ }}
421
+ />,
422
+ );
423
+ const row = host.querySelector('.parking-records__row');
424
+ expect(row).not.toBeNull();
425
+ // 点击行弹出 Sheet(createPortal 到 body),Sheet 内有开票按钮
426
+ act(() => (row as HTMLElement).click());
427
+ const invoice = document.body.querySelector(
428
+ '[data-action-id="parking.apply-invoice"]',
429
+ ) as HTMLButtonElement;
430
+ expect(invoice).not.toBeNull();
431
+ });
432
+ });
433
+
434
+ describe('ParkingPaymentResultCard 终态与刷新入口', () => {
435
+ const result = (over: Record<string, unknown>) => ({
436
+ paymentRef: 'PO1', plateNo: '浙A12345', amountText: '¥9.25',
437
+ message: 'm', details: [{ label: '车牌', value: '浙A12345' }], ...over,
438
+ });
439
+
440
+ it('CANCELLED 是终态:金额行标「未支付」且无刷新入口', () => {
441
+ const { host } = render(
442
+ <ParkingPaymentResultCard
443
+ data={result({ status: 'CANCELLED' }) as never}
444
+ cardId="c" isHistory={false}
445
+ actionTokens={{ 'parking.refresh-payment': 'tok' }}
446
+ />,
447
+ );
448
+ expect(host.querySelector('.parking-result__amount-row')?.textContent).toContain('未支付');
449
+ expect(host.querySelector('.parking-result__refresh')).toBeNull();
450
+ });
451
+
452
+ it('UNKNOWN 可刷新:厂商仍在对账,刷新才可能得到新结果', () => {
453
+ const { host } = render(
454
+ <ParkingPaymentResultCard
455
+ data={result({ status: 'UNKNOWN', retryable: true }) as never}
456
+ cardId="c" isHistory={false}
457
+ actionTokens={{ 'parking.refresh-payment': 'tok' }}
458
+ />,
459
+ );
460
+ expect(host.querySelector('.parking-result__amount-row')?.textContent).toContain('待确认');
461
+ expect((host.querySelector('.parking-result__refresh') as HTMLButtonElement)?.disabled).toBe(false);
462
+ });
463
+
464
+ it('历史卡不渲染刷新入口(指向一笔已翻篇的支付)', () => {
465
+ const { host } = render(
466
+ <ParkingPaymentResultCard
467
+ data={result({ status: 'UNKNOWN', retryable: true }) as never}
468
+ cardId="c" isHistory={true}
469
+ actionTokens={{ 'parking.refresh-payment': 'tok' }}
470
+ />,
471
+ );
472
+ expect(host.querySelector('.parking-result__refresh')).toBeNull();
473
+ });
474
+ });
475
+
476
+ describe('ParkingVehicleManagementCard 条目动作', () => {
477
+ it('渲染解绑按钮,并按 vehicleRef 提交', () => {
478
+ vi.mocked(sendCardAction).mockClear();
479
+ const { host } = render(
480
+ <ParkingVehicleManagementCard
481
+ data={{
482
+ bound: [{ vehicleRef: 'vehicle-safe-1', plateNo: '浙A12345' }],
483
+ }}
484
+ cardId="vehicle-card"
485
+ isHistory={false}
486
+ actionTokens={{
487
+ 'parking.unbind-vehicle': 'unbind-token',
488
+ }}
489
+ />,
490
+ );
491
+ const unbind = host.querySelector(
492
+ '[data-action-id="parking.unbind-vehicle"]',
493
+ ) as HTMLButtonElement;
494
+ expect(unbind).not.toBeNull();
495
+ // 寻车按钮已隐藏
496
+ const locate = host.querySelector('[data-action-id="parking.locate-vehicle"]');
497
+ expect(locate).toBeNull();
498
+ });
499
+
500
+ it('已绑定 3 辆车时添加车辆按钮置灰', () => {
501
+ const { host } = render(
502
+ <ParkingVehicleManagementCard
503
+ data={{
504
+ bound: [
505
+ { vehicleRef: 'v1', plateNo: '浙A12345' },
506
+ { vehicleRef: 'v2', plateNo: '浙A88888' },
507
+ { vehicleRef: 'v3', plateNo: '京AD01234' },
508
+ ],
509
+ }}
510
+ cardId="vm-full"
511
+ isHistory={false}
512
+ actionTokens={{ 'parking.bind-vehicle': 'tok' }}
513
+ />,
514
+ );
515
+ const addBtn = host.querySelector('.parking-vm__head-btn--add') as HTMLButtonElement;
516
+ expect(addBtn.disabled).toBe(true);
517
+ });
518
+
519
+ it('绑定 2 辆车时添加车辆按钮可点(未达上限)', () => {
520
+ const { host } = render(
521
+ <ParkingVehicleManagementCard
522
+ data={{
523
+ bound: [
524
+ { vehicleRef: 'v1', plateNo: '浙A12345' },
525
+ { vehicleRef: 'v2', plateNo: '浙A88888' },
526
+ ],
527
+ }}
528
+ cardId="vm-2"
529
+ isHistory={false}
530
+ actionTokens={{ 'parking.bind-vehicle': 'tok' }}
531
+ />,
532
+ );
533
+ const addBtn = host.querySelector('.parking-vm__head-btn--add') as HTMLButtonElement;
534
+ expect(addBtn.disabled).toBe(false);
535
+ });
536
+ });
537
+
538
+ describe('ParkingVehicleManagementCard H5 自绘车牌键盘', () => {
539
+ const clickKey = (host: HTMLElement, key: string) => {
540
+ const btn = host.querySelector(`[data-kb-key="${key}"]`) as HTMLButtonElement;
541
+ expect(btn).not.toBeNull();
542
+ act(() => btn.click());
543
+ };
544
+ const clickAction = (host: HTMLElement, action: string) => {
545
+ const btn = host.querySelector(`[data-kb-action="${action}"]`) as HTMLButtonElement;
546
+ expect(btn).not.toBeNull();
547
+ act(() => btn.click());
548
+ };
549
+ const cellText = (host: HTMLElement, i: number) =>
550
+ host.querySelectorAll('.parking-vm__plate-cell')[i]?.textContent ?? '';
551
+
552
+ it('纯浏览器点格子开自绘键盘:完整输入 7 位并绑定', () => {
553
+ vi.mocked(sendCardAction).mockClear();
554
+ const { host } = render(
555
+ <ParkingVehicleManagementCard
556
+ data={{ bound: [] }}
557
+ cardId="kb-card"
558
+ isHistory={false}
559
+ actionTokens={{ 'parking.bind-vehicle': 'bind-token' }}
560
+ />,
561
+ );
562
+ // 无车强制录入态:happy-dom 无壳无 bridge → 点分格直接开自绘键盘
563
+ const cell = host.querySelector('.parking-vm__plate-cell') as HTMLElement;
564
+ act(() => cell.click());
565
+ expect(host.querySelector('.parking-kb')).not.toBeNull();
566
+
567
+ clickKey(host, '浙');
568
+ clickKey(host, 'A');
569
+ for (const k of ['1', '2', '3', '4', '5']) clickKey(host, k);
570
+ expect(cellText(host, 0)).toBe('浙');
571
+ expect(cellText(host, 6)).toBe('5');
572
+
573
+ const bind = host.querySelector('.parking-vm__primary-btn') as HTMLButtonElement;
574
+ expect(bind.disabled).toBe(false);
575
+
576
+ clickAction(host, 'done');
577
+ expect(host.querySelector('.parking-kb')).toBeNull();
578
+
579
+ act(() => bind.click());
580
+ expect(sendCardAction).toHaveBeenCalledWith(
581
+ 'kb-card',
582
+ { type: 'moduleAction', actionId: 'parking.bind-vehicle', contextToken: 'bind-token' },
583
+ { plateNo: '浙A12345' },
584
+ );
585
+ });
586
+
587
+ it('8 位流程:统一输入,末两位放开特键', () => {
588
+ const { host } = render(
589
+ <ParkingVehicleManagementCard data={{ bound: [] }} cardId="kb2" isHistory={false} />
590
+ );
591
+ act(() => (host.querySelector('.parking-vm__plate-cell') as HTMLElement).click());
592
+ clickKey(host, '浙');
593
+ clickKey(host, 'A');
594
+ clickKey(host, 'D');
595
+ for (const k of ['1', '2', '3', '4']) clickKey(host, k);
596
+ expect(cellText(host, 6)).toBe('4');
597
+ // 第 8 格(索引 7)放开特键
598
+ const gang = host.querySelector('[data-kb-key="港"]') as HTMLButtonElement;
599
+ expect(gang.disabled).toBe(false);
600
+ });
601
+
602
+ it('退格删除与点格定位替换', () => {
603
+ const { host } = render(
604
+ <ParkingVehicleManagementCard data={{ bound: [] }} cardId="kb3" isHistory={false} />
605
+ );
606
+ act(() => (host.querySelector('.parking-vm__plate-cell') as HTMLElement).click());
607
+ clickKey(host, '浙');
608
+ clickKey(host, 'A');
609
+ clickKey(host, '1');
610
+ clickAction(host, 'backspace');
611
+ expect(cellText(host, 2)).toBe('');
612
+ // 点位 1 定位替换
613
+ act(() => (host.querySelectorAll('.parking-vm__plate-cell')[1] as HTMLElement).click());
614
+ clickKey(host, 'B');
615
+ expect(cellText(host, 1)).toBe('B');
616
+ expect(cellText(host, 2)).toBe('');
617
+ });
618
+
619
+ it('历史卡点格子不开键盘', () => {
620
+ const { host } = render(
621
+ <ParkingVehicleManagementCard data={{ bound: [] }} cardId="kb4" isHistory={true} />
622
+ );
623
+ act(() => (host.querySelector('.parking-vm__plate-cell') as HTMLElement).click());
624
+ expect(host.querySelector('.parking-kb')).toBeNull();
625
+ });
626
+ });
627
+
628
+ describe('D10 置位守卫(三轮修复:防"声明置位、实现漏置"回归)', () => {
629
+ it('parking 四张卡内写按钮卡 default 导出 selfRendersActions 置位', async () => {
630
+ const payment = (await import('../src/client/cards/parking-payment'))
631
+ .default as { selfRendersActions?: boolean };
632
+ const result = (await import('../src/client/cards/parking-payment-result'))
633
+ .default as { selfRendersActions?: boolean };
634
+ const vehicle = (
635
+ await import('../src/client/cards/parking-vehicle-management')
636
+ ).default as { selfRendersActions?: boolean };
637
+ const records = (
638
+ await import('../src/client/cards/parking-payment-records')
639
+ ).default as { selfRendersActions?: boolean };
640
+ expect(payment.selfRendersActions).toBe(true);
641
+ expect(result.selfRendersActions).toBe(true);
642
+ expect(vehicle.selfRendersActions).toBe(true);
643
+ expect(records.selfRendersActions).toBe(true);
644
+ });
645
+ });