freshyo/apps/admin-ui/tests/BUGS.md
2026-10-01 00:33:03 +05:30

242 lines
9.1 KiB
Markdown

# Known bugs — apps/admin-ui
Found while writing the integration test suite (`tests/`). Each entry names the
file and line, what the code does, what was expected, and the evidence. Severity
is my judgement of user impact.
---
## High — user-facing breakage
### 1. Add Product / Add Variant crashes (Formik empty-string normalisation)
`src/components/ProductForm.tsx:80`
```ts
const variantSignature = (attributes: Attribute[]): string =>
attributes
.map((a) => `${(a.featureName ?? '').trim().toLowerCase()}::${a.featureValue.trim().toLowerCase()}`)
```
`featureName` is guarded, `featureValue` is not. Formik's `validateYupSchema`
normalises empty strings to `undefined` before running Yup, so the `variants`
`unique-variants` `.test()` receives attributes whose `featureValue` is
`undefined` (`defaultAttribute`/`quantityAttribute` both start as `''`) and
`a.featureValue.trim()` throws `TypeError`.
**Impact:** every keystroke on the Add Product form (validation runs on change)
and the "Add Variant" / "Add Feature" buttons throw. Creating a product is
unusable. Editing only works when the fetched SKUs already have non-empty
feature values.
**Expected:** `(a.featureValue ?? '').trim()`.
**Pinned by:** `tests/components/product-form.test.tsx`,
`tests/screens/products-add.test.tsx`.
### 2. Coupon code list crashes on validation
`src/components/CouponForm.tsx:68`
```ts
const codes = (value.couponCodes || []).map((c: string) => c.trim()).filter(Boolean);
```
The sibling `codes-required` test on line 61 guards with `c && c.trim()`; this
one does not. Formik normalises the default `couponCodes: ['']` to `[undefined]`,
so `c.trim()` throws.
**Impact:** toggling "Is Reserved Coupon", switching discount type, "+ Add Code",
or selecting a user (`setFieldValue`) crashes the coupon form.
**Expected:** `(c || '').trim()` or filter first.
**Pinned by:** `tests/components/coupon-form.test.tsx`.
### 3. Prices Overview saves the SKU id as the product id
`app/(drawer)/dashboard/prices-overview/index.tsx:270` (and `:276`)
```ts
const update: any = { productId: sku?.id };
```
`pendingChanges` is keyed by SKU id and `sku` is resolved from `allSkus`, so the
payload carries a **SKU** id. The backend `admin.product.updateProductPrices`
resolves `productId` against `productInfo.id` (`apps/backend/.../product.ts:436`
→ `packages/db_helper_*/src/admin-apis/product.ts`), so it throws
`Invalid product IDs: ...` for every row.
**Expected:** send the SKU's parent product id (`sku.productId`).
**Pinned by:** `tests/screens/prices-overview.test.tsx`.
### 4. Product Groupings save SKU ids as product ids
`components/ProductGroupForm.tsx:44,119` + `components/ProductsSelector.tsx:117`
`ProductsSelector` emits `value: sku.id` (a SKU id) and the form forwards it as
`product_ids`. `createProductGroup` / `updateProductGroup` insert those into
`product_group_membership.productId`, which FKs `productInfo.id`. Create and
edit are also inconsistent: edit seeds `group.products.map(p => p.id)` (product
ids).
**Expected:** emit/insert product ids.
**Pinned by:** `tests/components/product-group-form.test.tsx`.
### 5. "Popular Items" add silently drops the selected product
`app/(drawer)/dashboard/customize-app/popular-items.tsx:184`
```ts
const newProducts = selectedProductIds
.map(id => allProducts?.products.find(p => p.id === id))
```
`selectedProductIds` are SKU ids (from `ProductsSelector`), matched against
product ids, so the lookup misses and the dialog closes with nothing added.
The label formatter also runs `labelFormat({ productName, price })` on a
`SkuSummary` that has no `price`, rendering `₹undefined`.
**Expected:** match on `sku.productId`.
**Pinned by:** `tests/screens/customize-app-popular-items.test.tsx`.
### 6. StoreForm bypasses Formik validation
`components/StoreForm.tsx:111,183`
The submit button calls a local `submit()` that invokes the `onSubmit` prop
directly; Formik's `handleSubmit` is destructured (`:110`) but never called, so
`validationSchema` never runs. Combined with `owner` initialised to `0`
(`stores/add.tsx:35`) and `Yup.number().required()` accepting `0`, an ownerless
store is submitted and rejected by the backend instead of inline.
**Expected:** `onPress={handleSubmit}`.
**Pinned by:** `tests/components/store-form.test.tsx`,
`tests/screens/stores-add.test.tsx`.
---
## Medium
### 7. Dashboard Banners fires duplicate `updateBanner` calls on save
`app/(drawer)/dashboard/dashboard-banners/index.tsx:75-116`
`handleSave` collects `bannersToUpdate` in a per-banner loop and again in a
per-slot loop. A banner whose slot changed is pushed by both, so the same
`updateBanner({ id, serialNum })` fires twice; moving a banner between slots can
emit contradictory updates.
**Expected:** de-duplicate by banner id.
**Pinned by:** `tests/screens/banners-index.test.tsx`.
### 8. Banner edit screen shows "Banner not found" on mount
`app/(drawer)/dashboard/dashboard-banners/edit/[id].tsx:42-73`
`useEffect(..., [bannerId, bannerData])` calls `loadBanner` on the first render,
when `bannerData` is still `undefined`, taking the `else` branch:
`Alert.alert('Error', 'Banner not found')` + `router.back()` — before the query
resolves. The form then renders anyway.
**Expected:** wait for the query to settle before treating "no data" as missing.
**Pinned by:** `tests/screens/banners-edit.test.tsx`.
### 9. Refund / cancellation-coupon actions are unreachable
`app/(drawer)/dashboard/manage-orders/order-details/[id].tsx:697-769`
The entire Refund Details block is commented out. It is the only caller of
`setInitiateRefundDialogOpen(true)` and `setGenerateCouponDialogOpen(true)`, so
`admin.payments.initiateRefund` and `admin.coupon.generateCancellationCoupon`
can never fire from the UI. The `initiateRefund` success alert (lines 66-69)
also drops the amount from its template string.
**Expected:** re-enable the block when the feature ships.
**Pinned by:** `tests/screens/order-details.test.tsx` (documents the gap).
### 10. Complaints resolve can send an empty response the backend rejects
`app/(drawer)/dashboard/complaints/index.tsx:66`
```ts
resolveComplaint.mutate({ id: String(selectedComplaintId), response: response ?? '' }, ...)
```
The backend input requires `response: z.string().min(1)`. Confirming Resolve with
no comment sends `''` and gets a server error (surfaced as a generic alert)
instead of being blocked client-side.
**Expected:** require a response, or make it optional server-side.
**Pinned by:** `tests/screens/complaints-index.test.tsx`.
---
## Low
### 11. Inline "Packaged" toggle in the orders list is inert
`app/(drawer)/dashboard/manage-orders/orders/index.tsx:218`
`onPress={() => {}}`. Packaged changes only work through `OrderOptionsMenu`.
### 12. CancelOrderDialog has an unreachable validation branch
`components/CancelOrderDialog.tsx:18-21` alerts on an empty reason, but the
confirm button is disabled while the reason is empty (`:85`), so the branch
never runs.
### 13. Send Notifications shows the error alert twice
`app/(drawer)/dashboard/send-notifications/index.tsx:48-50,87-96` — the mutation
has an `onError` alert and the caller also try/catches and alerts.
### 14. Product Groupings "N Products" does nothing
`app/(drawer)/dashboard/product-groupings/index.tsx:11,130` — `BottomDialog` is
imported and `viewProducts` is set by `onViewProducts`, but no dialog renders.
### 15. `NotificationToast` calls a hook outside a component
`services/toaster.tsx:39-40` — `NotificationToast` calls `useRouter()` though it
is exported as an event helper, not rendered as a component (Rules of Hooks).
### 16. Upload key parsing assumes path-style S3 URLs
`hooks/useUploadToObjectStore.ts:99-104` — `extractKeyFromPresignedUrl` strips the
first path segment (`slice(1)`). Correct for the backend's current
`<endpoint>/<bucket>/<key>` URLs, but breaks for virtual-host-style
(`<bucket>.<host>/<key>`). The backend's own `s3-client.ts` uses `slice(-2)`.
---
## Test-harness limitations (not app bugs)
- **`expo-image-picker` / `expo-document-picker` mocks do not reach `packages/ui`.**
`packages/ui` resolves its own copy of those modules, so `common-ui`'s
`usePickImage`/`ImageUploader` call the real (native) picker and cannot be
driven from a test. Image-upload flows are therefore exercised by mocking the
upload hook or seeding state, and upload integration is not covered.
- **`@expo/vector-icons` has a duplicate copy under `packages/ui/node_modules`,**
so `UNSAFE_getAllByType(MaterialIcons)` from the app's copy does not find the
`common-ui` icons. Prefer text/testID-based queries.
- **`react-native-draggable-flatlist` mock** ignores `ListHeaderComponent` /
`ListFooterComponent` and never calls `onDragEnd`, so drag-reorder save flows
cannot be asserted through the mock.
## Already fixed during this work
- `stores/edit.tsx` now invalidates `admin.store.getStores` (only `getStoreById`
was refetched before).
- `coupons/create.tsx` + `coupons/edit/[id].tsx` invalidate
`admin.coupon.getAll` / `getReservedCoupons` instead of refetching with a
hardcoded `search: ''` that missed the list's key when a search was active.
- `tests/mocks/native.ts` `tabViewMock` `SceneMap` returned the raw map instead
of a `renderScene` function (corrected).