开发者报障:弹窗打开默认高亮当前绑定行,点它只关闭不保存 ⇒ 要确认同一行必须 先点别的再点回来。 · 打开时无选中态;当前绑定行改为弱提示(左侧 2px 靛蓝细条 + aria-current); · 点任意一行(含当前绑定行)都立即保存(后端同 SKU 走幂等分支,不重复改明细); · 不可抵扣行仍禁用,搜索/过滤/展示/文案不变;两个入口共用同一组件,一处修复覆盖两处; · 新增 render 测试 7 条(含"点当前已绑定且不可抵扣那行"场景与连点幂等)+ 契约测试更新; · 设计文补 2026-10-20 修订说明。 验证:tsc 0 错;src/components/order + src/i18n 181 条、orderManagement 124 条全过;变异校验可抓住原 bug。
96 lines
4.7 KiB
TypeScript
96 lines
4.7 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
/**
|
|
* 「选择抵扣的库存商品」弹窗的选择态契约。
|
|
*
|
|
* 演变:
|
|
* · 2026-10-14 开发者:「选择抵扣的商品 这块应该默认选中展示当前被抵扣的呀」
|
|
* ⇒ 当时做成**勾 + 底色高亮**的"已选中",且**点它只关闭、不写库**;
|
|
* · 2026-10-20 开发者报障:打开就默认高亮当前那一行(例如「精瘦肉 · 不可抵扣」),
|
|
* 想再点同一个商品确认时**没有反应**(点已选中项不触发变更),必须"先点别的、再点回来"才生效。
|
|
*
|
|
* 现行契约(2026-10-20 起,取代上面那条):
|
|
* · **打开时选中态为空**:当前值那行只留**弱提示**(左侧细条 + `aria-current`),
|
|
* 不是"可点击的 selected 态"(无勾、无底色高亮、无 `aria-selected`/`aria-pressed`);
|
|
* · **点任意一行(含当前值那行)都立即保存 + 重跑抵扣** —— 服务端同 SKU 是幂等分支
|
|
* (只 upsert 映射、不重复改明细,返回 `applied: false`,见
|
|
* `server/src/services/mainSystemItemSkuMappingService.ts` 的 `setMainSystemItemCoverSku`);
|
|
* · 不可抵扣且**非**当前值的行仍 `disabled`;当前值行即使不可抵扣也保持可点(既有规则)。
|
|
*
|
|
* 渲染/点击行为另见 `OrderItemCoverSkuModal.render.test.tsx`(真渲染断言)。
|
|
*/
|
|
const modal = readFileSync(new URL('./OrderItemCoverSkuModal.tsx', import.meta.url), 'utf8');
|
|
const page = readFileSync(
|
|
new URL('../../pages/orders/orderManagement/OrderManagementPage.tsx', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const api = readFileSync(new URL('../../utils/workflowApi.ts', import.meta.url), 'utf8');
|
|
|
|
const locales = ['zh-CN', 'en', 'id'] as const;
|
|
const localeSource = (locale: string, ns: string) =>
|
|
readFileSync(new URL(`../../i18n/locales/${locale}/${ns}.ts`, import.meta.url), 'utf8');
|
|
|
|
/** 弹窗用到的所有 i18n key */
|
|
function usedKeys(): string[] {
|
|
const keys = new Set<string>();
|
|
for (const match of modal.matchAll(/t\('([^']+)'/g)) keys.add(match[1]);
|
|
return [...keys];
|
|
}
|
|
|
|
describe('选择抵扣的库存商品弹窗 · 选择态', () => {
|
|
it('① 初始无选中:当前值只留弱提示(aria-current + 左侧细条),没有勾 / 底色高亮', () => {
|
|
expect(modal).toContain('currentSkuCode');
|
|
expect(modal).toContain(
|
|
'const isCurrent = Boolean(currentSkuCode) && opt.sku_code === currentSkuCode'
|
|
);
|
|
// 弱提示:无障碍语义 + 一条细左边框(不是可点击的 selected 态)
|
|
expect(modal).toContain("aria-current={isCurrent ? 'true' : undefined}");
|
|
expect(modal).toContain('border-indigo-400');
|
|
// 旧的"已选中"视觉必须消失
|
|
expect(modal).not.toContain('bg-indigo-50');
|
|
expect(modal).not.toContain('ring-inset ring-indigo-400');
|
|
expect(modal).not.toContain('Check');
|
|
// 也不许换成别的"选中"语义
|
|
expect(modal).not.toContain('aria-selected');
|
|
expect(modal).not.toContain('aria-pressed');
|
|
});
|
|
|
|
it('② 点任意一行(含当前值那行)都立即走 pick,不再有"点了只关闭"的特例', () => {
|
|
expect(modal).toContain('onClick={() => void pick(opt.sku_code)}');
|
|
expect(modal).not.toContain('isCurrent ? onClose()');
|
|
// 点击必须落到保存链路(同 SKU 幂等由服务端保证)
|
|
expect(modal).toContain('setOrderItemStockCoverSkuApi(orderCode, itemId, skuCode)');
|
|
});
|
|
|
|
it('③ 不可抵扣行仍按既有规则禁用(当前值行保持可点)', () => {
|
|
expect(modal).toContain('Boolean(savingCode) || (!isCurrent && coverable <= 0)');
|
|
});
|
|
|
|
it('④ 取数带上明细 id:服务端据此把当前 SKU 补进结果并置顶', () => {
|
|
expect(modal).toContain('fetchStockCoverSkuOptionsApi(orderCode, debounced, itemId || undefined)');
|
|
expect(api).toContain("qs.set('item_id', itemId.trim())");
|
|
expect(page).toContain('currentSkuCode={coverSkuItem?.sku_code || null}');
|
|
});
|
|
|
|
it('⑤ 仍未新增文案:用到的 key 三语全都已存在,且代码里不硬编码中文', () => {
|
|
const keys = usedKeys();
|
|
expect(keys).toContain('orders.coverSku.title');
|
|
expect(keys).toContain('orders.coverSku.notCoverable');
|
|
for (const key of keys) {
|
|
const [ns, ...rest] = key.split('.');
|
|
const leaf = rest.join('.');
|
|
for (const locale of locales) {
|
|
expect(
|
|
localeSource(locale, ns).includes(`'${leaf}'`) || localeSource(locale, ns).includes(`${leaf}:`),
|
|
`${locale}/${ns}.ts 缺少词条 ${key}`
|
|
).toBe(true);
|
|
}
|
|
}
|
|
const codeOnly = modal
|
|
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
.replace(/^\s*\/\/.*$/gm, '');
|
|
expect(codeOnly).not.toMatch(/[\u4e00-\u9fa5]/);
|
|
});
|
|
});
|