# user-ui — test case info Every test case for the user-ui app, grouped by file with the API expectation each one locks in. Companion to `tests/home-page/README.md` (long-form home-page detail). - **Runner**: `jest-expo` + `@testing-library/react-native` - **Total**: **66 suites / 347 tests** (counted from the files after the region-test sync; not re-run in that pass) - Per-group counts below are counted from the files (`it`/`test` lines); jest expands `it.each` cases, so a run reports a few more than the sum of these tables. - Network is mocked at the layer (`tests/mocks/api.ts`); components, stores, hooks and the router stay real. ## Run From `apps/user-ui`: ```bash NODE_ENV=test bun run test # everything NODE_ENV=test bun run test tests/screens # one folder NODE_ENV=test bun run test:watch # watch bun run test:typecheck # tsc over app + tests ``` `NODE_ENV=test` is required (production React rejects `act`). ## Conventions - **API expectation**: any button that triggers a network call has a case asserting it — `expectProcedureCalled(fetchMock, '')`, `lastProcedureInput` for the payload, or the axios mock's call history for CDN files. - **Router**: `tests/mocks/router.ts` spies; real-router flows use `tests/helpers/real-router.tsx` in files that do **not** mock expo-router. - **State**: zustand stores are module singletons — reset them in `beforeEach`. --- # home-page (`tests/home-page/`) — 48 ### `home.test.tsx` — 18 | # | Test | Asserts | | --- | --- | --- | | 1 | requests the products cache url derived from common.essentialConsts | `common.essentialConsts` fetched, then the CDN products URL | | 2 | shows a tab for every tag | one `tag-tab-*` per tag with its name | | 3 | shows every product of every tag, expanding each grid once | 6-item preview then Show More reveals the rest | | 4 | renders a tag with its out-of-stock items last | out-of-stock pushed last, admin order kept within groups | | 5 | shows the upcoming slots in delivery order | first 5 upcoming slots, delivery then freeze sort | | 6 | hides a slot whose freeze time has passed | expired-freeze slot absent from the strip | | 7 | hides a slot whose freeze time has passed in the add-to-cart dialog | expired slot not offered, a valid one still is | | 8 | shows the load-all button until every product is loaded | `products-show-more` pages 21 at a time | | 9 | marks exactly the unavailable products out of stock in every tag | badge present iff unavailable | | 10 | lists the main product list with unavailable items last | mounted head matches the expected order | | 11 | adds items to the cart | bar counts lines; card swaps to a stepper | | 12 | updates and removes a cart item through the card quantity stepper | dialog update mode, quantity change, delete | | 13 | shows the store list and navigates when a store is tapped | push `…/stores` + navigationStore flags | | 14 | opens the product detail page from a tag grid card | push `…/product-detail/` | | 15 | opens the product detail page from the main list | push `…/product-detail/` | | 16 | opens the slot detail page when a slot card is tapped | push `…/slot-view?slotId=` | | 17 | opens search from the search bar | push `…/search-results` | | 18 | opens the cart from the floating bar | push `…/home/cart` | ### `navigation.test.tsx` — 3 (real router) | # | Test | Asserts | | --- | --- | --- | | 1 | routes to the product detail screen carrying the id | pathname + `id` param delivered | | 2 | routes to the slot view carrying the slotId | `/home/slot-view` + `slotId` param | | 3 | routes to the stores screen | `/stores` stub visible | ### `home-states.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | shows the loading screen while the products request is pending | "Loading products..." | | 2 | shows the products error state when the products request fails | "Oops!" + "Failed to load products" | | 3 | shows the app-settings error state when essentialConsts fails | "Failed to load app settings" | | 4 | shows the empty state when there are no products | "No products available" | | 5 | shows the empty-category message for a tag with no products | "No products in this category yet" | ### `home-refresh.test.tsx` — 2 | # | Test | Asserts | | --- | --- | --- | | 1 | refetches every data source through useManualRefresh | products/stores/slots/consts URLs requested again | | 2 | refetches every data source through useMarkDataFetchers | same, via the mark-data-fetchers callback | ### `home-slots.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | marks only the slots closing within 4 hours | CLOSING SOON iff freeze < 4h (both branches) | | 2 | labels each slot with its delivery range and order-by time | delivery range, order-by clock, date line | | 3 | shows how many products each slot holds | "View all N items" | ### `home-add-to-cart-dialog.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | offers flash delivery and routes to the flash cart when enabled | flash row shown; confirm pushes the flash cart | | 2 | keeps confirm disabled until a delivery option is chosen | disabled CTA | | 3 | pre-selects the cart quantity when reopened from the card stepper | Update Item + current quantity | ### `home-floating-cart-bar.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | adds exactly the pinned products and tracks the total and delivery threshold | ₹215 → "₹34 more"; +₹129 → ₹344 • 2 Items → Unlocked | | 2 | places each pinned product in the first open slot it belongs to | one slot label per line | | 3 | recomputes the total when the quantity changes | ₹215 → ₹430, still one line | | 4 | expands into the cart dialog with the line and the subtotal | "Your Cart" + Subtotal | | 5 | re-slots a stored cart item whose slot no longer exists | `useReconcileCartSlots` rewrites the slotId | ### `next-order-glimpse.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | renders nothing and never requests orders when signed out | no preview; `user.order.getOrders` not called | | 2 | previews an upcoming order | id, "N items • ₹total", status label | | 3 | flags a flash order | FLASH + "30-Min Delivery" | | 4 | ignores cancelled and completed orders | no preview | | 5 | routes to my-orders when a card is tapped | `router.replace('…/me')` | ### `home-cards.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | never renders a combo-only SKU | id 149 absent everywhere | | 2 | renders every store with the leading "The " stripped | all stores + name normalisation | | 3 | strikes through the market price when it is above the selling price | market price shown | | 4 | shows a fallback when a product image fails to load | "Image failed to load" | --- # screens (`tests/screens/`) — 133 ### `auth.test.tsx` — 9 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the mobile step with the submit button | mobile input + CTA | | 2 | rejects an invalid mobile number without calling the API | validation error, no `user.auth.sendOtp` | | 3 | sends an OTP and moves to the OTP step | `user.auth.sendOtp` called → OTP step | | 4 | verifies the OTP and hands the token to the auth context | `user.auth.verifyOtp` → `loginWithToken('tok', user)` | | 5 | logs in with identifier + password via the password path | `user.auth.login` → `loginWithToken` | | 6 | opens the terms dialog from the terms link | dialog visible | | 7 | renders the registration form and links to sign in | `router.push('/(auth)/login')` | | 8 | shows a spinner while the session is loading | auth layout spinner | | 9 | renders the stack once loading finishes | no spinner | ### `navigation-shell.test.tsx` — 2 (real router) | # | Test | Asserts | | --- | --- | --- | | 1 | redirects to the home route once auth has settled | pathname `/home` | | 2 | stays on the entry route and shows a spinner while auth loads | spinner, pathname `/` | ### `flash-gate.test.tsx` — 2 | # | Test | Asserts | | --- | --- | --- | | 1 | shows the unavailable screen and routes home when disabled | unavailable copy + `router.replace('…/home')` | | 2 | renders the slot content when enabled | `common.essentialConsts` fetched, no gate | ### `stores.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | lists every store with its product count | all names + one Explore Store each | | 2 | navigates to a store detail when Explore Store is pressed | push `…/store-detail/` | | 3 | deep-links to the store chosen on the home page and clears the flag | focus effect push + flags cleared | | 4 | shows the error state and refetches on Retry | "Store Fetch Failed" → `stores.json` re-requested | | 5 | shows the empty state when there are no stores | "No Stores Available" | ### `store-detail.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the store, its tags and products | store meta + "Chicken (3)" + cards | | 2 | filters by tag and clears the filter | "Chicken items" → Clear → "N products" | | 3 | navigates to a product detail when a card is pressed | push `…/product-detail/` | | 4 | shows the error state when the store cannot be loaded | store-not-found copy | ### `search.test.tsx` — 6 | # | Test | Asserts | | --- | --- | --- | | 1 | lists all products when the query is empty | "All Products" + cards | | 2 | filters products by the debounced query | 300ms debounce → filtered header + fewer cards | | 3 | shows the no-results state for an unmatched query | "No products found" + hint | | 4 | restores all products when the query is cleared | header back to "All Products" | | 5 | shows the loading state while products are pending | "Loading products..." | | 6 | opens the product detail page when a card is pressed | push `…/product-detail/` | ### `order-again.test.tsx` — 6 | # | Test | Asserts | | --- | --- | --- | | 1 | renders both section headers | Offers + Combos | | 2 | shows the empty message for a section with no products | "No offers available right now" | | 3 | renders a card for every combo | ≥1 card | | 4 | opens the product detail page when a card is pressed | push `…/order-again/product-detail/` | | 5 | shows the loading state while products are pending | "Loading offers..." | | 6 | shows the error state when products fail to load | "Oops!" + "Failed to load offers" | ### `slot-view.test.tsx` — 8 | # | Test | Asserts | | --- | --- | --- | | 1 | shows the loading state while slots load | "Loading slot delivery..." | | 2 | shows the error state when slots fail | "Failed to load slot delivery" | | 3 | shows the no-slot state for an unknown slot id | "No delivery slot available." | | 4 | lists the slot products and navigates on press | cards + push product-detail | | 5 | shows the empty message when a store has no products in the slot | store-filter copy | | 6 | lists flash-available in-stock products | flash filter | | 7 | filters products by the search box | no-results copy | | 8 | shows the empty message when there are no products | "No 1 Hr Delivery products available." | ### `cart-screen.test.tsx` — 11 Signed in by default (login wall when signed out; first-address gate when there are no addresses). | # | Test | Asserts | | --- | --- | --- | | 1 | shows the empty state and Start Shopping navigates home | push `…/home` | | 2 | renders the seeded line, the bill and queries the cart slots | bill ₹230 + `user.cart.getCartSlots` input `{productIds:[2]}` | | 3 | queries eligible coupons only when authenticated | `user.coupon.getEligible` + Offers & Coupons | | 4 | navigates to checkout with the selected slot | push `…/home/checkout` | | 5 | shows an enabled merge row when every item can use the majority slot | `delivery-slot-merge` → apply → hidden | | 6 | hides the merge row when one item cannot use the majority slot | no merge row | | 7 | hides the merge row when only one slot is selected | no merge row | | 8 | renders the flash cart variant without slot selection | "1 Hr Delivery Cart" | | 9 | shows the login wall when signed out | "Please log in" + "Log In"; no cart line | | 10 | shows the add-address gate before the cart when the user has no addresses | "Where should we deliver?" + `cart-address-other`; cart line hidden | | 11 | shows the add-address gate even when the cart is empty | gate, not "Your cart is empty" | ### `cart-coupons.test.tsx` — 12 (coupon application + discount calculation) Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryCharge 15. | # | Test | Asserts | | --- | --- | --- | | 1 | shows the item total and free delivery before a coupon is applied | no `Product Discount` row, "Free" | | 2 | offers the coupon with its computed saving | option label carries `Save ₹43` (10% of 430) | | 3 | applies a percentage discount and shows the applied code | `Product Discount -₹43`, `Coupon Applied SAVE10`, To Pay ₹387 | | 4 | caps a percentage discount at maxValue | 50% of 430 = 215 capped to `-₹50`, ₹380 | | 5 | applies a flat discount | `-₹100`, ₹330 | | 6 | caps a flat discount at the item total | flat 1000 on a 430 cart → `-₹430` (never negative) | | 7 | re-adds the delivery fee when the discount drops the total below the threshold | 430 − 200 = 230 < 249 → ₹245, no "Free" | | 8 | removes the coupon and the discount again | `Remove coupon` → both rows gone | | 9 | lists a min-order coupon as ineligible and does not apply it | label carries `Min order ₹1000`; pressing it applies nothing | | 10 | hides a coupon that has hit its per-user usage limit | "No coupons available" + empty copy | | 11 | drops the discount when a quantity change takes the cart below the minOrder | select a minOrder-300 coupon at ₹430, decrement to ₹215 → discount gone (`cart-item-1-decrement` / `-value`) | | 12 | sends the selected coupon id to checkout | push URL contains `&coupons=77` | ### `checkout-crash.test.tsx` — 4 (checkout guards + the resolved bill) The last case is the regression guard for the Rules-of-Hooks crash that used to make the screen unrenderable: it asserted the thrown error until the hooks were moved above the guard, and now asserts the bill instead. | # | Test | Asserts | | --- | --- | --- | | 1 | asks for delivery slots when the cart lines have none | "No items to checkout" + "Please select delivery slots for your items" | | 2 | reports flash-unavailable lines on the flash checkout | "None of your cart items are available for flash delivery" | | 3 | shows the empty-cart state when there is nothing to pay for | "Your cart is empty" | | 4 | renders the bill once the cart resolves to slotted items | header + Item Total ₹215 + To Pay ₹230, no discount (used to throw) | ### `checkout-coupons.test.tsx` — 10 (coupon application + discount calculation) Cart: 2 x product 2 @ 215 = 430. Consts: freeDeliveryThreshold 249, deliveryCharge 15. | # | Test | Asserts | | --- | --- | --- | | 1 | applies a percentage discount to the item total | `-₹43`, To Pay ₹387, "Free", "You saved ₹68 on this order" | | 2 | caps a percentage discount at maxValue | 50% of 430 = 215 capped to `-₹50`, ₹380 | | 3 | applies a flat discount | `-₹100`, ₹330 | | 4 | caps a flat discount at maxValue | `-₹150`, ₹280 | | 5 | never discounts below zero — capped at the item total | flat 1000 on a 430 cart → `-₹430` | | 6 | charges delivery again when the discount drops the total below the threshold | 430 − 200 = 230 < 249 → ₹245 + "Add products worth ₹19 for free delivery" | | 7 | does not apply a coupon whose minOrder is not met, even from the URL | no `Product Discount` row, "Free" | | 8 | ignores a coupon that has hit its per-user usage limit | no `Product Discount` row | | 9 | shows no discount when the URL carries no coupon | no `Product Discount`, "Free" | | 10 | sends the selected coupon id with the order | `placeOrder` payload `couponId: 77`; `replace('…totalAmount=387')` | ### `checkout.test.tsx` — 2 | # | Test | Asserts | | --- | --- | --- | | 1 | shows the empty-cart state and goes back | "Your cart is empty" + `router.back` | | 2 | redirects to login when unauthenticated | `router.push('/(auth)/login')` | ### `product-detail-routes.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | home route renders ProductDetail with the id | `7:regular` | | 2 | stores route renders ProductDetail | id passed | | 3 | order-again route renders ProductDetail | id passed | | 4 | flash route renders ProductDetail | id passed | ### `order-success.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the confirmation and performs both actions | `dismissTo` + `dismissAll` + push my-orders | | 2 | shows the order id and total when params are present | "Order #ORD-9" + "Total: ₹500" | | 3 | renders the confirmation actions | flash variant CTAs | ### `me-hub.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the account sections and menu entries | My Account + entries | | 2 | navigates to the orders screen | push `…/me/my-orders` | | 3 | navigates to addresses | push `…/me/addresses` | | 4 | logs out from the footer button | `logout` called | ### `me-orders.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the fetched orders | `user.order.getOrders` + row | | 2 | navigates to the order detail when a row is pressed | push `…/my-orders/11` | | 3 | shows the empty state and Start Shopping navigates home | push `…/home` | | 4 | shows the error state and retries | error copy + `getOrders` re-requested | | 5 | retries payment through user.payment.createRazorpayOrder | procedure called | ### `order-detail.test.tsx` — 6 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the order, its items and the total | `user.order.getOrderById` + total | | 2 | shows the error state and goes back | `router.back` | | 3 | saves special instructions via user.order.updateUserNotes | `{id, userNotes}` | | 4 | requires a reason before cancelling | alert, no `cancelOrder` | | 5 | cancels the order with a reason via user.order.cancelOrder | `{id, reason}` | | 6 | opens the complaint form | complaint textarea visible | ### `me-account.test.tsx` — 16 | # | Test | Asserts | | --- | --- | --- | | 1 | lists the addresses and singles out the default | cards + Set Default | | 2 | shows the empty state with an Add Address action | empty copy | | 3 | shows the error state and retries | `user.address.getUserAddresses` re-requested | | 4 | marks an address as default via user.address.updateAddress | `{id, isDefault: true}` | | 5 | deletes an address after confirming via user.address.deleteAddress | `{id}` | | 6 | renders personal and general sections | SAVE20 + both sections | | 7 | redeems a code via user.coupon.redeemReservedCoupon | `{secretCode: 'SECRET1'}` | | 8 | shows the empty sections when there are no coupons | both empty copies | | 9 | renders complaints and support contacts | item + Pending + Need Help? | | 10 | opens the dialer from Call Us | `Linking.openURL('tel:…')` | | 11 | shows the empty state and Continue Shopping navigates home | push `…/home` | | 12 | shows the error state | "Failed to load complaints" | | 13 | renders the profile form and logs out | `logout` called | | 14 | requires a mobile number before deleting the account | alert, no `deleteAccount` | | 15 | deletes the account via user.auth.deleteAccount | `{mobile}` | | 16 | renders the policy and goes back | terms content | --- # components (`tests/components/`) — 70 ### `product-card.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the name, price, struck market price and unit | all four | | 2 | shows the out-of-stock overlay when unavailable | badge | | 3 | queues the product when the add icon is pressed (dialog mode) | `cartStore.addedToCartProduct` | | 4 | shows the image-error fallback | "Image failed to load" | | 5 | calls onPress when the card is tapped | callback | ### `product-detail.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | shows the loading state | "Loading product details..." | | 2 | renders the product and loads its reviews | `getProductDetails{id}` + `getProductReviews` + flash badge | | 3 | shows the error state when the product fails to load | "Product not found or error loading" | | 4 | queues the add-to-cart dialog from the Add to Cart button | `cartStore.addedToCartProduct` | ### `payment-and-order.test.tsx` — 6 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the bill and an enabled Place Order button | Bill Details + ₹230 + enabled | | 2 | blocks ordering without an address | error banner + disabled CTA | | 3 | places a COD order and redirects to order success, clearing the cart | `placeOrder` payload, `replace('…order-success…')`, cart cleared | | 4 | shows an error when placing the order fails | alert | | 5 | renders the product discount and the savings banner when a coupon is applied | `Product Discount -₹43`, ₹387, "You saved ₹58 on this order" | | 6 | sends the selected coupon id with the order | `placeOrder` payload `couponId: 77` | ### `order-menu.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | navigates to the order details | push `…/my-orders/42` | | 2 | saves edited instructions via user.order.updateUserNotes | `{id, userNotes}` | | 3 | requires a reason before cancelling | alert, no `cancelOrder` | | 4 | cancels the order with a reason via user.order.cancelOrder | `{id, reason}` | ### `complaint-form.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | renders nothing when closed | null tree | | 2 | rejects an empty complaint without calling the API | alert, no `complaint.raise` | | 3 | raises a complaint with the typed body and closes | `{orderId, complaintBody, imageUrls: []}` + close | ### `registration-form.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the registration fields | Create Account + name field | | 2 | blocks submit with a validation error | "Name is required" | | 3 | rejects mismatched passwords | "Passwords do not match" | | 4 | submits the normalised register payload | trimmed/lowercased payload | | 5 | updates the password in edit mode via user.auth.updatePassword | `{password}` | ### `address-form.test.tsx` — 6 Coordinates are mandatory, so most cases seed the device location (`useLocationStore`) before rendering. | # | Test | Asserts | | --- | --- | --- | | 1 | renders the add-address form without a service-area notice | title + name field; no "We currently serve" | | 2 | keeps Add Address disabled until a location is attached | disabled CTA + "Attach a location to add address" after the first field is touched | | 3 | shows the device-source heading once a location is attached | "Current Location Attached" + "Choose Another Location in Map" | | 4 | validates the required fields | name/phone/line1 errors | | 5 | creates an address with the region and coordinates derived from the location | `createAddress` payload carries `regionId`, `latitude`/`longitude` and the City name | | 6 | updates an address in edit mode via user.address.updateAddress | `{id, regionId}` | ### `address-selectors.test.tsx` — 6 | # | Test | Asserts | | --- | --- | --- | | 1 | lists the addresses and auto-selects the default | both cards + `onAddressSelect(2)` | | 2 | selects an address on press | `onAddressSelect(1)` | | 3 | refreshes the addresses after attaching the current location | `updateAddress` gets the mocked coords, then `getUserAddresses` is fetched a **second** time (fails with the old dotted-string invalidation) | | 4 | shows the empty state | empty copy + Add Address | | 5 | shows the earliest slot and changes it from the dialog | slot options → `onSlotChange` | | 6 | shows the flash header variant | "Delivery in within 1 hour" | ### `location-attacher.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | attaches the current location on success | `onLocationChange(coords)` + attached badge | | 2 | shows an error when permission is denied | error copy, no callback | | 3 | does nothing while disabled | no permission request | ### `location-wrapper.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | renders its children once a region is selected | passthrough | | 2 | shows a spinner while the region is still resolving | "Finding your region..." | | 3 | asks for an address with a location notice when the location is denied | chooser + "Location access is not granted..." + `open-location-settings` | ### `cart-address-gate.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | offers the current-location and map options | both option cards; current enabled with a device fix | | 2 | disables the current-location option without a device fix | disabled card + "Turn on location to use this option" | | 3 | opens the address form from the map option | `address-name` visible | ### `slot-layout.test.tsx` — 2 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the delivery-time selector and the cart bar | Delivery Time + No Items In Cart | | 2 | renders the flash variant header | flash header copy | ### `wrappers.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | renders children when the backend is healthy | `common.healthCheck` ok | | 2 | shows the service-unavailable state and retries | error copy + `healthCheck` re-requested | | 3 | prompts to update when the backend version is ahead | "Update Available" | | 4 | renders children and does not check for updates on dev builds | UpdateChecker inert | ### `static-components.test.tsx` — 10 | # | Test | Asserts | | --- | --- | --- | | 1 | renders the full policy with the title by default | title + sections | | 2 | hides the title when showTitle is false | no title | | 3 | renders the notice and dismisses via the close button | notice visible | | 4 | auto-hides after the delay | timer removes it | | 5 | renders the testing-phase bullets | bullets | | 6 | renders its children | TabLayoutWrapper | | 7 | shows the welcome screen once, then the children after Next | first-run gate | | 8 | renders children when there is no webview html | children | | 9 | renders the webview when the server provides html | mock webview | | 10 | shows the exit confirmation on the home screen and swallows the event | alert + returns true | ### `icons.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1–5 | %s renders focused and unfocused (Home, Cart, Stores, Offers, Me) | each icon renders in both states | --- # hooks / stores / lib / contexts — 90 (hooks 40, stores 23, contexts 14, lib 13) ### `hooks/cart-query-hooks.test.tsx` — 6 | # | Test | Asserts | | --- | --- | --- | | 1 | adds an item to the regular cart | `cart_items` line written | | 2 | keeps the flash cart separate from the regular cart | flash key only | | 3 | increments the quantity of an item already in the cart | qty 1 → 3 | | 4 | updates and removes a cart line | qty → 4, then removed | | 5 | derives cart items and the total from the central stores | subtotal/total/totalItems | | 6 | clears the local cart | `clearLocalCart` empties | ### `hooks/prominent-api-hooks.test.tsx` — 6 | # | Test | Asserts | | --- | --- | --- | | 1 | exposes essentialConsts from the trpc procedure | threshold 249 | | 2 | derives the products cache url and merges availability | products + availability URLs, price/marketPrice | | 3 | derives the stores cache url | stores URL | | 4 | derives the slots cache url | slots URL | | 5 | fetches a single store detail | `stores/1.json` + store.id | | 6 | propagates a products fetch error | error surfaced | ### `hooks/useUploadToObjectStore.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | requests presigned urls and PUTs every image | `common.generateUploadUrls` + 2 PUTs + keys | | 2 | short-circuits when there are no images | empty result, no request | | 3 | fails when the URL count does not match the image count | throws | ### `hooks/useAuthenticatedRoute.test.tsx` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | redirects an unauthenticated user to login | `router.push('/(auth)/login')` | | 2 | does not redirect an authenticated user | no push | | 3 | does not redirect while auth is still loading | no push | ### `hooks/useProductSlotIdentifier.test.tsx` — 5 | # | Test | Asserts | | --- | --- | --- | | 1 | returns the id of the earliest upcoming slot for a product | slot 11 | | 2 | ignores slots whose delivery is already past | slot 2 | | 3 | returns null when the product has no slots | null | | 4 | returns null when there are no slots at all | null | | 5 | returns null when every slot for the product is in the past | null | ### `hooks/useJWT.test.ts` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | stores, reads and deletes the auth token | token round-trip | | 2 | stores and reads the user id | userId round-trip | | 3 | exposes the storage keys | `authToken` / `userId` | ### `hooks/useHideTabNav.test.tsx` — 2 | # | Test | Asserts | | --- | --- | --- | | 1 | marks the tab bar hidden for the caller key on focus | `hideTabsNav.cart` | | 2 | defaults the caller key when none is given | `hideTabsNav.default` | ### `hooks/useColorScheme.test.tsx` — 1 | # | Test | Asserts | | --- | --- | --- | | 1 | returns the platform colour scheme | null/light/dark | ### `stores/stores.test.ts` — 11 | # | Test | Asserts | | --- | --- | --- | | 1 | appStore tracks tab-bar visibility per caller | set key true/false | | 2 | addressStore holds the selected checkout address | 7 | | 3 | cartStore queues and clears the add-to-cart product | queue/clear | | 4 | flashCartStore queues and clears the flash product | queue/clear | | 5 | navigationStore tracks the from-home flag and selected store | flags | | 6 | quickDeliveryStore holds the selected slot | 1849 | | 7 | storeHeaderStore holds the screen title | title | | 8 | slotStore holds the quick-delivery slot and store | ids | | 9 | flashNavigationStore flags navigation back to the cart and resets | flag + reset | | 10 | centralProductStore indexes products by id | productsById | | 11 | centralSlotStore builds productSlotsMap from slots + availability | map + flags | ### `stores/region-store.test.ts` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | stores the selected region and bound and bumps the generation | id/region/bound + generation 1 | | 2 | does not bump the generation for an identical selection | generation stays 1 | | 3 | clears the region and bumps the generation | nulls + generation 2 | | 4 | is memory-only (no persist middleware) | `persist` undefined | ### `lib/string-manipulators.test.ts` — 3 | # | Test | Asserts | | --- | --- | --- | | 1 | maps pending to the user-facing "Confirmed" | mapping | | 2 | is case-insensitive | PENDING/Pending | | 3 | passes every other status through unchanged | packaged/success/cancelled/'' | ### `lib/pending-address.test.ts` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | round-trips a signed-out draft | save → get equals the draft | | 2 | returns null when there is no draft | null | | 3 | clears the draft | null after clear | | 4 | returns null for corrupt stored JSON | null | ### `lib/trpc-client.test.ts` — 2 | # | Test | Asserts | | --- | --- | --- | | 1 | emits the force-logout event on a 401 UNAUTHORIZED response | `FORCE_LOGOUT_EVENT` | | 2 | does not emit the force-logout event on a 500 response | no emit | ### `lib/query-invalidation-keys.test.tsx` — 1 | # | Test | Asserts | | --- | --- | --- | | 1 | matches the array path form and ignores the dotted string form | the stored key is `[['user','address','getUserAddresses'], {type}]`; `findAll({queryKey:['user.address.getUserAddresses']})` matches 0, the array form matches 1 (pins the stale-data bug in `CheckoutAddressSelector`) | ### `contexts/auth-context.test.tsx` — 4 | # | Test | Asserts | | --- | --- | --- | | 1 | settles to a signed-out state when there is no stored token | `false|false|none` | | 2 | loginWithToken persists the token and authenticates | token stored + `true|false|5` | | 3 | logout clears the session and the stored token | signed out + token null | | 4 | useAuth throws outside an AuthProvider | throws | --- ## Not covered Thin/global shells only: `app/_layout.tsx`, `(drawer)/_layout.tsx`, the per-route `_layout.tsx` files, and `services/notif-service`. **Coupon discount on the checkout page.** FIXED in this pass. `components/checkout-page.tsx` used to call `trpc.user.coupon.getEligible.useQuery` and four `useMemo`s *after* its `if (selectedItems.length === 0) return …` guard, so the hook count changed (4 → 9) as soon as `useGetCart` resolved from `[]` to slotted lines and React threw *"Rendered more hooks than during the previous render."* — the screen could not render at all with slotted items. The hooks now sit above the guard, so the `?coupons=` path is reachable and covered by `checkout-coupons.test.tsx` (10 cases). Eligibility is honoured on both sides — the `selectedCoupons` memo in each page filters on `isEligible`, so a coupon the cart cannot use is ignored rather than silently discounted (including one that drifts out of eligibility after selection, covered by `cart-coupons.test.tsx` case 11). If you mount this page in a test without an error boundary and it ever throws again, the runner wedges instead of failing (no output, ~0% CPU, no jest timeout); wrap it as `checkout-crash.test.tsx` does. Suites added alongside the parallel review — `cart-money`, `cart-storage`, `order-amounts`, `product-detail-flash-flag`, `payment-and-order-money`, `force-logout`, `store-staleness`, `auth-lifecycle` — are documented case-by-case in `tests/KNOWN-GAPS.md`; they are included in the totals above but not yet in the per-suite tables below. ## Harness reference | Path | Purpose | | --- | --- | | `tests/setup.ts` | Global stubs: axios, native modules (webview/updates/linking/location/notifications/razorpay/secure-store), `@react-navigation/native` focus, auth, storage, refresh hooks; frozen clock | | `tests/mocks/api.ts` | axios CDN + tRPC stubs; `setupApiMocks({ procedures, products, stores, storeProducts, consts, orders, fail*, pending* })` | | `tests/mocks/procedures.ts` | `expectProcedureCalled` / `procedureCalls` / `lastProcedureInput` (query + body inputs) | | `tests/mocks/router.ts` | Mocked expo-router + `routerMock` spies + `searchParamsMock` | | `tests/mocks/auth.ts` | Overridable auth mock + spies | | `tests/mocks/native.ts` | Native module stubs | | `tests/helpers/render.tsx` | `Providers` + `renderWithProviders` | | `tests/helpers/real-router.tsx` | `renderRoute` (real expo-router) |