freshyo/apps/user-ui/tests/home-page
2026-09-26 13:41:46 +05:30
..
home-add-to-cart-dialog.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
home-cards.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
home-floating-cart-bar.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
home-refresh.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
home-slots.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
home-states.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
home.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
navigation.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
next-order-glimpse.test.tsx test-expansion 2026-09-26 00:46:08 +05:30
README.md test-expansion 2026-09-26 00:46:08 +05:30
render.tsx user ui test automation 2026-09-26 13:41:46 +05:30

Home page tests

Jest integration tests for the user-ui home page (apps/user-ui/app/(drawer)/(tabs)/home/index.tsx) and the components it renders.

  • 9 files, 48 tests
  • Runner: jest-expo + @testing-library/react-native, config at tests/jest.config.js
  • Network is mocked at the layer (tests/mocks/api.ts); components, stores, hooks and the router wiring stay real

Run

From apps/user-ui:

NODE_ENV=test bun run test tests/home-page   # this folder
NODE_ENV=test bun run test                   # every test in the app
NODE_ENV=test bun run test:watch             # watch mode

NODE_ENV=test is required: with NODE_ENV=production React loads its production build and every render throws "act(...) is not supported in production builds of React". (Raw jest equivalent: NODE_ENV=test bunx jest --config tests/jest.config.js.)

Layout

File Tests Covers
home.test.tsx 18 Core home behaviour (mocked router)
navigation.test.tsx 3 Real expo-router navigation + params
home-states.test.tsx 5 Loading / error / empty states
home-refresh.test.tsx 2 Pull-to-refresh fan-out
home-slots.test.tsx 3 Slot card badge + labels
home-add-to-cart-dialog.test.tsx 3 Add-to-cart dialog specifics
home-floating-cart-bar.test.tsx 5 Floating cart bar (pinned products, totals, slots)
next-order-glimpse.test.tsx 5 Upcoming-order preview
home-cards.test.tsx 4 Product card / store list details
render.tsx — Shared provider stack + helpers (not a test)

Shared fixtures live in tests/mocks/ (network + router + auth + refresh) and tests/__fixtures__/. setup.ts stubs auth/refresh/storage and freezes the clock.


home.test.tsx — core home behaviour

API responses are mocked at the network layer; the tree includes the real CentralStoreInitializer so the slot/availability/product stores are populated as in the app. expo-router is mocked here.

# Test What it asserts
1 requests the products cache url derived from common.essentialConsts Fetches common.essentialConsts, then derives and requests the products CDN URL
2 shows a tab for every tag One tag-tab-* per tag, each showing its name
3 shows every product of every tag, expanding each grid once 6-item preview per tag, "Show More" reveals the rest
4 renders a tag with its out-of-stock items last Out-of-stock pushed to the end; admin order preserved within each group
5 shows the upcoming slots in delivery order First 5 upcoming slots, sorted by delivery then freeze
6 hides a slot whose freeze time has passed Expired-freeze slot absent from the home strip
7 hides a slot whose freeze time has passed in the add-to-cart dialog Expired slot not offered; a valid slot still is
8 shows the load-all button until every product is loaded products-show-more pages 21 at a time until gone
9 marks exactly the unavailable products out of stock in every tag Badge present iff the product is unavailable
10 lists the main product list with unavailable items last Mounted head of the list matches expected sort order
11 adds items to the cart Floating bar counts lines; card swaps add icon for a stepper
12 updates and removes a cart item through the card quantity stepper Increment opens update dialog; quantity changes in dialog; delete removes
13 shows the store list and navigates when a store is tapped Store row renders; tap pushes to stores + sets navigation store
14 opens the product detail page from a tag grid card Push .../product-detail/<id>
15 opens the product detail page from the main list Push .../product-detail/<id>
16 opens the slot detail page when a slot card is tapped Push .../slot-view?slotId=<id>
17 opens search from the search bar Push .../search-results
18 opens the cart from the floating bar Push .../home/cart

