Show the subtotal in the checkout order summary

React · React · beginner · modification

The checkout review page listed the items in the order but no subtotal, so customers added up the line totals in their heads before going on to payment. `src/orders/OrderSummary.jsx` now computes the subtotal from the order's lines and shows it in a footer row under the items, formatted like the line totals. `src/orders/OrderSummary.test.jsx` (new) covers the item rows and the subtotal row.

Shop SPA on React 18.3 (Vite, function components). Tests run with `npm test`: Vitest 2 with @testing-library/react 16 in jsdom. Existing and unchanged: `CheckoutReview.jsx` renders `<OrderSummary lines={cart.lines} />` once the cart has loaded and shows the loading, error and empty-cart states itself, so `lines` always holds at least one line. `lines` is an array of at most 50 `{ id, name, quantity, unitPriceCents }` objects: `id` is a unique non-empty string, `name` a non-empty display name, `quantity` an integer from 1 to 99 and `unitPriceCents` the price of one unit in US cents, an integer from 0 to 500000 (the cart API validates both). All prices are in US dollars. `formatCents` in `src/money.js` formats a whole number of cents as dollars with `Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })` (`1650` gives `$16.50`). `OrderSummary.css` styles the table.

Requirements

Files touched

Review this PR

React practice