oss-slu / Enhancing-Bioinformatics-Research-through-LLM

Apache License 2.0
0 stars 0 forks source link

Resizing profile image to 100x100 upon upload and adding a unit test for setting avatar image #34

Closed oam67 closed 3 weeks ago

oam67 commented 1 month ago

Fixes #30

What was changed?

For this issue, I modified the UserProfile page of the application. Previously, any image that was uploaded by the user was saved as their profile picture. My modifications to the UserProfile page ensures that any profile picture uploaded by the user is converted into a 100x100 image before saving it as the user's avatar. I also created a simple unit test to check if the user's avatar successfully changes.

Why was it changed?

Originally, an error occurred when trying to change the profile picture in the UserProfile page. This would happen because the size of the profile picture being uploaded exceeded the size limit of the server. This would also cause the terminal to display "PayloadTooLargeError: request entity too large." My code aims to fix this problem by resizing the profile picture to be 100x100 before it is saved. This ensures that any profile picture, including large profile pictures, are made small enough that they don't exceed size limits and cause errors. A unit test that changed the user's avatar was added to ensure that updates to the user avatar are possible.

How was it changed?

The first file I modified was UserProfile.js. Within this file, I focused on updating the handleImageChange function. The function first checks if the user has uploaded an image file. A FileReader object then converts the image into a Base64-encoded URL. Next an image object is created and its src attribute is set to the Base64-encoded URL. A 100x100 element is used to resize the image object. Lastly, the resized image is saved. The second file I modified was UserProfile.test.js. I created a new unit test that initialized mock image data and checked whether the src attribute of the avatar element could be changed. To access the avatar element in my unit test, I had to add data-testid="avatar" within UserProfile.js.

Screenshots that show the changes (if applicable):

image image