From b0694e371404344ff09dd7c338f39acd13880518 Mon Sep 17 00:00:00 2001 From: luiqor Date: Fri, 22 Nov 2024 16:10:08 +0200 Subject: [PATCH] fix edit profile tests --- src/pages/edit-profile/EditProfile.tsx | 12 ++++++++---- .../profile-tab-form/ProfileTabForm.spec.jsx | 2 +- tests/unit/redux/editProfileSlice.spec.js | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pages/edit-profile/EditProfile.tsx b/src/pages/edit-profile/EditProfile.tsx index 2f1221681..0f4bb1b2e 100644 --- a/src/pages/edit-profile/EditProfile.tsx +++ b/src/pages/edit-profile/EditProfile.tsx @@ -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, @@ -101,7 +105,7 @@ const EditProfile = () => { if ( typeof initialPhoto === 'string' && - (currentPhoto as UpdatedPhoto).name !== undefined && + isUpdatedPhoto(currentPhoto) && (currentPhoto as UpdatedPhoto).name !== initialPhoto ) { return true @@ -109,15 +113,15 @@ const EditProfile = () => { 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 ) { diff --git a/tests/unit/containers/edit-profile/profile-tab/profile-tab-form/ProfileTabForm.spec.jsx b/tests/unit/containers/edit-profile/profile-tab/profile-tab-form/ProfileTabForm.spec.jsx index f18bfc3e9..a8d29c22b 100644 --- a/tests/unit/containers/edit-profile/profile-tab/profile-tab-form/ProfileTabForm.spec.jsx +++ b/tests/unit/containers/edit-profile/profile-tab/profile-tab-form/ProfileTabForm.spec.jsx @@ -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 () => { diff --git a/tests/unit/redux/editProfileSlice.spec.js b/tests/unit/redux/editProfileSlice.spec.js index e0895ce79..1a6a13eee 100644 --- a/tests/unit/redux/editProfileSlice.spec.js +++ b/tests/unit/redux/editProfileSlice.spec.js @@ -87,7 +87,7 @@ const initialState = { professionalSummary: '', nativeLanguage: '', videoLink: { [UserRoleEnum.Tutor]: '', [UserRoleEnum.Student]: '' }, - photo: '', + photo: null, categories: { [UserRoleEnum.Tutor]: [], [UserRoleEnum.Student]: [] }, professionalBlock: { education: '',