Files
Genarrative/src/components/common/PlatformUnsavedLeaveConfirmDialog.test.tsx
T
kdletters 7005792580 收口未保存离开确认弹窗
新增 PlatformUnsavedLeaveConfirmDialog 统一承接未保存离开确认壳层
迁移 RPG 创作编辑器的关闭未保存修改与退出未保存结果确认复用共享组件
补充共享组件测试并更新 PlatformUiKit 收口文档与决策记录
2026-06-10 22:26:05 +08:00

54 lines
1.7 KiB
TypeScript

/* @vitest-environment jsdom */
import { fireEvent, render, screen, within } from '@testing-library/react';
import { expect, test, vi } from 'vitest';
import { PlatformUnsavedLeaveConfirmDialog } from './PlatformUnsavedLeaveConfirmDialog';
test('renders the platform variant with leave/continue actions', () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
render(
<PlatformUnsavedLeaveConfirmDialog
open
title="确认关闭"
onClose={onClose}
onConfirm={onConfirm}
>
当前修改尚未保存,确认关闭吗?
</PlatformUnsavedLeaveConfirmDialog>,
);
const dialog = screen.getByRole('dialog', { name: '确认关闭' });
expect(within(dialog).getByText('当前修改尚未保存,确认关闭吗?')).toBeTruthy();
fireEvent.click(within(dialog).getByRole('button', { name: '继续编辑' }));
expect(onClose).toHaveBeenCalledTimes(1);
fireEvent.click(within(dialog).getByRole('button', { name: '确认关闭' }));
expect(onConfirm).toHaveBeenCalledTimes(1);
});
test('supports pixel variant with custom confirm label', () => {
render(
<PlatformUnsavedLeaveConfirmDialog
open
title="确认退出"
confirmLabel="仍然退出"
variant="pixel"
onClose={() => {}}
onConfirm={() => {}}
>
当前生成画面还未保存。
</PlatformUnsavedLeaveConfirmDialog>,
);
const dialog = screen.getByRole('dialog', { name: '确认退出' });
expect(dialog.className).toContain('pixel-modal-shell');
expect(within(dialog).getByRole('button', { name: '仍然退出' })).toBeTruthy();
expect(within(dialog).getByRole('button', { name: '继续编辑' })).toBeTruthy();
});