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 29, 2024
1 parent aae6e0e commit c4d9cc9
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ vi.mock('react-router-dom', async () => ({
useNavigate: () => navigateMock
}))

const mockCloseModal = vi.fn()
const mockOpenModal = vi.fn()

vi.mock('~/context/modal-context', async () => {
const actual = await vi.importActual('~/context/modal-context')
return {
...actual,
useModalContext: () => ({
closeModal: mockCloseModal,
openModal: mockOpenModal
})
}
})

describe('CooperationContainer component ', () => {
it('should render card in container', () => {
renderWithProviders(
Expand Down Expand Up @@ -77,4 +91,23 @@ describe('CooperationContainer component ', () => {
expect(navigateMock).toHaveBeenCalledWith(`./${activeCoop._id}`)
})
})

it('opens modal for Pending status', async () => {
const pendingCoop = { ...mockedCoop, status: StatusEnum.Pending }

renderWithProviders(
<CooperationContainer
filterOptions={filterOptionsMock}
items={[pendingCoop]}
/>,
{ preloadedState }
)

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

await waitFor(() => {
expect(mockOpenModal).toHaveBeenCalled()
})
})
})

0 comments on commit c4d9cc9

Please sign in to comment.