@tbox.cn/app-module-parking 0.1.0 → 0.9.3

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