Files
Genarrative/src/components/common/PlatformDangerConfirmDialog.test.tsx
T
k88936 e6b3199490
Project CI / Repository checks (push) Successful in 48s
Project CI / Frontend tests (push) Successful in 3m21s
Project CI / Backend tests (push) Successful in 3m53s
Project CI / Native shell tests (push) Successful in 11m16s
Fix/统一修复modal样式失效 (#122)
之前遇到几次弹窗的样式不生效,bug 现在在画布agent的删除对话弹窗又出现了,
这个pr把类似的修改集中到最下层的UnifiedModal,适用于所有的modal,
一些特殊的modal有特殊处理.

画布agent的删除对话弹窗
![shotmd-1785399342.jpg](/attachments/d63d7dc6-bf7e-4f13-bfe8-bc4716cd798f)

---------

Co-authored-by: 段舒康 <kdletters@qq.com>
Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/122
Reviewed-by: 段舒康 <kdletters@qq.com>
Co-authored-by: 王德宇 <kvtodev@outlook.com>
Co-committed-by: 王德宇 <kvtodev@outlook.com>
2026-08-03 17:55:47 +08:00

73 lines
2.4 KiB
TypeScript

/* @vitest-environment jsdom */
import { fireEvent, render, screen, within } from '@testing-library/react';
import { expect, test, vi } from 'vitest';
import { PlatformDangerConfirmDialog } from './PlatformDangerConfirmDialog';
test('renders a standard danger confirmation with cancel and confirm actions', () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
render(
<PlatformDangerConfirmDialog
open
title="删除作品"
description="确认删除《潮雾列岛》吗?"
onClose={onClose}
onConfirm={onConfirm}
confirmLabel="确认删除"
>
删除后不可恢复。
</PlatformDangerConfirmDialog>,
);
const dialog = screen.getByRole('dialog', { name: '删除作品' });
expect(dialog.parentElement?.className).toContain('platform-theme--light');
expect(dialog.parentElement?.className).toContain('z-[140]');
expect(dialog.className).toContain('platform-remap-surface');
expect(dialog.className).toContain('shadow-[0_24px_80px_rgba(0,0,0,0.55)]');
expect(within(dialog).getByText('确认删除《潮雾列岛》吗?')).toBeTruthy();
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('forwards busy state and custom busy label for destructive actions', () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
render(
<PlatformDangerConfirmDialog
open
title="删除作品"
onClose={onClose}
onConfirm={onConfirm}
confirmLabel="确认删除"
busyConfirmLabel="删除中"
busy
closeOnBackdrop={false}
>
正在删除。
</PlatformDangerConfirmDialog>,
);
const dialog = screen.getByRole('dialog', { name: '删除作品' });
const confirmButton = within(dialog).getByRole('button', { name: '删除中' });
const cancelButton = within(dialog).getByRole('button', { name: '取消' });
expect((confirmButton as HTMLButtonElement).disabled).toBe(true);
expect((cancelButton as HTMLButtonElement).disabled).toBe(true);
fireEvent.click(confirmButton);
fireEvent.click(cancelButton);
expect(onClose).not.toHaveBeenCalled();
expect(onConfirm).not.toHaveBeenCalled();
});