@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.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.
- package/AGENTS.md +16 -0
- package/README.md +96 -0
- package/dist/chunk-AYQZO2FV.js +1496 -0
- package/dist/chunk-VKDA6RXQ.js +1676 -0
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -8
- package/dist/server/index.d.ts +2512 -608
- package/dist/server/index.js +1 -7
- package/dist/shopping-guide-EGRHPEDA.css +2598 -0
- package/package.json +25 -16
- package/skills/shopping-guide/SKILL.md +127 -24
- package/src/client/cards/category-list/index.tsx +113 -0
- package/src/client/cards/human-guide-list/index.tsx +72 -0
- package/src/client/cards/index.ts +14 -0
- package/src/client/cards/location-handoff/index.tsx +52 -0
- package/src/client/cards/mall-directory/index.tsx +77 -0
- package/src/client/cards/nearby-mall-list/index.tsx +40 -0
- package/src/client/cards/product-comparison/index.tsx +100 -0
- package/src/client/cards/product-detail/index.tsx +97 -0
- package/src/client/cards/product-list/index.tsx +223 -0
- package/src/client/cards/recommend-merchants/index.tsx +147 -0
- package/src/client/cards/shop-detail/index.tsx +133 -0
- package/src/client/cards/shop-list/index.tsx +216 -0
- package/src/client/cards/view.ts +147 -0
- package/src/client/categories.ts +38 -0
- package/src/client/components/ImageWithFallback.tsx +34 -0
- package/src/client/components/MerchantRow.tsx +78 -0
- package/src/client/components/ShopDetailSheet.tsx +383 -0
- package/src/client/components/ShopGuideHeader.tsx +23 -0
- package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
- package/src/client/components/ShopListSheet.tsx +293 -0
- package/src/client/index.ts +8 -6
- package/src/client/styles/shopping-guide.css +2598 -0
- package/src/client/types/css.d.ts +2 -0
- package/src/server/cards/category-list/meta.ts +0 -2
- package/src/server/cards/human-guide-list/meta.ts +0 -2
- package/src/server/cards/index.ts +10 -10
- package/src/server/cards/location-handoff/meta.ts +0 -2
- package/src/server/cards/mall-directory/meta.ts +0 -2
- package/src/server/cards/nearby-mall-list/meta.ts +1 -3
- package/src/server/cards/product-comparison/meta.ts +0 -2
- package/src/server/cards/product-detail/meta.ts +0 -2
- package/src/server/cards/product-list/meta.ts +0 -2
- package/src/server/cards/recommend-merchants/meta.ts +37 -0
- package/src/server/cards/recommend-merchants/samples.ts +189 -0
- package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
- package/src/server/cards/shop-detail/samples.ts +72 -0
- package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
- package/src/server/cards/shop-list/samples.ts +154 -0
- package/src/server/domain/value-objects.ts +1 -2
- package/src/server/handler.ts +63 -0
- package/src/server/index.ts +161 -101
- package/src/server/ports/index.ts +120 -91
- package/src/server/ports/local-adapters.ts +5 -55
- package/src/server/projections/index.ts +159 -41
- package/src/server/tools/index.ts +590 -315
- package/tbox.module.json +137 -0
- package/tests/cards-render.test.tsx +830 -0
- package/tests/floor-pretool.test.ts +275 -0
- package/tests/handler.test.ts +259 -0
- package/tests/merchant-list-limit.test.ts +53 -0
- package/tests/ports-resolve.test.ts +112 -0
- package/tests/samples.test.ts +71 -0
- package/tests/shopping-guide.test.ts +402 -234
- package/tests/skill.test.ts +86 -0
- package/tests/view.test.ts +42 -0
- package/tsup.config.ts +9 -1
- package/dist/chunk-AGBLC6XI.js +0 -1294
- package/dist/chunk-U4WDS5PQ.js +0 -173
- package/skills/shopping-guide/references/comparison-format.md +0 -5
- package/skills/shopping-guide/references/faq-answers.md +0 -5
- package/skills/shopping-guide/references/floor-directory.md +0 -4
- package/skills/shopping-guide/references/intent-patterns.md +0 -5
- package/skills/shopping-guide/references/location-format.md +0 -5
- package/skills/shopping-guide/references/policy-lookup.md +0 -5
- package/skills/shopping-guide/references/product-search-tips.md +0 -6
- package/skills/shopping-guide/references/recommendation-style.md +0 -5
- package/src/client/cards/index.tsx +0 -267
- package/src/server/cards/customer-service-faq/meta.ts +0 -18
- package/src/server/integrations/joycity/adapter.ts +0 -226
- package/src/server/integrations/joycity/auth-strategy.ts +0 -38
- package/src/server/integrations/joycity/gateway.ts +0 -128
- package/tbox.component.json +0 -48
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* module-shopping-guide 客户端卡片渲染测试(0.4.0 D9:happy-dom)。
|
|
3
|
+
* 覆盖:分类折叠 / 详情轮播 / 对比卡计时器 / 条目动作。
|
|
4
|
+
* (FAQ 手风琴用例随客服承接拆分迁至 module-customer-service,2026-08-31)
|
|
5
|
+
*/
|
|
6
|
+
// @vitest-environment happy-dom
|
|
7
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
import { createRoot } from 'react-dom/client';
|
|
9
|
+
import { act } from 'react-dom/test-utils';
|
|
10
|
+
import { httpGet, navigateToAlipayPage, sendCardAction } from '@tbox.cn/app-sdk/client';
|
|
11
|
+
import {
|
|
12
|
+
CategoryListCard,
|
|
13
|
+
ProductComparisonCard,
|
|
14
|
+
ProductDetailCard,
|
|
15
|
+
RecommendMerchantsCard,
|
|
16
|
+
ShopDetailCard,
|
|
17
|
+
ShopListCard,
|
|
18
|
+
} from '../src/client/cards';
|
|
19
|
+
|
|
20
|
+
vi.mock('@tbox.cn/app-sdk/client', async (importOriginal) => {
|
|
21
|
+
const mod = await importOriginal<typeof import('@tbox.cn/app-sdk/client')>();
|
|
22
|
+
return { ...mod, httpGet: vi.fn(), navigateToAlipayPage: vi.fn(() => Promise.resolve()), sendCardAction: vi.fn() };
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const mountedRoots = new Set<ReturnType<typeof createRoot>>();
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
for (const root of mountedRoots) {
|
|
29
|
+
act(() => root.unmount());
|
|
30
|
+
}
|
|
31
|
+
mountedRoots.clear();
|
|
32
|
+
document.body.innerHTML = '';
|
|
33
|
+
document.body.style.overflow = '';
|
|
34
|
+
vi.mocked(httpGet).mockReset();
|
|
35
|
+
vi.mocked(sendCardAction).mockReset();
|
|
36
|
+
vi.mocked(navigateToAlipayPage).mockReset();
|
|
37
|
+
vi.mocked(navigateToAlipayPage).mockResolvedValue(undefined);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function render(ui: React.ReactElement) {
|
|
41
|
+
const host = document.createElement('div');
|
|
42
|
+
document.body.appendChild(host);
|
|
43
|
+
const root = createRoot(host);
|
|
44
|
+
act(() => {
|
|
45
|
+
root.render(ui);
|
|
46
|
+
});
|
|
47
|
+
mountedRoots.add(root);
|
|
48
|
+
return { host, root };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const categories = (n: number) =>
|
|
52
|
+
Array.from({ length: n }, (_, i) => ({
|
|
53
|
+
code: `c${i}`,
|
|
54
|
+
name: `分类${i}`,
|
|
55
|
+
merchantCount: i,
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
describe('CategoryListCard', () => {
|
|
59
|
+
it('≤9 项不渲染展开开关', () => {
|
|
60
|
+
const { host } = render(<CategoryListCard data={{ categories: categories(5), observedAt: '2026-08-01T00:00:00.000Z' } as never} cardId="c1" isHistory={false} />);
|
|
61
|
+
expect(host.querySelectorAll('.sg-category-cell').length).toBe(5);
|
|
62
|
+
expect(host.querySelector('.sg-category-toggle')).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('>9 项折叠渲染前 9,展开后全部', () => {
|
|
66
|
+
const { host } = render(<CategoryListCard data={{ categories: categories(12), observedAt: '2026-08-01T00:00:00.000Z' } as never} cardId="c1" isHistory={false} />);
|
|
67
|
+
expect(host.querySelectorAll('.sg-category-cell').length).toBe(9);
|
|
68
|
+
const toggle = host.querySelector('.sg-category-toggle') as HTMLButtonElement;
|
|
69
|
+
act(() => toggle.click());
|
|
70
|
+
expect(host.querySelectorAll('.sg-category-cell').length).toBe(12);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// CustomerServiceFaqCard 手风琴用例随客服承接拆分迁至 module-customer-service(2026-08-31)
|
|
75
|
+
|
|
76
|
+
describe('ProductDetailCard 轮播', () => {
|
|
77
|
+
const detailData = {
|
|
78
|
+
productId: 'p1',
|
|
79
|
+
name: '商品',
|
|
80
|
+
imageUrls: ['https://a.com/1.jpg', 'https://a.com/2.jpg'],
|
|
81
|
+
brand: '品牌',
|
|
82
|
+
categoryPath: [],
|
|
83
|
+
price: { sale: { display: '¥100' } },
|
|
84
|
+
availability: { status: 'in_stock', label: '有货', marketable: true, observedAt: '2026-08-01T00:00:00.000Z' },
|
|
85
|
+
merchant: { merchantId: 'm1', name: '商户' },
|
|
86
|
+
attributes: [{ name: '材质', value: '棉' }],
|
|
87
|
+
promotionFacts: [],
|
|
88
|
+
evidence: [],
|
|
89
|
+
humanGuideAvailable: false,
|
|
90
|
+
itemActions: [],
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
it('多图渲染缩略图条,点击切换主图', () => {
|
|
94
|
+
const { host } = render(<ProductDetailCard data={detailData as never} cardId="c1" isHistory={false} />);
|
|
95
|
+
expect(host.querySelectorAll('.sg-carousel__thumb').length).toBe(2);
|
|
96
|
+
expect(host.querySelector('.sg-carousel__count')!.textContent).toContain('1/2');
|
|
97
|
+
const thumbs = host.querySelectorAll('.sg-carousel__thumb');
|
|
98
|
+
act(() => (thumbs[1] as HTMLButtonElement).click());
|
|
99
|
+
expect(host.querySelector('.sg-carousel__count')!.textContent).toContain('2/2');
|
|
100
|
+
expect(thumbs[1].getAttribute('aria-current')).toBe('true');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('单图不渲染缩略图条', () => {
|
|
104
|
+
const { host } = render(
|
|
105
|
+
<ProductDetailCard data={{ ...detailData, imageUrls: ['https://a.com/1.jpg'] } as never} cardId="c1" isHistory={false} />,
|
|
106
|
+
);
|
|
107
|
+
expect(host.querySelector('.sg-carousel__thumb')).toBeNull();
|
|
108
|
+
expect(host.querySelector('.sg-carousel__count')).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('ProductComparisonCard 到期计时器', () => {
|
|
113
|
+
const compareData = {
|
|
114
|
+
products: [
|
|
115
|
+
{
|
|
116
|
+
productId: 'p1', name: 'A', price: { sale: { display: '¥10' } },
|
|
117
|
+
availability: { status: 'in_stock', label: '有货', marketable: true, observedAt: '2026-08-01T00:00:00.000Z' },
|
|
118
|
+
merchant: { merchantId: 'm1', name: 'M' }, attributes: [{ name: '容量', value: '1L' }], caveats: [],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
observedAt: '2026-08-01T00:00:00.000Z',
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
it('无 refreshRequiredAt 不置 stale', () => {
|
|
125
|
+
const { host } = render(<ProductComparisonCard data={compareData as never} isHistory={false} />);
|
|
126
|
+
expect(host.querySelector('.sg-product-comparison--stale')).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('到期后置 stale 横幅 + 整卡降透明', () => {
|
|
130
|
+
vi.useFakeTimers();
|
|
131
|
+
const { host } = render(
|
|
132
|
+
<ProductComparisonCard
|
|
133
|
+
data={{ ...compareData, refreshRequiredAt: new Date(Date.now() + 1000).toISOString() } as never}
|
|
134
|
+
isHistory={false}
|
|
135
|
+
/>,
|
|
136
|
+
);
|
|
137
|
+
expect(host.querySelector('.sg-product-comparison--stale')).toBeNull();
|
|
138
|
+
act(() => {
|
|
139
|
+
vi.advanceTimersByTime(2000);
|
|
140
|
+
});
|
|
141
|
+
expect(host.querySelector('.sg-product-comparison--stale')).not.toBeNull();
|
|
142
|
+
expect(host.querySelector('.sg-stale-notice')).not.toBeNull();
|
|
143
|
+
vi.useRealTimers();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('三轮修复:isHistory 历史卡不显示"数据过期"标记(历史 ≠ 过期,语义分离)', () => {
|
|
147
|
+
const { host } = render(
|
|
148
|
+
<ProductComparisonCard data={{ ...compareData, refreshRequiredAt: new Date(Date.now() + 60_000).toISOString() } as never} isHistory={true} />,
|
|
149
|
+
);
|
|
150
|
+
const marker = host.querySelector('.sg-compare__stale-marker') as HTMLElement;
|
|
151
|
+
expect(marker).not.toBeNull();
|
|
152
|
+
expect(marker.hidden).toBe(true);
|
|
153
|
+
expect(host.querySelector('.sg-stale-notice')).toBeNull();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const observedAt = '2026-08-01T00:00:00.000Z';
|
|
158
|
+
|
|
159
|
+
describe('门店导览无权益内容', () => {
|
|
160
|
+
const merchant = {
|
|
161
|
+
merchantId: 'm1',
|
|
162
|
+
name: '日光咖啡实验室',
|
|
163
|
+
logoUrl: 'https://example.com/logo.png',
|
|
164
|
+
coverUrl: 'https://example.com/cover.png',
|
|
165
|
+
brand: '日光咖啡',
|
|
166
|
+
businessCategories: ['咖啡'],
|
|
167
|
+
location: { displayText: 'A 座 L1 A117', buildingName: 'A 座', floorName: 'L1' },
|
|
168
|
+
status: { code: 'enabled', label: '营业中', observedAt },
|
|
169
|
+
contactInfo: [{ channel: 'phone', value: '400-000-1122' }],
|
|
170
|
+
services: ['堂食'],
|
|
171
|
+
promotionFacts: ['旧权益事实不应进入门店导览界面'],
|
|
172
|
+
itemActions: [],
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
it('recommend-merchants 使用中性标题和门店计数,并可打开详情半屏', () => {
|
|
176
|
+
const { host } = render(
|
|
177
|
+
<RecommendMerchantsCard
|
|
178
|
+
data={{
|
|
179
|
+
summary: '结合偏好推荐值得逛的门店',
|
|
180
|
+
categoryTabs: [{ code: 'coffee', name: '咖啡' }],
|
|
181
|
+
items: [{
|
|
182
|
+
...merchant,
|
|
183
|
+
rating: '4.8',
|
|
184
|
+
avgSpend: '¥36',
|
|
185
|
+
operatingStatus: '营业至 22:00',
|
|
186
|
+
itemActions: [{ kind: 'send', label: '问问导购', value: '介绍一下日光咖啡实验室' }],
|
|
187
|
+
}],
|
|
188
|
+
observedAt,
|
|
189
|
+
} as never}
|
|
190
|
+
cardId="recommend"
|
|
191
|
+
isHistory={false}
|
|
192
|
+
/>,
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
expect(host.textContent).toContain('门店导览');
|
|
196
|
+
// 分区标签与列表卡统一:只剩「门店」标题,不再在标题右侧报「当前显示 N 家」。
|
|
197
|
+
expect(host.textContent).toContain('门店');
|
|
198
|
+
expect(host.textContent).not.toContain('当前显示');
|
|
199
|
+
// 行内:业态做成标签、位置退居第三行、不再展示营业状态与营业时间。
|
|
200
|
+
expect([...host.querySelectorAll('.sg-rm-item-tag')].map((el) => el.textContent)).toEqual(['咖啡']);
|
|
201
|
+
expect(host.querySelector('.sg-rm-item-status-row')).toBeNull();
|
|
202
|
+
expect(host.textContent).not.toContain('营业至 22:00');
|
|
203
|
+
expect(host.textContent).not.toContain('营业中');
|
|
204
|
+
expect(host.textContent).not.toContain('旧权益事实');
|
|
205
|
+
expect(host.querySelector('.sg-rm-promo-list')).toBeNull();
|
|
206
|
+
expect(host.querySelector('.sg-rm-item[role="button"]')).toBeNull();
|
|
207
|
+
expect(host.querySelector('.sg-rm-item-head button')).toBeNull();
|
|
208
|
+
|
|
209
|
+
act(() => (host.querySelector('.sg-rm-item-head') as HTMLButtonElement).click());
|
|
210
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('门店详情');
|
|
211
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).not.toContain('问问导购');
|
|
212
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).not.toContain('旧权益事实');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('recommend-merchants 主卡只预览三家,查看更多进入独立门店列表半屏', () => {
|
|
216
|
+
const items = Array.from({ length: 5 }, (_, index) => ({
|
|
217
|
+
...merchant,
|
|
218
|
+
merchantId: `merchant-${index}`,
|
|
219
|
+
name: `示例门店${index + 1}`,
|
|
220
|
+
rating: `4.${index + 5}`,
|
|
221
|
+
avgSpend: `¥${30 + index * 10}`,
|
|
222
|
+
}));
|
|
223
|
+
const { host } = render(
|
|
224
|
+
<RecommendMerchantsCard
|
|
225
|
+
data={{
|
|
226
|
+
categoryTabs: [{ code: 'coffee', name: '咖啡' }],
|
|
227
|
+
items,
|
|
228
|
+
observedAt,
|
|
229
|
+
} as never}
|
|
230
|
+
cardId="recommend-list"
|
|
231
|
+
isHistory={false}
|
|
232
|
+
/>,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
expect(host.querySelectorAll('.sg-rm-item')).toHaveLength(3);
|
|
236
|
+
// 首项是「全部」,未筛选时它处于选中态。
|
|
237
|
+
expect(host.querySelector('.sg-rm-tab')?.textContent).toBe('全部');
|
|
238
|
+
expect(host.querySelector('.sg-rm-tab')?.getAttribute('aria-pressed')).toBe('true');
|
|
239
|
+
act(() => (host.querySelector('.sg-rm-view-all') as HTMLButtonElement).click());
|
|
240
|
+
const listClose = document.body.querySelector('[aria-label="关闭门店列表"]') as HTMLButtonElement;
|
|
241
|
+
expect(listClose).not.toBeNull();
|
|
242
|
+
expect(document.activeElement).toBe(listClose);
|
|
243
|
+
expect(document.activeElement).not.toBe(document.body.querySelector('.sg-store-list-sheet__search input'));
|
|
244
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(5);
|
|
245
|
+
expect(document.body.textContent).not.toContain('旧权益事实');
|
|
246
|
+
|
|
247
|
+
const listTab = document.body.querySelector('.sg-store-list-sheet__categories button[aria-pressed="false"]') as HTMLButtonElement;
|
|
248
|
+
listTab.focus();
|
|
249
|
+
act(() => listTab.click());
|
|
250
|
+
expect(document.activeElement).toBe(listTab);
|
|
251
|
+
|
|
252
|
+
act(() => (document.body.querySelector('.sg-store-list-sheet__item') as HTMLButtonElement).click());
|
|
253
|
+
expect(document.body.querySelectorAll('[role="dialog"]')).toHaveLength(1);
|
|
254
|
+
expect(document.body.querySelector('[aria-label="关闭门店详情"]')).not.toBeNull();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('门店列表半屏组合搜索、业态与楼层筛选', () => {
|
|
258
|
+
const categoryTabs = Array.from({ length: 5 }, (_, index) => ({ code: `category-${index}`, name: `业态${index + 1}` }));
|
|
259
|
+
const items = Array.from({ length: 6 }, (_, index) => ({
|
|
260
|
+
...merchant,
|
|
261
|
+
merchantId: `search-${index}`,
|
|
262
|
+
name: index === 5 ? '山野运动旗舰店' : `示例门店${index + 1}`,
|
|
263
|
+
brand: index === 5 ? 'Mountain Lab' : undefined,
|
|
264
|
+
businessCategories: [categoryTabs[index % categoryTabs.length].name],
|
|
265
|
+
location: {
|
|
266
|
+
displayText: `A 座 L${index + 1} A10${index}`,
|
|
267
|
+
floorName: `L${index + 1}`,
|
|
268
|
+
},
|
|
269
|
+
}));
|
|
270
|
+
const { host } = render(
|
|
271
|
+
<RecommendMerchantsCard
|
|
272
|
+
data={{ categoryTabs, items, observedAt } as never}
|
|
273
|
+
cardId="search-and-category"
|
|
274
|
+
isHistory={false}
|
|
275
|
+
/>,
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
act(() => (host.querySelector('.sg-rm-view-all') as HTMLButtonElement).click());
|
|
279
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__categories button')).toHaveLength(6);
|
|
280
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(6);
|
|
281
|
+
|
|
282
|
+
const floorButtons = () => Array.from(
|
|
283
|
+
document.body.querySelectorAll<HTMLButtonElement>('.sg-store-list-sheet__floors button'),
|
|
284
|
+
);
|
|
285
|
+
// 高层在上,首项是退回全部的「全」——商场楼层图与电梯面板都是这个方向。
|
|
286
|
+
expect(floorButtons().map((button) => button.textContent)).toEqual(['全', 'L6', 'L5', 'L4', 'L3', 'L2', 'L1']);
|
|
287
|
+
expect(floorButtons()[0].getAttribute('aria-pressed')).toBe('true');
|
|
288
|
+
|
|
289
|
+
// 楼层是筛选而非大纲:点一层只留那一层,再点「全」退回。
|
|
290
|
+
const floorL6 = floorButtons().find((button) => button.textContent === 'L6') as HTMLButtonElement;
|
|
291
|
+
act(() => floorL6.click());
|
|
292
|
+
expect(floorL6.getAttribute('aria-pressed')).toBe('true');
|
|
293
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(1);
|
|
294
|
+
act(() => floorButtons()[0].click());
|
|
295
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(6);
|
|
296
|
+
|
|
297
|
+
const input = document.body.querySelector('.sg-store-list-sheet__search input') as HTMLInputElement;
|
|
298
|
+
act(() => {
|
|
299
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, 'Mountain');
|
|
300
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
301
|
+
});
|
|
302
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(1);
|
|
303
|
+
expect(document.body.textContent).toContain('山野运动旗舰店');
|
|
304
|
+
|
|
305
|
+
const category = Array.from(document.body.querySelectorAll<HTMLButtonElement>('.sg-store-list-sheet__categories button'))
|
|
306
|
+
.find((button) => button.textContent === '业态2');
|
|
307
|
+
act(() => category?.click());
|
|
308
|
+
expect(input.value).toBe('Mountain');
|
|
309
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(0);
|
|
310
|
+
expect(document.body.textContent).toContain('暂时没有符合条件的门店');
|
|
311
|
+
|
|
312
|
+
act(() => (document.body.querySelector('[aria-label="清空门店搜索"]') as HTMLButtonElement).click());
|
|
313
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(1);
|
|
314
|
+
|
|
315
|
+
const fifthCategory = Array.from(document.body.querySelectorAll<HTMLButtonElement>('.sg-store-list-sheet__categories button'))
|
|
316
|
+
.find((button) => button.textContent === '业态5');
|
|
317
|
+
act(() => fifthCategory?.click());
|
|
318
|
+
expect(document.body.querySelectorAll('.sg-store-list-sheet__item')).toHaveLength(1);
|
|
319
|
+
const listSheet = document.body.querySelector('.sg-store-list-sheet') as HTMLElement;
|
|
320
|
+
act(() => (document.body.querySelector('[aria-label="关闭门店列表"]') as HTMLButtonElement).click());
|
|
321
|
+
expect(listSheet.classList.contains('sg-store-list-sheet--closing')).toBe(true);
|
|
322
|
+
act(() => listSheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
323
|
+
// 浮层里的选择不回写卡内:卡内仍停在「全部」,其余品类 tab 均未选中。
|
|
324
|
+
const cardTabs = Array.from(host.querySelectorAll('.sg-rm-tab'));
|
|
325
|
+
expect(cardTabs[0].getAttribute('aria-pressed')).toBe('true');
|
|
326
|
+
expect(cardTabs.slice(1).every((tab) => tab.getAttribute('aria-pressed') === 'false')).toBe(true);
|
|
327
|
+
act(() => (host.querySelector('.sg-rm-view-all') as HTMLButtonElement).click());
|
|
328
|
+
expect(document.body.querySelector('.sg-store-list-sheet')?.classList.contains('sg-store-list-sheet--closing')).toBe(false);
|
|
329
|
+
expect(document.body.querySelector('.sg-store-list-sheet__categories button[aria-pressed="true"]')?.textContent).toBe('全部');
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('历史 recommend-merchants 与 shop-list 同口径:保留只读浏览列表与详情', () => {
|
|
333
|
+
const items = Array.from({ length: 4 }, (_, index) => ({
|
|
334
|
+
...merchant,
|
|
335
|
+
merchantId: `history-${index}`,
|
|
336
|
+
name: `历史门店${index + 1}`,
|
|
337
|
+
}));
|
|
338
|
+
const { host } = render(
|
|
339
|
+
<RecommendMerchantsCard
|
|
340
|
+
data={{ items, observedAt } as never}
|
|
341
|
+
cardId="history-recommend"
|
|
342
|
+
isHistory
|
|
343
|
+
/>,
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const preview = host.querySelector('.sg-rm-item-head') as HTMLButtonElement;
|
|
347
|
+
expect(preview.disabled).toBe(false);
|
|
348
|
+
act(() => preview.click());
|
|
349
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('历史门店1');
|
|
350
|
+
act(() => (document.body.querySelector('[aria-label="关闭门店详情"]') as HTMLButtonElement).click());
|
|
351
|
+
expect((host.querySelector('.sg-rm-view-all') as HTMLButtonElement).disabled).toBe(false);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('历史 shop-list 详情:电话仍是可拨打链接,发消息动作禁用', () => {
|
|
355
|
+
const merchantWithActions = { ...merchant, itemActions: [{ kind: 'send', label: '查看推荐', value: '查看门店推荐' }] };
|
|
356
|
+
const { host } = render(
|
|
357
|
+
<ShopListCard
|
|
358
|
+
data={{ context: 'search', items: [merchantWithActions], refinements: [] } as never}
|
|
359
|
+
cardId="history-shop-phone"
|
|
360
|
+
isHistory
|
|
361
|
+
/>,
|
|
362
|
+
);
|
|
363
|
+
act(() => (host.querySelector('.sg-rm-item-head') as HTMLButtonElement).click());
|
|
364
|
+
const phone = document.body.querySelector<HTMLAnchorElement>('[aria-label="拨打日光咖啡实验室电话"]');
|
|
365
|
+
expect(phone?.tagName).toBe('A');
|
|
366
|
+
expect(phone?.href).toContain('400-000-1122');
|
|
367
|
+
const sendAction = [...document.body.querySelectorAll<HTMLButtonElement>('.sg-shop-sheet__action')]
|
|
368
|
+
.find((button) => button.textContent === '查看推荐') as HTMLButtonElement;
|
|
369
|
+
expect(sendAction.disabled).toBe(true);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('shop-list 使用紧凑门店预览,详情中保留电话且不呈现 promotionFacts', () => {
|
|
373
|
+
const merchantWithActions = {
|
|
374
|
+
...merchant,
|
|
375
|
+
itemActions: [
|
|
376
|
+
{ kind: 'send', label: '查看详情', value: '查看门店详情' },
|
|
377
|
+
{ kind: 'link', label: '导航', url: 'https://uri.amap.com/search?keyword=test' },
|
|
378
|
+
{ kind: 'send', label: '查看推荐', value: '查看门店推荐' },
|
|
379
|
+
],
|
|
380
|
+
};
|
|
381
|
+
const { host } = render(
|
|
382
|
+
<ShopListCard
|
|
383
|
+
data={{
|
|
384
|
+
context: 'search',
|
|
385
|
+
summary: '找到 1 家门店',
|
|
386
|
+
items: [merchantWithActions],
|
|
387
|
+
refinements: [
|
|
388
|
+
{ label: '只看营业中', queryText: '只看现在营业的门店' },
|
|
389
|
+
{ label: '只看 L1', queryText: '查看 L1 的门店' },
|
|
390
|
+
],
|
|
391
|
+
} as never}
|
|
392
|
+
cardId="shops"
|
|
393
|
+
isHistory={false}
|
|
394
|
+
/>,
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
expect(host.textContent).toContain('门店导览');
|
|
398
|
+
expect(host.textContent).toContain('A 座');
|
|
399
|
+
expect(host.textContent).not.toContain('旧权益事实');
|
|
400
|
+
expect(host.textContent).not.toContain('只看营业中');
|
|
401
|
+
expect(host.textContent).not.toContain('只看 L1');
|
|
402
|
+
expect(host.querySelector('.sg-refinements')).toBeNull();
|
|
403
|
+
expect(host.querySelector('.sg-promo-facts')).toBeNull();
|
|
404
|
+
expect(host.querySelectorAll('.sg-rm-item')).toHaveLength(1);
|
|
405
|
+
|
|
406
|
+
act(() => (host.querySelector('.sg-rm-item-head') as HTMLButtonElement).click());
|
|
407
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('日光咖啡实验室');
|
|
408
|
+
expect(document.body.querySelector<HTMLAnchorElement>('[aria-label="拨打日光咖啡实验室电话"]')?.href)
|
|
409
|
+
.toContain('400-000-1122');
|
|
410
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).not.toContain('查看详情');
|
|
411
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).not.toContain('导航');
|
|
412
|
+
const retainedAction = [...document.body.querySelectorAll<HTMLButtonElement>('.sg-shop-sheet__action')]
|
|
413
|
+
.find((button) => button.textContent === '查看推荐') as HTMLButtonElement;
|
|
414
|
+
expect(retainedAction).not.toBeUndefined();
|
|
415
|
+
expect(retainedAction.disabled).toBe(false);
|
|
416
|
+
expect(document.body.querySelector('.sg-shop-sheet__snapshot')).toBeNull();
|
|
417
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).not.toContain('旧权益事实');
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('shop-list 获取完整详情时显示骨架,成功后一次性替换动态信息', async () => {
|
|
421
|
+
let resolveRequest!: (value: unknown) => void;
|
|
422
|
+
const pendingRequest = new Promise<unknown>((resolve) => {
|
|
423
|
+
resolveRequest = resolve;
|
|
424
|
+
});
|
|
425
|
+
vi.mocked(httpGet).mockReturnValueOnce(pendingRequest as never);
|
|
426
|
+
const { host } = render(
|
|
427
|
+
<ShopListCard
|
|
428
|
+
data={{
|
|
429
|
+
context: 'search',
|
|
430
|
+
mallId: 'mall-1',
|
|
431
|
+
miniAppId: 'mini-1',
|
|
432
|
+
items: [{
|
|
433
|
+
...merchant,
|
|
434
|
+
status: { code: 'unknown', label: '营业状态以现场为准', observedAt },
|
|
435
|
+
contactInfo: undefined,
|
|
436
|
+
services: [],
|
|
437
|
+
}],
|
|
438
|
+
refinements: [],
|
|
439
|
+
} as never}
|
|
440
|
+
cardId="shops-loading"
|
|
441
|
+
isHistory={false}
|
|
442
|
+
/>,
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
act(() => (host.querySelector('.sg-rm-item-head') as HTMLButtonElement).click());
|
|
446
|
+
const loadingDialog = document.body.querySelector('[role="dialog"]') as HTMLElement;
|
|
447
|
+
expect(loadingDialog.getAttribute('aria-busy')).toBe('true');
|
|
448
|
+
expect(loadingDialog.querySelector('[role="status"]')?.getAttribute('aria-label')).toBe('门店详情加载中');
|
|
449
|
+
expect(loadingDialog.querySelector('.sg-shop-sheet__phone-skeleton')).not.toBeNull();
|
|
450
|
+
expect(loadingDialog.querySelector('.sg-shop-sheet__details-skeleton')).not.toBeNull();
|
|
451
|
+
expect(loadingDialog.textContent).not.toContain('营业状态以现场为准');
|
|
452
|
+
|
|
453
|
+
await act(async () => {
|
|
454
|
+
resolveRequest({
|
|
455
|
+
data: {
|
|
456
|
+
data: {
|
|
457
|
+
...merchant,
|
|
458
|
+
coverUrls: [merchant.coverUrl],
|
|
459
|
+
status: { code: 'enabled', label: '营业中', observedAt },
|
|
460
|
+
contactInfo: [
|
|
461
|
+
{ channel: '营业时间', value: '10:00–22:00' },
|
|
462
|
+
{ channel: '电话', value: '400-000-1122' },
|
|
463
|
+
],
|
|
464
|
+
services: ['店内支付', '消费积分'],
|
|
465
|
+
description: '完整门店详情',
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
await pendingRequest;
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const loadedDialog = document.body.querySelector('[role="dialog"]') as HTMLElement;
|
|
473
|
+
expect(loadedDialog.getAttribute('aria-busy')).toBeNull();
|
|
474
|
+
expect(loadedDialog.querySelector('[role="status"]')).toBeNull();
|
|
475
|
+
expect(loadedDialog.textContent).toContain('营业中');
|
|
476
|
+
expect(loadedDialog.textContent).toContain('10:00–22:00');
|
|
477
|
+
expect(loadedDialog.textContent).toContain('支持店内支付、消费积分');
|
|
478
|
+
expect(loadedDialog.textContent).toContain('完整门店详情');
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it('详情半屏 unknown 营业状态不显示占位文案,营业时间缺省走商场兜底', async () => {
|
|
482
|
+
// 2026-09-04:厂商无真实营业状态,unknown 恒为「营业状态以现场为准」=噪音(同 MerchantRow 列表行裁定)
|
|
483
|
+
let resolveRequest!: (value: unknown) => void;
|
|
484
|
+
const pendingRequest = new Promise<unknown>((resolve) => {
|
|
485
|
+
resolveRequest = resolve;
|
|
486
|
+
});
|
|
487
|
+
vi.mocked(httpGet).mockReturnValueOnce(pendingRequest as never);
|
|
488
|
+
const { host } = render(
|
|
489
|
+
<ShopListCard
|
|
490
|
+
data={{
|
|
491
|
+
context: 'search',
|
|
492
|
+
mallId: 'mall-1',
|
|
493
|
+
miniAppId: 'mini-1',
|
|
494
|
+
items: [{
|
|
495
|
+
...merchant,
|
|
496
|
+
status: { code: 'unknown', label: '营业状态以现场为准', observedAt },
|
|
497
|
+
contactInfo: undefined,
|
|
498
|
+
services: [],
|
|
499
|
+
}],
|
|
500
|
+
refinements: [],
|
|
501
|
+
} as never}
|
|
502
|
+
cardId="shops-unknown-status"
|
|
503
|
+
isHistory={false}
|
|
504
|
+
/>,
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
act(() => (host.querySelector('.sg-rm-item-head') as HTMLButtonElement).click());
|
|
508
|
+
// 列表行无状态行 + 详情半屏骨架期不出现占位文案
|
|
509
|
+
expect(host.querySelector('.sg-rm-item-status-row')).toBeNull();
|
|
510
|
+
let dialog = document.body.querySelector('[role="dialog"]') as HTMLElement;
|
|
511
|
+
expect(dialog.textContent).not.toContain('营业状态以现场为准');
|
|
512
|
+
|
|
513
|
+
await act(async () => {
|
|
514
|
+
resolveRequest({
|
|
515
|
+
data: {
|
|
516
|
+
data: {
|
|
517
|
+
...merchant,
|
|
518
|
+
coverUrls: [merchant.coverUrl],
|
|
519
|
+
status: { code: 'unknown', label: '营业状态以现场为准', observedAt },
|
|
520
|
+
contactInfo: [],
|
|
521
|
+
services: [],
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
await pendingRequest;
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// 加载完成态:unknown 状态 chip 不渲染(stats 行整体缺席),营业时间走商场缺省兜底
|
|
529
|
+
dialog = document.body.querySelector('[role="dialog"]') as HTMLElement;
|
|
530
|
+
expect(dialog.textContent).not.toContain('营业状态以现场为准');
|
|
531
|
+
expect(dialog.querySelector('.sg-shop-sheet__stats')).toBeNull();
|
|
532
|
+
expect(dialog.textContent).toContain('周一-周日 10:00-22:00');
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it('shop-list 详情请求失败后清除骨架并回退列表信息', async () => {
|
|
536
|
+
let rejectRequest!: (reason?: unknown) => void;
|
|
537
|
+
const pendingRequest = new Promise<unknown>((_resolve, reject) => {
|
|
538
|
+
rejectRequest = reject;
|
|
539
|
+
});
|
|
540
|
+
vi.mocked(httpGet).mockReturnValueOnce(pendingRequest as never);
|
|
541
|
+
const { host } = render(
|
|
542
|
+
<ShopListCard
|
|
543
|
+
data={{
|
|
544
|
+
context: 'search',
|
|
545
|
+
mallId: 'mall-1',
|
|
546
|
+
miniAppId: 'mini-1',
|
|
547
|
+
items: [merchant],
|
|
548
|
+
refinements: [],
|
|
549
|
+
} as never}
|
|
550
|
+
cardId="shops-loading-error"
|
|
551
|
+
isHistory={false}
|
|
552
|
+
/>,
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
act(() => (host.querySelector('.sg-rm-item-head') as HTMLButtonElement).click());
|
|
556
|
+
expect(document.body.querySelector('[role="dialog"]')?.getAttribute('aria-busy')).toBe('true');
|
|
557
|
+
await act(async () => {
|
|
558
|
+
rejectRequest(new Error('detail unavailable'));
|
|
559
|
+
await pendingRequest.catch(() => undefined);
|
|
560
|
+
});
|
|
561
|
+
expect(document.body.querySelector('[role="dialog"]')?.getAttribute('aria-busy')).toBeNull();
|
|
562
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('营业中');
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('shop-detail 关闭后重开时忽略上一轮迟到响应', async () => {
|
|
566
|
+
let resolveFirst!: (value: unknown) => void;
|
|
567
|
+
let resolveSecond!: (value: unknown) => void;
|
|
568
|
+
const firstRequest = new Promise<unknown>((resolve) => { resolveFirst = resolve; });
|
|
569
|
+
const secondRequest = new Promise<unknown>((resolve) => { resolveSecond = resolve; });
|
|
570
|
+
vi.mocked(httpGet)
|
|
571
|
+
.mockReturnValueOnce(firstRequest as never)
|
|
572
|
+
.mockReturnValueOnce(secondRequest as never);
|
|
573
|
+
const { host } = render(
|
|
574
|
+
<ShopDetailCard
|
|
575
|
+
data={{
|
|
576
|
+
...merchant,
|
|
577
|
+
mallId: 'mall-1',
|
|
578
|
+
miniAppId: 'mini-1',
|
|
579
|
+
coverUrls: [merchant.coverUrl],
|
|
580
|
+
evidence: [],
|
|
581
|
+
} as never}
|
|
582
|
+
cardId="detail-race"
|
|
583
|
+
isHistory={false}
|
|
584
|
+
/>,
|
|
585
|
+
);
|
|
586
|
+
const trigger = host.querySelector('.sg-merchant-row') as HTMLButtonElement;
|
|
587
|
+
|
|
588
|
+
act(() => trigger.click());
|
|
589
|
+
expect(document.body.querySelector('[role="dialog"]')?.getAttribute('aria-busy')).toBe('true');
|
|
590
|
+
act(() => (document.body.querySelector('[aria-label="关闭门店详情"]') as HTMLButtonElement).click());
|
|
591
|
+
act(() => trigger.click());
|
|
592
|
+
expect(document.body.querySelector('[role="dialog"]')?.getAttribute('aria-busy')).toBe('true');
|
|
593
|
+
|
|
594
|
+
await act(async () => {
|
|
595
|
+
resolveFirst({ data: { data: { ...merchant, name: '迟到的旧详情', coverUrls: [merchant.coverUrl] } } });
|
|
596
|
+
await firstRequest;
|
|
597
|
+
});
|
|
598
|
+
expect(document.body.querySelector('[role="dialog"]')?.getAttribute('aria-busy')).toBe('true');
|
|
599
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).not.toContain('迟到的旧详情');
|
|
600
|
+
|
|
601
|
+
await act(async () => {
|
|
602
|
+
resolveSecond({ data: { data: { ...merchant, name: '当前门店详情', coverUrls: [merchant.coverUrl] } } });
|
|
603
|
+
await secondRequest;
|
|
604
|
+
});
|
|
605
|
+
expect(document.body.querySelector('[role="dialog"]')?.getAttribute('aria-busy')).toBeNull();
|
|
606
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('当前门店详情');
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it('历史 shop-list 保留只读门店详情和列表浏览', () => {
|
|
610
|
+
const items = Array.from({ length: 4 }, (_, index) => ({
|
|
611
|
+
...merchant,
|
|
612
|
+
merchantId: `history-shop-${index}`,
|
|
613
|
+
name: `历史门店${index + 1}`,
|
|
614
|
+
}));
|
|
615
|
+
const { host } = render(
|
|
616
|
+
<ShopListCard
|
|
617
|
+
data={{ context: 'search', items, refinements: [] } as never}
|
|
618
|
+
cardId="history-shop-list"
|
|
619
|
+
isHistory
|
|
620
|
+
/>,
|
|
621
|
+
);
|
|
622
|
+
|
|
623
|
+
const preview = host.querySelector('.sg-rm-item-head') as HTMLButtonElement;
|
|
624
|
+
expect(preview.disabled).toBe(false);
|
|
625
|
+
act(() => preview.click());
|
|
626
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('历史门店1');
|
|
627
|
+
act(() => (document.body.querySelector('[aria-label="关闭门店详情"]') as HTMLButtonElement).click());
|
|
628
|
+
|
|
629
|
+
const viewAll = host.querySelector('.sg-rm-view-all') as HTMLButtonElement;
|
|
630
|
+
expect(viewAll.disabled).toBe(false);
|
|
631
|
+
act(() => viewAll.click());
|
|
632
|
+
expect(document.activeElement).toBe(document.body.querySelector('[aria-label="关闭门店列表"]'));
|
|
633
|
+
expect((document.body.querySelector('.sg-store-list-sheet__item') as HTMLButtonElement).disabled).toBe(false);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
it('shop-detail 以紧凑入口打开半屏,并支持关闭和滚动恢复', () => {
|
|
637
|
+
const { host } = render(
|
|
638
|
+
<ShopDetailCard
|
|
639
|
+
data={{
|
|
640
|
+
...merchant,
|
|
641
|
+
coverUrls: [merchant.coverUrl],
|
|
642
|
+
description: '明亮安静的城市咖啡空间。',
|
|
643
|
+
contactInfo: [
|
|
644
|
+
{ channel: '营业时间', value: '10:00–22:00' },
|
|
645
|
+
{ channel: '电话', value: 'tel:4000001122' },
|
|
646
|
+
],
|
|
647
|
+
evidence: [],
|
|
648
|
+
} as never}
|
|
649
|
+
cardId="detail"
|
|
650
|
+
isHistory={false}
|
|
651
|
+
/>,
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
expect(document.body.querySelector('[role="dialog"]')).toBeNull();
|
|
655
|
+
act(() => (host.querySelector('.sg-merchant-row') as HTMLButtonElement).click());
|
|
656
|
+
expect(document.body.style.overflow).toBe('hidden');
|
|
657
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('明亮安静的城市咖啡空间');
|
|
658
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).not.toContain('旧权益事实');
|
|
659
|
+
const closeButton = document.body.querySelector('[aria-label="关闭门店详情"]') as HTMLButtonElement;
|
|
660
|
+
const phoneLink = document.body.querySelector('[aria-label="拨打日光咖啡实验室电话"]') as HTMLAnchorElement;
|
|
661
|
+
expect(document.activeElement).toBe(closeButton);
|
|
662
|
+
act(() => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', shiftKey: true, bubbles: true })));
|
|
663
|
+
expect(document.activeElement).toBe(phoneLink);
|
|
664
|
+
act(() => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true })));
|
|
665
|
+
expect(document.activeElement).toBe(closeButton);
|
|
666
|
+
|
|
667
|
+
act(() => closeButton.click());
|
|
668
|
+
const sheet = document.body.querySelector('.sg-shop-sheet') as HTMLElement;
|
|
669
|
+
expect(sheet.classList.contains('sg-shop-sheet--closing')).toBe(true);
|
|
670
|
+
expect(document.body.querySelector('[role="dialog"]')).not.toBeNull();
|
|
671
|
+
act(() => sheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
672
|
+
expect(document.body.querySelector('[role="dialog"]')).toBeNull();
|
|
673
|
+
expect(document.body.style.overflow).toBe('');
|
|
674
|
+
|
|
675
|
+
act(() => (host.querySelector('.sg-merchant-row') as HTMLButtonElement).click());
|
|
676
|
+
expect(document.body.querySelector('.sg-shop-sheet')?.classList.contains('sg-shop-sheet--closing')).toBe(false);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
it('门店优惠免费 redirect 与付费抢购复用 openLink,历史卡也保持可点击', () => {
|
|
680
|
+
const freeUrl = 'alipays://platformapi/startapp?appId=demo&page=free';
|
|
681
|
+
const paidUrl = 'alipays://platformapi/startapp?appId=demo&page=paid';
|
|
682
|
+
const { host } = render(
|
|
683
|
+
<ShopDetailCard
|
|
684
|
+
data={{
|
|
685
|
+
...merchant,
|
|
686
|
+
coverUrls: [merchant.coverUrl],
|
|
687
|
+
coupons: [
|
|
688
|
+
{ name: '免费券', salePrice: 0, offerRef: 'offer:1', freeCouponClaimMode: 'REDIRECT', purchaseUrl: freeUrl },
|
|
689
|
+
{ name: '付费券', salePrice: 1, offerRef: 'offer:2', freeCouponClaimMode: 'DIRECT', purchaseUrl: paidUrl },
|
|
690
|
+
],
|
|
691
|
+
evidence: [],
|
|
692
|
+
} as never}
|
|
693
|
+
cardId="history-shop-coupons"
|
|
694
|
+
isHistory
|
|
695
|
+
actionTokens={{ 'promotion.acquire-from-shop-detail': 'must-not-use' }}
|
|
696
|
+
/>,
|
|
697
|
+
);
|
|
698
|
+
act(() => (host.querySelector('.sg-merchant-row') as HTMLButtonElement).click());
|
|
699
|
+
const actions = [...document.body.querySelectorAll<HTMLButtonElement>('.sg-shop-sheet__coupon-claim')];
|
|
700
|
+
expect(actions.map((button) => button.textContent)).toEqual(['去小程序领取', '去小程序抢购']);
|
|
701
|
+
expect(actions.every((button) => !button.disabled)).toBe(true);
|
|
702
|
+
act(() => actions[0].click());
|
|
703
|
+
act(() => actions[1].click());
|
|
704
|
+
expect(vi.mocked(navigateToAlipayPage)).toHaveBeenNthCalledWith(1, freeUrl);
|
|
705
|
+
expect(vi.mocked(navigateToAlipayPage)).toHaveBeenNthCalledWith(2, paidUrl);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
it('门店优惠 direct 保留原写动作;redirect 缺链禁用且无券号继续纯展示', () => {
|
|
709
|
+
const { host } = render(
|
|
710
|
+
<ShopListCard
|
|
711
|
+
data={{
|
|
712
|
+
context: 'search',
|
|
713
|
+
items: [{
|
|
714
|
+
...merchant,
|
|
715
|
+
coupons: [
|
|
716
|
+
{ name: '直领免费券', salePrice: 0, offerRef: 'offer:3', freeCouponClaimMode: 'DIRECT' },
|
|
717
|
+
{ name: '缺链免费券', salePrice: 0, offerRef: 'offer:4', freeCouponClaimMode: 'REDIRECT' },
|
|
718
|
+
{ name: '无券号', salePrice: 0, freeCouponClaimMode: 'REDIRECT' },
|
|
719
|
+
],
|
|
720
|
+
}],
|
|
721
|
+
refinements: [],
|
|
722
|
+
} as never}
|
|
723
|
+
cardId="shop-list-coupons"
|
|
724
|
+
isHistory={false}
|
|
725
|
+
actionTokens={{ 'promotion.acquire-from-shop-list': 'list-token' }}
|
|
726
|
+
/>,
|
|
727
|
+
);
|
|
728
|
+
act(() => (host.querySelector('.sg-rm-item-head') as HTMLButtonElement).click());
|
|
729
|
+
const actions = [...document.body.querySelectorAll<HTMLButtonElement>('.sg-shop-sheet__coupon-claim')];
|
|
730
|
+
expect(actions).toHaveLength(2);
|
|
731
|
+
expect(actions[0].textContent).toBe('领取');
|
|
732
|
+
expect(actions[0].disabled).toBe(false);
|
|
733
|
+
act(() => actions[0].click());
|
|
734
|
+
expect(sendCardAction).toHaveBeenCalledWith(
|
|
735
|
+
'shop-list-coupons',
|
|
736
|
+
{ type: 'moduleAction', actionId: 'promotion.acquire-from-shop-list', contextToken: 'list-token' },
|
|
737
|
+
{ offerRef: 'offer:3' },
|
|
738
|
+
);
|
|
739
|
+
expect(actions[1].textContent).toBe('领取链接暂不可用');
|
|
740
|
+
expect(actions[1].disabled).toBe(true);
|
|
741
|
+
act(() => actions[1].click());
|
|
742
|
+
expect(sendCardAction).toHaveBeenCalledTimes(1);
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
it('shop-detail 的免费券 DIRECT 使用详情卡专属旧写动作', () => {
|
|
746
|
+
const { host } = render(
|
|
747
|
+
<ShopDetailCard
|
|
748
|
+
data={{
|
|
749
|
+
...merchant,
|
|
750
|
+
coverUrls: [merchant.coverUrl],
|
|
751
|
+
coupons: [{ name: '详情直领券', salePrice: 0, offerRef: 'offer:5', freeCouponClaimMode: 'DIRECT' }],
|
|
752
|
+
evidence: [],
|
|
753
|
+
} as never}
|
|
754
|
+
cardId="shop-detail-direct"
|
|
755
|
+
isHistory={false}
|
|
756
|
+
actionTokens={{ 'promotion.acquire-from-shop-detail': 'detail-token' }}
|
|
757
|
+
/>,
|
|
758
|
+
);
|
|
759
|
+
act(() => (host.querySelector('.sg-merchant-row') as HTMLButtonElement).click());
|
|
760
|
+
const claim = document.body.querySelector<HTMLButtonElement>('.sg-shop-sheet__coupon-claim')!;
|
|
761
|
+
act(() => claim.click());
|
|
762
|
+
expect(sendCardAction).toHaveBeenCalledWith(
|
|
763
|
+
'shop-detail-direct',
|
|
764
|
+
{ type: 'moduleAction', actionId: 'promotion.acquire-from-shop-detail', contextToken: 'detail-token' },
|
|
765
|
+
{ offerRef: 'offer:5' },
|
|
766
|
+
);
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
it('券行三项字段职责(2026-09-05):免费文案/右上角业态金标/sub 行可用时间', () => {
|
|
770
|
+
const { host } = render(
|
|
771
|
+
<ShopDetailCard
|
|
772
|
+
data={{
|
|
773
|
+
...merchant,
|
|
774
|
+
coverUrls: [merchant.coverUrl],
|
|
775
|
+
coupons: [
|
|
776
|
+
{
|
|
777
|
+
name: '85元券',
|
|
778
|
+
faceValue: 85,
|
|
779
|
+
salePrice: 0,
|
|
780
|
+
applicableCategories: ['餐饮'],
|
|
781
|
+
validHours: 24,
|
|
782
|
+
usageTimeText: '周一至周日 00:00-23:59',
|
|
783
|
+
},
|
|
784
|
+
{ name: '无附加券', faceValue: 10 },
|
|
785
|
+
],
|
|
786
|
+
evidence: [],
|
|
787
|
+
} as never}
|
|
788
|
+
cardId="shop-coupon-fields"
|
|
789
|
+
isHistory={false}
|
|
790
|
+
/>,
|
|
791
|
+
);
|
|
792
|
+
act(() => (host.querySelector('.sg-merchant-row') as HTMLButtonElement).click());
|
|
793
|
+
const row = document.body.querySelector('.sg-shop-sheet__coupon-row')!;
|
|
794
|
+
expect(row.querySelector('.sg-shop-sheet__coupon-free')?.textContent).toBe('免费');
|
|
795
|
+
expect(row.querySelector('.sg-shop-sheet__coupon-tag')?.textContent).toBe('餐饮');
|
|
796
|
+
expect(row.querySelector('.sg-shop-sheet__coupon-sub')?.textContent).toBe('周一至周日 00:00-23:59');
|
|
797
|
+
expect(row.textContent).not.toContain('免费领取');
|
|
798
|
+
expect(row.textContent).not.toContain('24 小时');
|
|
799
|
+
const plainRow = document.body.querySelectorAll('.sg-shop-sheet__coupon-row')[1]!;
|
|
800
|
+
expect(plainRow.querySelector('.sg-shop-sheet__coupon-tag')).toBeNull();
|
|
801
|
+
expect(plainRow.querySelector('.sg-shop-sheet__coupon-sub')).toBeNull();
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
it('历史 shop-detail 仍可读取完整详情,Escape 可关闭并恢复焦点', () => {
|
|
805
|
+
const { host } = render(
|
|
806
|
+
<ShopDetailCard
|
|
807
|
+
data={{
|
|
808
|
+
...merchant,
|
|
809
|
+
coverUrls: [merchant.coverUrl],
|
|
810
|
+
description: '历史门店详情仍应可读。',
|
|
811
|
+
evidence: [],
|
|
812
|
+
} as never}
|
|
813
|
+
cardId="history-detail"
|
|
814
|
+
isHistory={true}
|
|
815
|
+
/>,
|
|
816
|
+
);
|
|
817
|
+
const trigger = host.querySelector('.sg-merchant-row') as HTMLButtonElement;
|
|
818
|
+
trigger.focus();
|
|
819
|
+
act(() => trigger.click());
|
|
820
|
+
expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('历史门店详情仍应可读');
|
|
821
|
+
expect(document.activeElement).toBe(document.body.querySelector('[aria-label="关闭门店详情"]'));
|
|
822
|
+
|
|
823
|
+
act(() => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })));
|
|
824
|
+
const sheet = document.body.querySelector('.sg-shop-sheet') as HTMLElement;
|
|
825
|
+
expect(sheet.classList.contains('sg-shop-sheet--closing')).toBe(true);
|
|
826
|
+
act(() => sheet.dispatchEvent(new Event('animationend', { bubbles: true })));
|
|
827
|
+
expect(document.body.querySelector('[role="dialog"]')).toBeNull();
|
|
828
|
+
expect(document.activeElement).toBe(trigger);
|
|
829
|
+
});
|
|
830
|
+
});
|