Skip to content

Commit

Permalink
implement some code feature
Browse files Browse the repository at this point in the history
  • Loading branch information
BohdanMylyi committed Jul 31, 2024
1 parent e5a122a commit f646c49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function SubjectGroup({
)

const handleDisableOptions = (option: Partial<SubjectInterface>) => {
return disableOptions.some((subject) => subject._id === option._id)
return disableOptions.some((subjects) => subjects._id === option._id)
}

return (
Expand Down Expand Up @@ -132,18 +132,34 @@ const AddProfessionalCategoryModal: FC<AddProfessionalCategoryModalProps> = ({
})
)
} else {
// Ensure all necessary fields are populated
const categoryToAdd: UserMainSubject = {
_id: uuidv4(),
isDeletionBlocked,
...data
}
dispatch(
addCategory({
category: categoryToAdd,
userRole: userRoleCategory
})
)

if (!categoryToAdd.category?._id || !categoryToAdd.subjects.length) {
console.error(
'Required fields are missing for the new category:',
categoryToAdd
)
return
}

try {
dispatch(
addCategory({
category: categoryToAdd,
userRole: userRoleCategory
})
)
} catch (error) {
console.error('Failed to add category:', error)
// Optionally, show an error message to the user
}
}

closeModal()
}

Expand Down Expand Up @@ -201,7 +217,7 @@ const AddProfessionalCategoryModal: FC<AddProfessionalCategoryModalProps> = ({
const handleBlockOption = (option: CategoryNameInterface) => {
const isCurrent = option._id !== data.category?._id
const isBlocked = blockedCategoriesOptions.some(
(mainSubject) => mainSubject.category?._id === option._id
(mainSubjects) => mainSubjects.category?._id === option._id
)
return isBlocked && isCurrent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,34 +204,4 @@ describe('AddProfessionalCategoryModal with initial value', () => {

expect(mockCloseModal).toHaveBeenCalled()
})

it('should render correctly with empty blockedCategoriesOptions', async () => {
renderWithProviders(
<AddProfessionalCategoryModal
blockedCategoriesOptions={[]}
closeModal={mockCloseModal}
/>
)

const categoryAutocomplete = screen.getByLabelText(
/editProfilePage.profile.professionalTab.mainStudyCategory/
)

expect(categoryAutocomplete).toBeInTheDocument()
})

it('should show error message if API call fails', async () => {
mockAxiosClient.onGet(URLs.categories.getNames).reply(500)
renderWithProviders(
<AddProfessionalCategoryModal
blockedCategoriesOptions={mockedBlockedCategory}
closeModal={mockCloseModal}
/>
)

await waitFor(() => {
const errorMessage = screen.getByText(/error/i)
expect(errorMessage).toBeInTheDocument()
})
})
})

0 comments on commit f646c49

Please sign in to comment.