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 { BarcodeScannerView } from './BarcodeScannerView';
|
||||||
import { ExternalProductInfo, fetchProductFromOFF } from '../modules/openFoodFacts';
|
import { ExternalProductInfo, fetchProductFromOFF } from '../modules/openFoodFacts';
|
||||||
import { DEFAULT_BULK_NAME, DEFAULT_UNIT_TYPE, Product } from '../models/Product';
|
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 = {
|
export type AddProductDialogProps = {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -271,7 +275,7 @@ export const AddProductDialog = ({
|
|||||||
fullWidth
|
fullWidth
|
||||||
maxWidth="sm"
|
maxWidth="sm"
|
||||||
PaperProps={{ role: 'form' }}
|
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 }}>
|
<DialogTitle id="add-product-dialog-title" sx={{ pr: 6 }}>
|
||||||
Add product
|
Add product
|
||||||
@@ -312,7 +316,7 @@ export const AddProductDialog = ({
|
|||||||
inputProps={{ 'data-testid': 'product-barcode-input' }}
|
inputProps={{ 'data-testid': 'product-barcode-input' }}
|
||||||
error={!!barcodeError}
|
error={!!barcodeError}
|
||||||
helperText={barcodeError || ' '}
|
helperText={barcodeError || ' '}
|
||||||
FormHelperTextProps={{ 'data-testid': 'barcode-error' }}
|
FormHelperTextProps={{ 'data-testid': 'barcode-error' } as WithTestId<FormHelperTextProps>}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<Button onClick={() => setScannerOpen(true)}>Scan barcode</Button>
|
<Button onClick={() => setScannerOpen(true)}>Scan barcode</Button>
|
||||||
@@ -340,7 +344,7 @@ export const AddProductDialog = ({
|
|||||||
onClose={() => setScannerOpen(false)}
|
onClose={() => setScannerOpen(false)}
|
||||||
aria-label="Scan barcode"
|
aria-label="Scan barcode"
|
||||||
data-testid="scan-barcode-dialog"
|
data-testid="scan-barcode-dialog"
|
||||||
BackdropProps={{ 'data-testid': 'scan-barcode-backdrop' }}
|
BackdropProps={{ 'data-testid': 'scan-barcode-backdrop' } as WithTestId<BackdropProps>}
|
||||||
>
|
>
|
||||||
<DialogTitle>Scan barcode</DialogTitle>
|
<DialogTitle>Scan barcode</DialogTitle>
|
||||||
<DialogContent>
|
<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 }> {
|
export class MockTable<T extends { id: string }> {
|
||||||
items: T[];
|
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 {
|
return {
|
||||||
products: new MockTable(data?.products ?? []),
|
products: new MockTable<Product>(data?.products ?? []),
|
||||||
categories: new MockTable(data?.categories ?? []),
|
categories: new MockTable<Category>(data?.categories ?? []),
|
||||||
areas: new MockTable(data?.areas ?? []),
|
areas: new MockTable<Area>(data?.areas ?? []),
|
||||||
pickLists: new MockTable(data?.pickLists ?? []),
|
pickLists: new MockTable<PickList>(data?.pickLists ?? []),
|
||||||
pickItems: new MockTable(data?.pickItems ?? []),
|
pickItems: new MockTable<PickItem>(data?.pickItems ?? []),
|
||||||
importExportLogs: new MockTable<any>([]),
|
importExportLogs: new MockTable<any>(data?.importExportLogs ?? []),
|
||||||
transaction: async (_mode: string, ...args: any[]) => {
|
transaction: async (_mode: string, ...args: any[]) => {
|
||||||
const cb = args[args.length - 1];
|
const cb = args[args.length - 1];
|
||||||
if (typeof cb === 'function') return cb();
|
if (typeof cb === 'function') return cb();
|
||||||
|
|||||||
Reference in New Issue
Block a user