Skip to content

Commit

Permalink
fix edit profile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luiqor committed Nov 23, 2024
1 parent fc7e53e commit b0694e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/pages/edit-profile/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const EditProfile = () => {
return JSON.stringify(initialData) !== JSON.stringify(currentData)
}

const isUpdatedPhoto = (photo: string | null | UpdatedPhoto): boolean => {
return photo !== null && typeof photo === 'object' && 'name' in photo
}

const hasPhotoChanges = useCallback(
(
initialPhoto: string | null | UpdatedPhoto,
Expand All @@ -101,23 +105,23 @@ const EditProfile = () => {

if (
typeof initialPhoto === 'string' &&
(currentPhoto as UpdatedPhoto).name !== undefined &&
isUpdatedPhoto(currentPhoto) &&
(currentPhoto as UpdatedPhoto).name !== initialPhoto
) {
return true
}

if (
initialPhoto === null &&
(currentPhoto as UpdatedPhoto).name !== undefined &&
isUpdatedPhoto(currentPhoto) &&
areAllValuesEmptyStrings(currentPhoto as UpdatedPhoto)
) {
return true
}

if (
(initialPhoto as UpdatedPhoto).name !== undefined &&
(currentPhoto as UpdatedPhoto).name !== undefined &&
isUpdatedPhoto(initialPhoto) &&
isUpdatedPhoto(currentPhoto) &&
(initialPhoto as UpdatedPhoto).name !==
(currentPhoto as UpdatedPhoto).name
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('ProfileTabForm', () => {
const removePhotoBtn = screen.getByRole('button', { name: 'common.remove' })
fireEvent.click(removePhotoBtn)

expect(handleNonInputValueChange).toHaveBeenCalledWith('photo', null)
expect(handleNonInputValueChange).toHaveBeenCalledWith('photo', '')
})

it('should handle adding a photo', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/redux/editProfileSlice.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const initialState = {
professionalSummary: '',
nativeLanguage: '',
videoLink: { [UserRoleEnum.Tutor]: '', [UserRoleEnum.Student]: '' },
photo: '',
photo: null,
categories: { [UserRoleEnum.Tutor]: [], [UserRoleEnum.Student]: [] },
professionalBlock: {
education: '',
Expand Down

0 comments on commit b0694e3

Please sign in to comment.