Skip to content

Commit

Permalink
inventory form updates (#1455)
Browse files Browse the repository at this point in the history
* Conditionally render serial number field

* Update inventory form title

* Make po number optional

* Update tests
  • Loading branch information
peterMuriuki authored Aug 1, 2024
1 parent 618e7d0 commit 544f1f8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,16 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
/>
</FormItem>

<FormItem
id={serialNumber}
rules={validationRules[serialNumber]}
name={serialNumber}
label={t('Serial number')}
>
<Input disabled={!attractiveProduct} placeholder={t('Serial number')} />
</FormItem>
{attractiveProduct ? (
<FormItem
id={serialNumber}
rules={validationRules[serialNumber]}
name={serialNumber}
label={t('Serial number')}
>
<Input placeholder={t('Serial number')} />
</FormItem>
) : null}

<FormItem id={donor} name={donor} label={t('Donor')}>
<ValueSetAsyncSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const AddLocationInventory = (props: AddLocationInventoryProps) => {
const { fhirBaseURL, listId, commodityListId } = props;
const { t } = useTranslation();
const { inventoryId, servicePointId } = useParams<RouteParams>();
const pageTitle = inventoryId ? t('Edit locations Inventory') : t('Add locations Inventory');
const pageTitle = inventoryId
? t('Edit Service Point Inventory')
: t('Add Service Point Inventory');

const inventoryResource = useQuery(
[fhirBaseURL, inventoryId],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ test('form validation works', async () => {
'Delivery date is required',
'Accountability end date is required',
'UNICEF section is required',
'PO number is required',
]);
});

Expand Down Expand Up @@ -320,6 +319,9 @@ test('#1384 - correctly updates location inventory', async () => {
expect(preFetchScope.isDone()).toBeTruthy();
});

// serial number is initially not shown on the form
expect(screen.queryByText('Serial number')).not.toBeInTheDocument();

// simulate value selection for product
const productSelectComponent = document.querySelector(`input#${product}`)!;
fireEvent.mouseDown(productSelectComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ test('renders correctly', async () => {

await waitForElementToBeRemoved(document.querySelector('.ant-spin'));

screen.getByText('Add locations Inventory');
screen.getByText('Add Service Point Inventory');
// form items
screen.getByText('Product name');
screen.getByText('Quantity');
screen.getByText('Delivery date');
screen.getByText('Accountability end date');
screen.getByText('UNICEF section');
screen.getByText('Serial number');
expect(screen.queryByAltText('Serial number')).not.toBeInTheDocument();
screen.getByText('Donor');
screen.getByText('PO number');
screen.getByText('Expiry date');
Expand Down Expand Up @@ -160,5 +160,5 @@ test('renders correctly on edit', async () => {

await waitForElementToBeRemoved(document.querySelector('.ant-spin'));

screen.getByText('Edit locations Inventory');
screen.getByText('Edit Service Point Inventory');
});
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,7 @@ export const validationRulesFactory = (t: TFunction, isAttractiveProduct: boolea
{ required: true, message: t('Accountability end date is required') },
] as Rule[],
[serialNumber]: [{ type: 'string', message: t('Must be a valid string') }] as Rule[],
[PONumber]: [
{ type: 'string', message: t('Must be a valid string') },
{ required: true, message: t('PO number is required') },
] as Rule[],
[PONumber]: [{ type: 'string', message: t('Must be a valid string') }] as Rule[],
};
if (isAttractiveProduct) {
rules[serialNumber].push({ required: true, message: t('Serial number is required') });
Expand Down

0 comments on commit 544f1f8

Please sign in to comment.