Facebook Pixel

Food Ordering App: Edge Cases and Testing

Edge cases make the app production-ready. Here are the cases to handle and how to test.

Food Ordering App: Edge Cases and Testing

Edge cases make the food ordering app production-ready. Here are the cases to handle and how to test.

Edge Cases to Handle

1. Empty Cart

if (Object.keys(cart).length === 0) { cartDiv.innerHTML = "<p>Your cart is empty</p>"; return; } `` #### 2. No Search Results ```js if (filteredItems.length === 0) { menuDiv.innerHTML = "<p>No items found</p>"; return; } `` #### 3. Quantity 0 ```js function changeQuantity(id, delta) { cart[id] = (cart[id] || 0) + delta; if (cart[id] <= 0) delete cart[id]; renderCart(); } `` #### 4. Decimal Prices ```js const total = Object.entries(cart).reduce((sum, [id, qty]) => { const item = menu.find((m) => m.id === parseInt(id)); return sum + item.price * qty; }, 0); // format: total.toFixed(2) `` #### 5. Clear Cart ```js function clearCart() { cart = {}; renderCart(); } `` #### 6. Checkout Confirmation ```js function checkout() { if (Object.keys(cart).length === 0) return; const total = calculateTotal(); alert(`Order placed! Total: ₹${total}`); clearCart(); } `` ### How to Test 1. **Add items to cart**: verify the cart updates. 2. **Change quantity**: verify the total updates. 3. **Remove items**: verify the cart updates. 4. **Search**: verify only matching items show. 5. **Filter veg/non-veg**: verify the correct items show. 6. **Filter by category**: verify only that category shows. 7. **Empty cart**: verify the empty message shows. 8. **No results**: verify the no results message shows. 9. **Clear cart**: verify the cart is emptied. 10. **Checkout**: verify the confirmation and cart clearing. ### The Takeaway Handle edge cases: empty cart, no search results, quantity 0 (remove), decimal prices (toFixed), clear cart, and checkout confirmation. Test each feature manually: add, remove, quantity, search, filters, empty states, clear, and checkout. Edge cases and testing show production-readiness.

Empty cart (show message), no search results (show message), quantity 0 (remove from cart), decimal prices (use toFixed), clear cart button, and checkout confirmation. These show production-readiness.

Test manually: add items to cart, change quantity, remove items, search, apply filters, verify empty cart message, verify no results message, clear cart, and checkout. Test each feature and edge case before submitting.

Calculate the total normally, then format with toFixed(2): total.toFixed(2). This ensures two decimal places (e.g., 150.50 instead of 150.5). Use parseFloat when reading prices to avoid string concatenation.

Check if the cart is empty (return early). Calculate the total. Show a confirmation (alert or modal). Clear the cart after confirmation. Disable checkout if the cart is empty.

When decrementing, check if the quantity drops to 0 or below. If so, delete the item from the cart: if (cart[id] <= 0) delete cart[id]. This keeps the cart clean and prevents negative quantities.

Ready to master React completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.