navigation.test.tsx — real router

Renders the actual expo-router (via expo-router/testing-library) with a route map mirroring app/, proving pushed URLs resolve and params arrive.

# Test What it asserts
1 routes to the product detail screen carrying the id Pathname /home/product-detail/<id>, id param delivered
2 routes to the slot view carrying the slotId Pathname /home/slot-view, slotId search param delivered
3 routes to the stores screen Pathname /stores, stores stub visible

home-states.test.tsx — page states

# Test What it asserts
1 shows the loading screen while the products request is pending "Loading products..." while the products request never resolves
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 "Oops!" + "Failed to load app settings"
4 shows the empty state when there are no products "No products available" (list empty component)
5 shows the empty-category message for a tag with no products "No products in this category yet" for an empty tag

home-refresh.test.tsx — refresh

handleRefresh fans out to products, slots, stores and essentialConsts. Availability is intentionally not asserted (it is not refetched).

# Test What it asserts
1 refetches every data source through useManualRefresh Each URL requested again after the manual-refresh callback fires
2 refetches every data source through useMarkDataFetchers Same, via the mark-data-fetchers callback

home-slots.test.tsx — slot card details

# Test What it asserts
1 marks only the slots closing within 4 hours "CLOSING SOON" iff freeze is within 4h (both branches exercised)
2 labels each slot with its delivery range and order-by time Delivery range, order-by clock time, date line
3 shows how many products each slot holds "View all N items" matches the slot's product count

home-add-to-cart-dialog.test.tsx — add-to-cart dialog

# Test What it asserts
1 offers flash delivery and routes to the flash cart when enabled Flash row shown (flash enabled + SKU flash-available); confirm pushes the flash cart
2 keeps confirm disabled until a delivery option is chosen Confirm disabled with no slot selected
3 pre-selects the cart quantity when reopened from the card stepper Update mode shows the current cart quantity

home-floating-cart-bar.test.tsx — floating cart bar

Uses two pinned products with exact fixture prices so every money and slot expectation is a fixed number: 2 "Chicken Breast 500 g" (₹215) and 40 "Chicken regular cut Large pieces" (₹129), both in the "Chicken" tag. A single expanded grid holds them; the free-delivery threshold is ₹249.

# Test What it asserts
1 adds exactly the pinned products and tracks the total and delivery threshold ₹215 → "₹34 more for FREE Delivery"; +₹129 → ₹344 • 2 Items → "Free Delivery Unlocked"
2 places each pinned product in the first open slot it belongs to Each line shows its slot label (both resolve to slot 1849)
3 recomputes the total when the quantity changes Quantity 1 → 2 moves the total ₹215 → ₹430 (still one line)
4 expands into the cart dialog with the line and the subtotal "Your Cart" dialog shows the item and Subtotal
5 re-slots a stored cart item whose slot no longer exists useReconcileCartSlots rewrites the invalid slotId to a real slot

next-order-glimpse.test.tsx — upcoming order preview

# Test What it asserts
1 renders nothing and never requests orders when signed out No "Upcoming Order"; user.order.getOrders not requested
2 previews an upcoming order Order id, "N items • ₹total", status label (pending → "Confirmed")
3 flags a flash order "FLASH" badge + "30-Min Delivery"
4 ignores cancelled and completed orders Cancelled / successful orders produce no preview
5 routes to my-orders when a card is tapped router.replace('/(drawer)/(tabs)/me')

home-cards.test.tsx — card / list details

# Test What it asserts
1 never renders a combo-only SKU Combo-only SKU (149) absent from the main list and every tag grid
2 renders every store with the leading "The " stripped All stores render; The prefix removed from the display name
3 strikes through the market price when it is above the selling price Market price shown when greater than the selling price
4 shows a fallback when a product image fails to load "Image failed to load" after an image error