Fix typo and add better ops for decrypt API calls

This commit is contained in:
Jack Kingsman
2026-03-15 15:47:09 -07:00
parent cf1a55e258
commit 0b1a19164a
36 changed files with 134 additions and 142 deletions
@@ -11,6 +11,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import { NewMessageModal } from '../components/NewMessageModal';
import type { Contact } from '../types';
import { toast } from '../components/ui/sonner';
// Mock sonner (toast)
vi.mock('../components/ui/sonner', () => ({
@@ -35,6 +36,11 @@ const mockContact: Contact = {
first_seen: null,
};
const mockToast = toast as unknown as {
success: ReturnType<typeof vi.fn>;
error: ReturnType<typeof vi.fn>;
};
describe('NewMessageModal form reset', () => {
const onClose = vi.fn();
const onSelectConversation = vi.fn();
@@ -137,6 +143,24 @@ describe('NewMessageModal form reset', () => {
});
expect(onClose).toHaveBeenCalled();
});
it('toasts when creation fails', async () => {
const user = userEvent.setup();
onCreateChannel.mockRejectedValueOnce(new Error('Bad key'));
renderModal();
await switchToTab(user, 'Room');
await user.type(screen.getByPlaceholderText('Room name'), 'MyRoom');
await user.type(screen.getByPlaceholderText('Pre-shared key (hex)'), 'cc'.repeat(16));
await user.click(screen.getByRole('button', { name: 'Create' }));
await waitFor(() => {
expect(mockToast.error).toHaveBeenCalledWith('Failed to create conversation', {
description: 'Bad key',
});
});
expect(screen.getByText('Bad key')).toBeTruthy();
});
});
describe('tab switching resets form', () => {