Clone the project
git clone https://github.com/Sabelo710/SARS-Risk-Data-Frontend.gitEnter the sars-risk-data folder
cd sars-risk-dataInstall dependencies
npm installRun the application
npm run devAfter that you will see the following on your cli

Open http://localhost:5173 on your browser:

Enter comma-separated numbers e.g 25,0,0.5,1,100 and click "Sort Numbers"

Click "Toggle Sort (Ascending/Descending)" to sort the number list in ascending or descending order

- Use the vite build tool:
- Instant startup and lightning-fast Hot Module Replacement
- No Webpack config. No Babel setup. Just code.
- Speeds up UI tweaking
- Use react-hook-form:
- Minimal re-renders - only fields that change are re-rendered, leading to significant performance gains
- Schema-based validation (via Yup or Zod) for future multi-step wizards
- Conditional validations
- Custom useNumberSorter:
- No unnecessary re-computations since sorting only happens during render phase
- Single responsibility principle - the hook only handles number sorting
- Easy to test in isolation
- Can be easily extended (e.g., adding custom comparator functions) without affecting consuming components
- Grouping css with component:
- Keeps code modular
- Makes it easy reuse in future
-
Test the custom hook (
useNumberSorter.js):- Verify that the initial state is correct (sortDirection is "asc", sortedNumbers is empty).
- Test that
sortNumberscorrectly parses and stores numbers from a string. - Test that
toggleSortDirectionswitches between "asc" and "desc". - Ensure that numbers are sorted correctly in both ascending and descending order.
-
Test the form component (
NumberInputForm.jsx):- Check that the form renders correctly.
- Validate that entering valid numbers enables form submission.
- Validate that entering invalid input (e.g., letters) shows an error.
- Ensure the
onSubmitcallback is called with the correct data.
-
Test the list component (
SortableNumbersList.jsx):- Ensure the list displays the numbers in the correct order.
- Test that clicking the toggle button calls the
onToggleSorthandler. - Check that the sort direction label updates appropriately.
-
Test the page component (
NumberSorter.jsx):- Ensure the form and list render as expected.
- Test the integration: submitting the form updates the list, and toggling sort updates the order.
-
Test the main app (
App.jsx):- Ensure the
NumberSorterpage is rendered.
- Ensure the
I would use a testing library like React Testing Library and Jest to simulate user interactions and assert expected outcomes. Mock hooks or props as needed to isolate component behavior.

