Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nebby2105 committed Dec 17, 2024
1 parent 772c70e commit 48e4d68
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ const AcceptCooperationClosing: React.FC<AcceptCooperationClosureProps> = ({

const handleReasonSubmit = () => {
const isValid = trigger('declineReason')
handleSubmit()

if (isValid && !errors.declineReason) {
handleSubmit()
setIsReasonSubmitted(true)
setIsInputShown(false)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import { render, screen } from '@testing-library/react'
import { fireEvent, render, screen } from '@testing-library/react'
import { beforeEach, vi } from 'vitest'
import AcceptCooperationClosing from '~/containers/my-cooperations/accept-cooperation-close/AcceptCooperationClosing'

vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key) => key
})
}))
describe('AcceptCooperationClosing', () => {
const mockOnAccept = vi.fn()
const mockOnDecline = vi.fn()

beforeEach(() => {
render(<AcceptCooperationClosing user='John Doe' onAccept={mockOnAccept} />)
render(
<AcceptCooperationClosing
user='John Doe'
onAccept={mockOnAccept}
onDecline={mockOnDecline}
/>
)
})

it('should render the title correctly', () => {
const titleText = screen.getByText('titles.acceptCooperationClosing')
expect(titleText).toBeInTheDocument()
})

it('renders input field when decline button is clicked', () => {
const declineBtn = screen.getByText('cooperationDetailsPage.declineBtn')
fireEvent.click(declineBtn)
expect(declineBtn).toBeInTheDocument()
const inputLabel = screen.getByText(
'cooperationDetailsPage.InputFieldLabel'
)
expect(inputLabel).toBeInTheDocument()
})

it('shows error message when submitting empty input', () => {
const declineBtn = screen.getByText('cooperationDetailsPage.declineBtn')
fireEvent.click(declineBtn)
const submitBtn = screen.getByText('cooperationDetailsPage.submitBtn')
expect(submitBtn).toBeInTheDocument()
fireEvent.click(submitBtn)
const errorMessage = screen.getByText('cooperationDetailsPage.inputError')
expect(errorMessage).toBeInTheDocument()
})
})

0 comments on commit 48e4d68

Please sign in to comment.