Skip to content

Commit

Permalink
add test for CooperationContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
nebby2105 committed Nov 28, 2024
1 parent b8bffcc commit c141087
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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(
Expand All @@ -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(
<CooperationContainer
filterOptions={filterOptionsMock}
items={[activeCoop]}
/>,
{ preloadedState }
)

const card = screen.getByText(activeCoop.offer.subject.name)
userEvent.click(card)

await waitFor(() => {
expect(navigateMock).toHaveBeenCalledWith(`./${activeCoop._id}`)
})
})
})

0 comments on commit c141087

Please sign in to comment.