58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
/**
|
|
* Add product (app/(drawer)/dashboard/products/add.tsx) — create-mode screen.
|
|
*
|
|
* KNOWN APP BUG (src/components/ProductForm.tsx:80): `variantSignature` calls
|
|
* `a.featureValue.trim()` unguarded. The create form starts every variant with
|
|
* an empty `quantity` value, so any keystroke / variant add makes Yup throw
|
|
* `TypeError: Cannot read properties of undefined (reading 'trim')`,
|
|
* `validateForm()` never resolves, and the form cannot be submitted. This
|
|
* screen therefore can only be asserted for render/loading; the submit payload
|
|
* is covered against ProductForm with valid seeded values (see
|
|
* tests/components/product-form.test.tsx). See the final report.
|
|
*/
|
|
|
|
jest.mock('expo-router', () => require('../mocks/router').expoRouterMock())
|
|
|
|
import React from 'react'
|
|
import { Alert } from 'react-native'
|
|
import { fireEvent, screen } from '@testing-library/react-native'
|
|
|
|
import AddProduct from '@/app/(drawer)/dashboard/products/add'
|
|
import { resetStorage, setupApiMocks } from '../mocks/api'
|
|
import { procCount } from '../mocks/procedures'
|
|
import { searchParamsMock } from '../mocks/router'
|
|
import { renderWithProviders } from '../helpers/render'
|
|
|
|
describe('Add product', () => {
|
|
beforeEach(async () => {
|
|
await resetStorage()
|
|
searchParamsMock.current = {}
|
|
setupApiMocks()
|
|
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
})
|
|
|
|
it('renders the create form with a single seeded variant', () => {
|
|
renderWithProviders(<AddProduct />)
|
|
|
|
expect(screen.getByText('Create Product')).toBeVisible()
|
|
expect(screen.getByTestId('product-name-input')).toBeVisible()
|
|
expect(screen.getByTestId('variant-0-price')).toBeVisible()
|
|
expect(screen.getByTestId('variant-0-attr-0-name').props.value).toBe('quantity')
|
|
expect(screen.queryByTestId('variant-1-price')).toBeNull()
|
|
})
|
|
|
|
it('starts the form empty', () => {
|
|
renderWithProviders(<AddProduct />)
|
|
|
|
expect(screen.getByTestId('product-name-input').props.value).toBe('')
|
|
expect(screen.getByTestId('variant-0-price').props.value).toBe('')
|
|
expect(screen.getByTestId('variant-0-attr-0-value').props.value).toBe('')
|
|
})
|
|
|
|
it('does not call createProduct on mount', () => {
|
|
const api = setupApiMocks()
|
|
renderWithProviders(<AddProduct />)
|
|
|
|
expect(procCount(api.fetchMock, 'admin.product.createProduct')).toBe(0)
|
|
})
|
|
})
|