From c1410874d502c25b0d8acaa2ec42d0ff2dbc6fe0 Mon Sep 17 00:00:00 2001 From: nebby2105 Date: Thu, 28 Nov 2024 19:23:20 +0200 Subject: [PATCH] add test for CooperationContainer --- .../CooperationContainer.spec.jsx | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/unit/containers/my-cooperations/cooperation-container/CooperationContainer.spec.jsx b/tests/unit/containers/my-cooperations/cooperation-container/CooperationContainer.spec.jsx index 9b82547bd..f179e4fd1 100644 --- a/tests/unit/containers/my-cooperations/cooperation-container/CooperationContainer.spec.jsx +++ b/tests/unit/containers/my-cooperations/cooperation-container/CooperationContainer.spec.jsx @@ -1,7 +1,10 @@ -import { screen } from '@testing-library/react' +import { screen, waitFor } from '@testing-library/react' import { renderWithProviders } from '~tests/test-utils' import CooperationContainer from '~/containers/my-cooperations/cooperations-container/CooperationContainer' import { mockedCoop } from '~tests/unit/containers/my-cooperations/MyCooperations.spec.constants' +import { vi } from 'vitest' +import userEvent from '@testing-library/user-event' +import { StatusEnum } from '~/types' const filterOptionsMock = { filters: { @@ -17,6 +20,13 @@ const preloadedState = { socket: { usersOnline: [] } } +const navigateMock = vi.fn() + +vi.mock('react-router-dom', async () => ({ + ...(await vi.importActual('react-router-dom')), + useNavigate: () => navigateMock +})) + describe('CooperationContainer component ', () => { it('should render card in container', () => { renderWithProviders( @@ -31,4 +41,22 @@ describe('CooperationContainer component ', () => { expect(level).toBeInTheDocument() }) + + it('navigates to cooperation detail for Active status', async () => { + const activeCoop = { ...mockedCoop, status: StatusEnum.Active } + renderWithProviders( + , + { preloadedState } + ) + + const card = screen.getByText(activeCoop.offer.subject.name) + userEvent.click(card) + + await waitFor(() => { + expect(navigateMock).toHaveBeenCalledWith(`./${activeCoop._id}`) + }) + }) })