Fix production build TS failures
modified: src/components/AddProductDialog.tsx modified: src/testUtils/mockDb.ts
This commit is contained in:
@@ -19,6 +19,10 @@ import { useProducts } from '../hooks/dataHooks';
|
||||
import { BarcodeScannerView } from './BarcodeScannerView';
|
||||
import { ExternalProductInfo, fetchProductFromOFF } from '../modules/openFoodFacts';
|
||||
import { DEFAULT_BULK_NAME, DEFAULT_UNIT_TYPE, Product } from '../models/Product';
|
||||
import type { BackdropProps } from '@mui/material/Backdrop';
|
||||
import type { FormHelperTextProps } from '@mui/material/FormHelperText';
|
||||
|
||||
type WithTestId<T> = Partial<T> & { 'data-testid'?: string };
|
||||
|
||||
export type AddProductDialogProps = {
|
||||
open: boolean;
|
||||
@@ -271,7 +275,7 @@ export const AddProductDialog = ({
|
||||
fullWidth
|
||||
maxWidth="sm"
|
||||
PaperProps={{ role: 'form' }}
|
||||
BackdropProps={{ 'data-testid': 'add-product-backdrop' }}
|
||||
BackdropProps={{ 'data-testid': 'add-product-backdrop' } as WithTestId<BackdropProps>}
|
||||
>
|
||||
<DialogTitle id="add-product-dialog-title" sx={{ pr: 6 }}>
|
||||
Add product
|
||||
@@ -312,7 +316,7 @@ export const AddProductDialog = ({
|
||||
inputProps={{ 'data-testid': 'product-barcode-input' }}
|
||||
error={!!barcodeError}
|
||||
helperText={barcodeError || ' '}
|
||||
FormHelperTextProps={{ 'data-testid': 'barcode-error' }}
|
||||
FormHelperTextProps={{ 'data-testid': 'barcode-error' } as WithTestId<FormHelperTextProps>}
|
||||
fullWidth
|
||||
/>
|
||||
<Button onClick={() => setScannerOpen(true)}>Scan barcode</Button>
|
||||
@@ -340,7 +344,7 @@ export const AddProductDialog = ({
|
||||
onClose={() => setScannerOpen(false)}
|
||||
aria-label="Scan barcode"
|
||||
data-testid="scan-barcode-dialog"
|
||||
BackdropProps={{ 'data-testid': 'scan-barcode-backdrop' }}
|
||||
BackdropProps={{ 'data-testid': 'scan-barcode-backdrop' } as WithTestId<BackdropProps>}
|
||||
>
|
||||
<DialogTitle>Scan barcode</DialogTitle>
|
||||
<DialogContent>
|
||||
|
||||
+21
-7
@@ -1,3 +1,10 @@
|
||||
// src/testUtils/mockDb.ts
|
||||
import type { Product } from '../models/Product';
|
||||
import type { Category } from '../models/Category';
|
||||
import type { Area } from '../models/Area';
|
||||
import type { PickList } from '../models/PickList';
|
||||
import type { PickItem } from '../models/PickItem';
|
||||
|
||||
export class MockTable<T extends { id: string }> {
|
||||
items: T[];
|
||||
|
||||
@@ -55,14 +62,21 @@ export class MockTable<T extends { id: string }> {
|
||||
}
|
||||
}
|
||||
|
||||
export const createMockDb = (data?: any) => {
|
||||
export const createMockDb = (data?: {
|
||||
products?: Product[];
|
||||
categories?: Category[];
|
||||
areas?: Area[];
|
||||
pickLists?: PickList[];
|
||||
pickItems?: PickItem[];
|
||||
importExportLogs?: any[];
|
||||
}) => {
|
||||
return {
|
||||
products: new MockTable(data?.products ?? []),
|
||||
categories: new MockTable(data?.categories ?? []),
|
||||
areas: new MockTable(data?.areas ?? []),
|
||||
pickLists: new MockTable(data?.pickLists ?? []),
|
||||
pickItems: new MockTable(data?.pickItems ?? []),
|
||||
importExportLogs: new MockTable<any>([]),
|
||||
products: new MockTable<Product>(data?.products ?? []),
|
||||
categories: new MockTable<Category>(data?.categories ?? []),
|
||||
areas: new MockTable<Area>(data?.areas ?? []),
|
||||
pickLists: new MockTable<PickList>(data?.pickLists ?? []),
|
||||
pickItems: new MockTable<PickItem>(data?.pickItems ?? []),
|
||||
importExportLogs: new MockTable<any>(data?.importExportLogs ?? []),
|
||||
transaction: async (_mode: string, ...args: any[]) => {
|
||||
const cb = args[args.length - 1];
|
||||
if (typeof cb === 'function') return cb();
|
||||
|
||||
Reference in New Issue
Block a user