diff --git a/frontend/src/hooks/bot/useFlowCollaboration.test.ts b/frontend/src/hooks/bot/useFlowCollaboration.test.ts index 1d79278d..f36b92e1 100644 --- a/frontend/src/hooks/bot/useFlowCollaboration.test.ts +++ b/frontend/src/hooks/bot/useFlowCollaboration.test.ts @@ -7,6 +7,18 @@ const mockAuthState = { accessToken: 'mock_access_token', }; +vi.mock('@stomp/stompjs', () => { + class MockClient { + activate = vi.fn(); + deactivate = vi.fn(); + publish = vi.fn(); + subscribe = vi.fn(); + } + return { + Client: MockClient, + }; +}); + vi.mock('../../store/useAuthStore', () => { const useAuthStoreMock = (selector?: (state: Record) => unknown) => selector ? selector(mockAuthState) : mockAuthState; diff --git a/frontend/src/hooks/crm/useChatLocalStorage.test.ts b/frontend/src/hooks/crm/useChatLocalStorage.test.ts index c5988268..13b0e3c8 100644 --- a/frontend/src/hooks/crm/useChatLocalStorage.test.ts +++ b/frontend/src/hooks/crm/useChatLocalStorage.test.ts @@ -52,11 +52,15 @@ describe('useChatLocalStorage', () => { expect(result.current.contactNotes[1]).toBe('Important client'); }); - it('toggles favorites correctly', () => { + it('toggles favorites correctly', async () => { const { result } = renderHook(() => useChatLocalStorage({ conversations: mockConversations, selectedConvId: 1 }) ); + await waitFor(() => { + expect(result.current.labels).toEqual(['Lead', 'Customer']); + }); + act(() => { result.current.toggleFavorite(1); }); diff --git a/frontend/src/hooks/crm/useCrmQueries.test.ts b/frontend/src/hooks/crm/useCrmQueries.test.ts index 8c9ec61c..2b526e60 100644 --- a/frontend/src/hooks/crm/useCrmQueries.test.ts +++ b/frontend/src/hooks/crm/useCrmQueries.test.ts @@ -75,7 +75,9 @@ describe('useCrmQueries', () => { await orderRes.current.mutateAsync({ orderId: 1, status: 'COMPLETED' as unknown as never, notes: 'Done' }); }); - expect(sendRes.current.data).toEqual({ id: 2, content: 'Reply', senderType: 'OWNER' }); - expect(orderRes.current.data).toEqual({ id: 1, status: 'COMPLETED' }); + await waitFor(() => { + expect(sendRes.current.data).toEqual({ id: 2, content: 'Reply', senderType: 'OWNER' }); + expect(orderRes.current.data).toEqual({ id: 1, status: 'COMPLETED' }); + }); }); }); diff --git a/frontend/src/pages/admin/AdminStats/AdminStatsPage.test.tsx b/frontend/src/pages/admin/AdminStats/AdminStatsPage.test.tsx index 53aa8105..6a004092 100644 --- a/frontend/src/pages/admin/AdminStats/AdminStatsPage.test.tsx +++ b/frontend/src/pages/admin/AdminStats/AdminStatsPage.test.tsx @@ -1,5 +1,5 @@ import { describe, it, expect, vi } from 'vitest'; -import { render } from '@testing-library/react'; +import { render, waitFor } from '@testing-library/react'; import { AdminStatsPage } from './AdminStatsPage'; import { MemoryRouter } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; @@ -44,8 +44,11 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => ( ); describe('AdminStatsPage', () => { - it('renders admin statistics overview page', () => { + it('renders admin statistics overview page', async () => { const { container } = render(, { wrapper: Wrapper }); expect(container).toBeDefined(); + await waitFor(() => { + expect(container.querySelector('[data-testid="admin-layout"]')).toBeInTheDocument(); + }); }); }); diff --git a/frontend/src/pages/owner/Chat/components/ContactsFilterBuilder.test.tsx b/frontend/src/pages/owner/Chat/components/ContactsFilterBuilder.test.tsx index a38206b2..61d76149 100644 --- a/frontend/src/pages/owner/Chat/components/ContactsFilterBuilder.test.tsx +++ b/frontend/src/pages/owner/Chat/components/ContactsFilterBuilder.test.tsx @@ -12,7 +12,7 @@ vi.mock('../../../../api/bot', () => ({ })); describe('ContactsFilterBuilder', () => { - it('returns null when isOpen=false', () => { + it('returns null when isOpen=false', async () => { const { container } = render( ( ); describe('Templates Pages', () => { - it('renders MyTemplatesPage', () => { + it('renders MyTemplatesPage', async () => { const { container } = render(, { wrapper: Wrapper }); expect(container).toBeDefined(); + await waitFor(() => { + expect(container.querySelector('[data-testid="dashboard-layout"]')).toBeInTheDocument(); + }); }); it('renders TemplateDetailPage', () => {