enh
This commit is contained in:
parent
ad6b525748
commit
d5a4d373ef
8 changed files with 965 additions and 201 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -418,6 +418,13 @@ Mock `useAllProducts` via `common.essentialConsts` + versioned `products.json` a
|
|||
| HOME-110 | edge | support mobile present | “Need help? Call …”; tap opens `tel:` |
|
||||
| HOME-111 | happy | tap order card | navigation target set; `replace('/(drawer)/(tabs)/me')` |
|
||||
| HOME-112 | edge | more than one order | pagination dots; scroll updates active dot |
|
||||
| HOME-113 | edge | delivery > 24h ago | excluded from the glimpse |
|
||||
| HOME-114 | edge | delivery within 24h | still shown |
|
||||
| HOME-115 | edge | scheduled order, no delivery date | excluded |
|
||||
| HOME-116 | edge | flash order, no delivery date | 1-hour promise keeps it visible |
|
||||
| HOME-117 | edge | old flash order, no delivery date | excluded |
|
||||
| HOME-118 | edge | new published version, file pending | previous catalog stays; no “Loading products...” |
|
||||
| HOME-119 | edge | background refresh fails with data present | last catalog stays; no error screen |
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -1452,6 +1459,7 @@ Covered by HOME-81..98, plus:
|
|||
| API-21 | edge | `essentialUrls` empty | shared builders used as fallback |
|
||||
| API-22 | happy | store-detail template | `{storeId}` replaced; fetched |
|
||||
| API-23 | edge | empty store-detail template | shared builder fallback |
|
||||
| API-24 | edge | version bump, new file pending | previous catalog stays; `isLoading` false, placeholder true |
|
||||
|
||||
### Region and location — `tests/lib/use-region.test.tsx`, `location-store.test.ts`
|
||||
|
||||
|
|
|
|||
|
|
@ -682,7 +682,9 @@ export default function Dashboard() {
|
|||
);
|
||||
}
|
||||
|
||||
if (error || constsError) {
|
||||
// Only take over the screen when there is nothing else to show. A failed
|
||||
// background refresh keeps the last loaded catalog on screen.
|
||||
if ((error || constsError) && products.length === 0) {
|
||||
return (
|
||||
<View style={tw`flex-1 justify-center items-center bg-gray-50`}>
|
||||
<MaterialIcons name="error-outline" size={48} color="#EF4444" />
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useEffect, useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useQuery, keepPreviousData } from '@tanstack/react-query'
|
||||
import { fetchJson } from '@/src/lib/fetch-json'
|
||||
import { trpc } from '@/src/trpc-client'
|
||||
import type { ProductPriceFlags } from '@packages/shared'
|
||||
|
|
@ -192,6 +192,9 @@ export function useAllProducts() {
|
|||
},
|
||||
staleTime: 60000, // 1 minute
|
||||
enabled: !!cacheUrl,
|
||||
// A published version bump changes the key. Keep showing the previous
|
||||
// catalog until the new file lands, then swap atomically (no blank screen).
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
|
||||
const mergedProducts = React.useMemo(() => {
|
||||
|
|
@ -248,6 +251,8 @@ export function useAvailability() {
|
|||
},
|
||||
staleTime: 60000, // 1 minute
|
||||
enabled: !!cacheUrl,
|
||||
// Keep the previous prices/flags while the new availability file loads.
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -266,6 +271,7 @@ export function useStores() {
|
|||
},
|
||||
staleTime: 60000, // 1 minute
|
||||
enabled: !!cacheUrl,
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -284,6 +290,7 @@ export function useSlots() {
|
|||
},
|
||||
staleTime: 60000, // 1 minute
|
||||
enabled: !!cacheUrl,
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -314,5 +321,6 @@ export function useStoreWithProducts(storeId: number) {
|
|||
},
|
||||
staleTime: 60000, // 1 minute
|
||||
enabled: !!cacheUrl,
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import {
|
|||
import {
|
||||
setJsonResponse,
|
||||
setJsonError,
|
||||
setJsonPending,
|
||||
jsonCalls,
|
||||
jsonCallsFor,
|
||||
} from '../mocks/fetch-json'
|
||||
|
|
@ -501,4 +502,53 @@ describe('prominent API hooks', () => {
|
|||
await waitFor(() => expect(result.current.data?.store).toBeTruthy())
|
||||
expect(jsonCallsFor(storeDetailCacheUrl(1))).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('API-24: a published version bump keeps the previous catalog on screen while the new file loads', async () => {
|
||||
let productsVersion: number = CONSTS.products_version_num
|
||||
|
||||
setProcedure('common.essentialConsts', {
|
||||
impl: () => ({
|
||||
...CONSTS,
|
||||
products_version_num: productsVersion,
|
||||
essentialUrls: buildEssentialUrls({
|
||||
assetsDomain: CONSTS.assetsDomain,
|
||||
apiCacheKey: CONSTS.apiCacheKey,
|
||||
regionId: 1,
|
||||
versions: {
|
||||
products: productsVersion,
|
||||
availability: CONSTS.availability_version_num,
|
||||
slots: CONSTS.slots_version_num,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
})
|
||||
setJsonResponse(productsCacheUrl(1, CONSTS.products_version_num), PRODUCTS_RESPONSE)
|
||||
setJsonResponse(availabilityCacheUrl(), AVAILABILITY_RESPONSE)
|
||||
|
||||
const { element, result } = makeProbe(() => {
|
||||
const consts = useGetEssentialConsts()
|
||||
const products = useAllProducts()
|
||||
return { consts, products }
|
||||
})
|
||||
renderWithProviders(element, { auth: false })
|
||||
|
||||
await waitFor(() => expect(result.current.products.data?.products).toBeTruthy())
|
||||
const loadedCount = result.current.products.data!.products.length
|
||||
|
||||
// The backend publishes the next version; its file never resolves yet.
|
||||
productsVersion += 1
|
||||
setJsonPending(productsCacheUrl(1, productsVersion))
|
||||
|
||||
await act(async () => {
|
||||
await result.current.consts.refetch()
|
||||
})
|
||||
await waitFor(() =>
|
||||
expect(jsonCallsFor(productsCacheUrl(1, productsVersion))).toHaveLength(1)
|
||||
)
|
||||
|
||||
// The old catalog is still rendered; the screen is not blanking out.
|
||||
expect(result.current.products.data?.products).toHaveLength(loadedCount)
|
||||
expect(result.current.products.isLoading).toBe(false)
|
||||
expect(result.current.products.isPlaceholderData).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/**
|
||||
* Catalogue section 6 — Home (`tests/pages/home.test.tsx`, HOME-01..112).
|
||||
* Catalogue section 6 — Home (`tests/pages/home.test.tsx`, HOME-01..119).
|
||||
*
|
||||
* Products / availability / slots / stores come from the versioned CDN documents
|
||||
* (`seedBoot`); the consts + orders come from the tRPC procedure registry. The
|
||||
|
|
@ -37,6 +37,7 @@ import { useNavigationTarget } from 'common-ui/hooks/useNavigationTarget'
|
|||
import { StorageServiceCasual, tw } from 'common-ui'
|
||||
|
||||
import { flush, renderWithProviders, seedBoot, seedSelectedAddress } from '../helpers/test-utils'
|
||||
import { buildEssentialUrls } from '@packages/shared'
|
||||
import { resetAllMocks } from '../helpers/reset'
|
||||
import {
|
||||
procedureQueryCalls,
|
||||
|
|
@ -58,6 +59,10 @@ import {
|
|||
CART_FLASH,
|
||||
CART_REG,
|
||||
CONSTS_FLASH_OFF,
|
||||
CONSTS,
|
||||
PRODUCTS_VERSION_NUM,
|
||||
AVAILABILITY_VERSION_NUM,
|
||||
SLOTS_VERSION_NUM,
|
||||
P_CHICKEN,
|
||||
SLOTS,
|
||||
SLOTS_RESPONSE,
|
||||
|
|
@ -336,6 +341,80 @@ describe('Home (HOME)', () => {
|
|||
expect(queryByText('Our Stores')).toBeNull()
|
||||
})
|
||||
|
||||
it('HOME-118: a new published version keeps the current catalog while it loads', async () => {
|
||||
let productsVersion: number = PRODUCTS_VERSION_NUM
|
||||
setProcedure('common.essentialConsts', {
|
||||
impl: () => ({
|
||||
...CONSTS,
|
||||
products_version_num: productsVersion,
|
||||
essentialUrls: buildEssentialUrls({
|
||||
assetsDomain: CONSTS.assetsDomain,
|
||||
apiCacheKey: CONSTS.apiCacheKey,
|
||||
regionId: CONSTS.regionId,
|
||||
versions: {
|
||||
products: productsVersion,
|
||||
availability: AVAILABILITY_VERSION_NUM,
|
||||
slots: SLOTS_VERSION_NUM,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
const view = await renderHome()
|
||||
await waitFor(() => expect(mainListIds(view).length).toBeGreaterThan(0))
|
||||
const before = mainListIds(view)
|
||||
|
||||
// The backend publishes the next products version; its file never resolves.
|
||||
productsVersion += 1
|
||||
setJsonPending(productsCacheUrl(1, productsVersion))
|
||||
await emitFocus()
|
||||
await waitFor(() =>
|
||||
expect(jsonCallsFor(productsCacheUrl(1, productsVersion))).toHaveLength(1)
|
||||
)
|
||||
|
||||
// The old catalog is still on screen: no full-screen loader, same rows.
|
||||
expect(view.queryByText('Loading products...')).toBeNull()
|
||||
expect(view.getByTestId('home-search')).toBeTruthy()
|
||||
expect(mainListIds(view)).toEqual(before)
|
||||
})
|
||||
|
||||
it('HOME-119: a failed background refresh keeps the last good catalog', async () => {
|
||||
let productsVersion: number = PRODUCTS_VERSION_NUM
|
||||
setProcedure('common.essentialConsts', {
|
||||
impl: () => ({
|
||||
...CONSTS,
|
||||
products_version_num: productsVersion,
|
||||
essentialUrls: buildEssentialUrls({
|
||||
assetsDomain: CONSTS.assetsDomain,
|
||||
apiCacheKey: CONSTS.apiCacheKey,
|
||||
regionId: CONSTS.regionId,
|
||||
versions: {
|
||||
products: productsVersion,
|
||||
availability: AVAILABILITY_VERSION_NUM,
|
||||
slots: SLOTS_VERSION_NUM,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
const view = await renderHome()
|
||||
await waitFor(() => expect(mainListIds(view).length).toBeGreaterThan(0))
|
||||
const before = mainListIds(view)
|
||||
|
||||
productsVersion += 1
|
||||
setJsonError(productsCacheUrl(1, productsVersion), new Error('offline'))
|
||||
await emitFocus()
|
||||
await waitFor(() =>
|
||||
expect(jsonCallsFor(productsCacheUrl(1, productsVersion)).length).toBeGreaterThan(0)
|
||||
)
|
||||
await flush(3)
|
||||
|
||||
// The background failure is not allowed to replace a usable catalog.
|
||||
expect(view.queryByText('Oops!')).toBeNull()
|
||||
expect(view.queryByText('Failed to load products')).toBeNull()
|
||||
expect(mainListIds(view)).toEqual(before)
|
||||
})
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* 6.2 Tags and product grid */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { useMemo, useEffect, useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useQuery, keepPreviousData } from '@tanstack/react-query'
|
||||
import axios from 'axios'
|
||||
import { trpc } from '../lib/trpc-client'
|
||||
import { useAuth } from '../lib/auth-context'
|
||||
|
|
@ -327,7 +327,7 @@ export function useAllProducts() {
|
|||
},
|
||||
staleTime: 60000,
|
||||
enabled: !!cacheUrl && isReady,
|
||||
placeholderData: initialData,
|
||||
placeholderData: initialData ?? keepPreviousData,
|
||||
})
|
||||
|
||||
const mergedProducts = useMemo(() => {
|
||||
|
|
@ -386,7 +386,7 @@ export function useAvailability() {
|
|||
},
|
||||
staleTime: 60000,
|
||||
enabled: !!cacheUrl && isReady,
|
||||
placeholderData: initialData,
|
||||
placeholderData: initialData ?? keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -407,7 +407,7 @@ export function useStores() {
|
|||
},
|
||||
staleTime: 60000,
|
||||
enabled: !!cacheUrl && isReady,
|
||||
placeholderData: initialData,
|
||||
placeholderData: initialData ?? keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -428,7 +428,7 @@ export function useSlots() {
|
|||
},
|
||||
staleTime: 60000,
|
||||
enabled: !!cacheUrl && isReady,
|
||||
placeholderData: initialData,
|
||||
placeholderData: initialData ?? keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -449,7 +449,7 @@ export function useBanners() {
|
|||
},
|
||||
staleTime: 60000,
|
||||
enabled: !!cacheUrl && isReady,
|
||||
placeholderData: initialData,
|
||||
placeholderData: initialData ?? keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -482,6 +482,6 @@ export function useStoreWithProducts(storeId: number) {
|
|||
},
|
||||
staleTime: 60000,
|
||||
enabled: !!cacheUrl && isReady,
|
||||
placeholderData: initialData,
|
||||
placeholderData: initialData ?? keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9820,3 +9820,53 @@ failure swallowed).
|
|||
+++ b/apps/backend/tests/unit/slot-sku-cleanup.test.ts
|
||||
+ 36h retention constant + cutoff exactness
|
||||
+ upcoming / 35h-old slots kept; exactly-36h and 37h-old slots cleared
|
||||
|
||||
[2026-10-25 10:36 IST] Home/catalog version bumps no longer blank the screen. Every versioned
|
||||
CDN query now keeps the previous result while the new version's file downloads and swaps in
|
||||
when it lands (`placeholderData: keepPreviousData`). user-ui: products/availability/stores/
|
||||
slots/store-detail; web-ui: the same six via `initialData ?? keepPreviousData` so the
|
||||
persisted placeholder still wins. Home's error screen now only takes over when there is no
|
||||
catalog to show, so a failed background refresh keeps the last good data.
|
||||
|
||||
--- a/apps/user-ui/src/hooks/prominent-api-hooks.ts
|
||||
+++ b/apps/user-ui/src/hooks/prominent-api-hooks.ts
|
||||
@@ imports
|
||||
+import { useQuery, keepPreviousData } from '@tanstack/react-query'
|
||||
@@ useAllProducts / useAvailability / useStores / useSlots / useStoreWithProducts
|
||||
+ placeholderData: keepPreviousData
|
||||
+ // new product/availability/store/slot version keeps the previous data until
|
||||
+ // the CDN file resolves; isLoading stays false (isPlaceholderData true)
|
||||
|
||||
--- a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx
|
||||
+++ b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx
|
||||
@@ error guard
|
||||
- if (error || constsError) {
|
||||
+ if ((error || constsError) && products.length === 0) {
|
||||
|
||||
--- a/apps/web-ui/src/hooks/prominent-api-hooks.ts
|
||||
+++ b/apps/web-ui/src/hooks/prominent-api-hooks.ts
|
||||
@@ imports
|
||||
+import { useQuery, keepPreviousData } from '@tanstack/react-query'
|
||||
@@ products / availability / stores / slots / banners / store detail
|
||||
- placeholderData: initialData,
|
||||
+ placeholderData: initialData ?? keepPreviousData,
|
||||
|
||||
--- a/apps/user-ui/tests/lib/prominent-api-hooks.test.tsx
|
||||
+++ b/apps/user-ui/tests/lib/prominent-api-hooks.test.tsx
|
||||
@@ new
|
||||
+ API-24: published version bump keeps the previous catalog while the new file is pending
|
||||
+ (data unchanged, isLoading false, isPlaceholderData true)
|
||||
|
||||
--- a/apps/user-ui/JEST-TEST-CASES.md
|
||||
+++ b/apps/user-ui/JEST-TEST-CASES.md
|
||||
@@ Prominent API hooks
|
||||
+ API-24 | edge | version bump, new file pending | previous catalog stays; no loading state
|
||||
|
||||
[2026-10-25 10:38 IST] Tests for the no-blank version-bump behaviour.
|
||||
- API-24 (tests/lib/prominent-api-hooks.test.tsx): products version bumps with the new CDN
|
||||
file pending; the previous catalog stays, isLoading false, isPlaceholderData true.
|
||||
- HOME-118 (tests/pages/home.test.tsx): same at the screen level -- the old rows and search
|
||||
bar remain, "Loading products..." never renders.
|
||||
- HOME-119: a failed background refresh (new version errors) keeps the last good catalog and
|
||||
does not swap to the "Oops!" screen (cold-start failures still do, pinned by HOME-02).
|
||||
- JEST-TEST-CASES.md rows HOME-113..119 added (113-117 were undocumented).
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue