修复「沿用上一版本截图」按钮永远可点
- 该按钮只在已读到上一版本截图时渲染,原 disabled 判断恒为 false - 改为逐槽比较草稿与上一版本 objectKey,相同即停用,避免重复标 dirty - 补充相同停用 / 不同可用并触发沿用的测试
This commit is contained in:
+9
-1
@@ -154,6 +154,14 @@ export function FormCard({
|
||||
} else if (localScreenshotCount > 0) {
|
||||
screenshotSummary = `本地 ${localScreenshotCount} 张`;
|
||||
}
|
||||
// 「沿用上一版本截图」是把上一版本 key 整组写进草稿。草稿已经与上一版本逐槽相同就停用,否则重复
|
||||
// 点击会不断标 dirty、触发无意义的自动保存与冲突往返。
|
||||
const screenshotsSame =
|
||||
onlineScreenshots.length > 0 &&
|
||||
form.screenshotPaths.length === onlineScreenshots.length &&
|
||||
form.screenshotPaths.every(
|
||||
(path, index) => path.trim() === onlineScreenshots[index]?.objectKey,
|
||||
);
|
||||
|
||||
// 封面预览三态:空值显示沿用 / 未选占位;本地路径走项目内预览;线上 objectKey 走上一版本换签。
|
||||
const renderCoverPreview = (): ReactNode => {
|
||||
@@ -498,7 +506,7 @@ export function FormCard({
|
||||
variant="link"
|
||||
ariaLabel="沿用上一版本截图"
|
||||
title="把上一版本截图逐槽写进草稿,发布时整组沿用"
|
||||
disabled={onlineScreenshots.length === 0}
|
||||
disabled={screenshotsSame}
|
||||
onClick={onAdoptScreenshots}
|
||||
>
|
||||
<ArrowUp size={13} aria-hidden="true" />
|
||||
|
||||
@@ -1178,6 +1178,43 @@ describe('面板左半', () => {
|
||||
expect(adoptOnlineCover).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('截图已与上一版本逐槽相同时停用「沿用上一版本截图」', () => {
|
||||
const adoptOnlineScreenshots = vi.fn();
|
||||
renderPane(
|
||||
fakeTaonier({
|
||||
form: { ...FORM, screenshotPaths: ['shot/1.png'] },
|
||||
online: ONLINE_VALUES,
|
||||
onlineState: 'ready',
|
||||
adoptOnlineScreenshots,
|
||||
}),
|
||||
);
|
||||
// 已逐槽相同:再点只会重复标 dirty,按钮停用。
|
||||
expect(
|
||||
(
|
||||
screen.getByRole('button', {
|
||||
name: '沿用上一版本截图',
|
||||
}) as HTMLButtonElement
|
||||
).disabled,
|
||||
).toBe(true);
|
||||
|
||||
cleanup();
|
||||
renderPane(
|
||||
fakeTaonier({
|
||||
form: FORM,
|
||||
online: ONLINE_VALUES,
|
||||
onlineState: 'ready',
|
||||
adoptOnlineScreenshots,
|
||||
}),
|
||||
);
|
||||
// 草稿是本地图,与上一版本不同:按钮可用并触发沿用。
|
||||
const differentButton = screen.getByRole('button', {
|
||||
name: '沿用上一版本截图',
|
||||
});
|
||||
expect((differentButton as HTMLButtonElement).disabled).toBe(false);
|
||||
fireEvent.click(differentButton);
|
||||
expect(adoptOnlineScreenshots).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('上一版本封面换签失败时显示原因,不伪装成「没有封面」', () => {
|
||||
renderPane(
|
||||
fakeTaonier({
|
||||
|
||||
Reference in New Issue
Block a user