test: add frontend dialog interaction coverage

This commit is contained in:
cesnimda
2026-03-22 14:29:31 +01:00
parent 9908674b8f
commit 51e3d695b3
2 changed files with 53 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import React from 'react';
import '@testing-library/jest-dom';
import { fireEvent, render, screen } from '@testing-library/react';
import { ConfirmProvider } from './confirm';
import { useConfirm } from './confirm';
function DeleteDemo() {
const { confirm } = useConfirm();
return <button onClick={() => void confirm({ title: 'Delete attachment', message: 'Delete attachment "resume.pdf"?', confirmLabel: 'Delete', destructive: true })}>Delete attachment</button>;
}
test('destructive confirm dialog shows warning state', async () => {
render(
<ConfirmProvider>
<DeleteDemo />
</ConfirmProvider>,
);
fireEvent.click(screen.getByRole('button', { name: /delete attachment/i }));
expect(await screen.findByText(/this action may be hard to undo/i)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /^delete$/i })).toBeInTheDocument();
});