monke7769 / copy1

hayden chen
https://monke7769.github.io/copy1/
MIT License
0 stars 0 forks source link

Debugging Event Issue #13

Open monke7769 opened 4 months ago

monke7769 commented 4 months ago

THE PROBLEM This is not supposed to happen. Screenshot-2024-03-06-at-9-33-12-PM.png When the user searches for "elmo", a "big bird" design also comes up. Not ideal and effectively defeats the purpose of the whole search page.

DEBUGGING: Backend server started: Screenshot-2024-03-05-at-10-53-20-PM.png

Frontend Breakpoints set: Screenshot-2024-03-06-at-8-48-31-PM.png This is when the search button is clicked; code should check if Public or Private is selected Below is the code that is supposed to handle the event that Public is selected

Screenshot-2024-03-06-at-8-48-44-PM.png The first breakpoint makes the HTML table The second breakpoint logs the name of the design found into the console

Backend Breakpoint set: Screenshot-2024-03-06-at-9-00-57-PM.png Red Cherry Tomato inserted at the beginning of the /api/users/search part of the code (called by the getPublic() frontend function)

Running frontend/step over: Screenshot-2024-03-06-at-9-02-59-PM.png The searchTerm is correctly logged and stored, so we know it's not an issue with differentiating between public/private searches

Screenshot-2024-03-06-at-9-04-44-PM.png Now in the getPublic() function, fetching to backend ^^

Screenshot-2024-03-06-at-9-07-17-PM.png Call to backend function worked without any issue. Continue with displayDataInTable ^^

Screenshot-2024-03-06-at-9-08-30-PM.png now logging the names of the designs fetched from the backend ^^

Screenshot-2024-03-06-at-9-09-49-PM.png After running through for each of the designs, these designs were logged in the console. The table is created, as expected, but returns "big bird" design even when only "elmo" was searched for.

We found the problem! The displayDataInTable function does absolutely nothing with searchTerm, so it returns everything (all the designs) that were fetched from the backend without any conditionals. Everything else works as normal (public/private, making table, getting/inserting data from backend into table).

Fixing the problem: Screenshot-2024-03-06-at-9-21-12-PM.png Added the line (conditional) if (searchTerm && (item.Name.includes(searchTerm) || (item.Content && item.Content.includes(searchTerm)))) Removed previous breakpoints that worked fine, now logging all the designs that match the searchTerm

Stepped through the breakpoints. Found out that the conditional was tested twice (for each of the 2 designs in the database) but logging only occurred once (meaning the stuff inside the conditional only ran once), and this time the table was correct :) Screenshot-2024-03-06-at-9-27-16-PM.png

jm1021 commented 4 months ago

break point in backend "cherry tomato" should be in the body of the method you want the code to stop in. All your debugging looks like frontend only.