Skip to content

Commit

Permalink
Merge branch 'main' into sort-and-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki authored Oct 31, 2024
2 parents 5a4e655 + 13f57fe commit 6d7beb0
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`renders correctly: attractive item no radio button 1`] = `

exports[`renders correctly: attractive item yes radio button 1`] = `
<input
checked=""
class="ant-radio-input"
type="radio"
value="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,108 @@ export const createdBinary = {
contentType: 'image/png',
data: 'aGVsbG8=',
};

export const removedImageCommodity = {
resourceType: 'Group',
id: '52cffa51-fa81-49aa-9944-5b45d9e4c117',
identifier: [
{ use: 'secondary', value: '606109db-5632-48c5-8710-b726e1b3addf' },
{ use: 'official', value: '52cffa51-fa81-49aa-9944-5b45d9e4c117' },
],
active: true,
type: 'substance',
actual: false,
code: {
coding: [{ system: 'http://snomed.info/sct', code: '386452003', display: 'Supply management' }],
},
name: 'Bed nets',
characteristic: [
{
code: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '23435363',
display: 'Attractive Item code',
},
],
},
valueBoolean: true,
},
{
code: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '34536373',
display: 'Is it there code',
},
],
},
valueCodeableConcept: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '34536373-1',
display: 'Value entered on the It is there code',
},
],
text: 'yes',
},
},
{
code: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '45647484',
display: 'Is it in good condition? (optional)',
},
],
},
valueCodeableConcept: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '45647484-1',
display: 'Value entered on the Is it in good condition? (optional)',
},
],
text: 'Yes, no tears, and inocuated',
},
},
{
code: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '56758595',
display: 'Is it being used appropriately? (optional)',
},
],
},
valueCodeableConcept: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '56758595-1',
display: 'Value entered on the Is it being used appropriately? (optional)',
},
],
text: 'Hanged at correct height and covers averagely sized beds',
},
},
{
code: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '67869606',
display: 'Accountability period (in months)',
},
],
},
valueQuantity: { value: 12 },
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
editedCommodity1,
listEdited1,
newList,
removedImageCommodity,
} from './fixtures';
import { binaryResourceType, groupResourceType, listResourceType } from '../../../../constants';
import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -196,7 +197,7 @@ test('form validation works', async () => {
const errorNodes = [...document.querySelectorAll('.ant-form-item-explain-error')];
const errorMsgs = errorNodes.map((node) => node.textContent);

expect(errorMsgs).toEqual(['Required', 'Required', 'Required']);
expect(errorMsgs).toEqual(['Required', 'Required', 'Required', 'Required']);
});

it('can create new commodity', async () => {
Expand Down Expand Up @@ -432,8 +433,8 @@ it('can remove product image', async () => {
);

nock(props.fhirBaseURL)
.put(`/${groupResourceType}/${commodity1.id}`, commodityLessImage)
.reply(200, commodityLessImage)
.put(`/${groupResourceType}/${commodity1.id}`, removedImageCommodity)
.reply(200, removedImageCommodity)
.persist();

render(
Expand All @@ -446,6 +447,9 @@ it('can remove product image', async () => {
screen.getByText('Edit commodity | Bed nets');
});

const attractiveYes = screen.getByRole('radio', { name: /yes/i });
userEvent.click(attractiveYes);

const removeFileIcon = screen.getByTitle('Remove file');
userEvent.click(removeFileIcon);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { cloneDeep, get } from 'lodash';
import {
active,
groupResourceType,
id,
identifier,
type,
unitOfMeasure,
name,
listResourceType,
Expand Down Expand Up @@ -54,6 +51,7 @@ import { IBinary } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IBinary';
import { UploadFile } from 'antd';
import { Coding } from '@smile-cdr/fhirts/dist/FHIR-R4/classes/coding';
import { R4GroupTypeCodes } from '@opensrp/fhir-helpers';
import { defaultValidationRulesFactory } from '../../ProductForm/utils';

export type EusmGroupFormFields = GroupFormFields<{ group: IGroup; binary?: IBinary }>;

Expand All @@ -80,8 +78,7 @@ export const defaultCode = {
*/
export const validationRulesFactory = (t: TFunction) => {
return {
[id]: [{ type: 'string' }] as Rule[],
[identifier]: [{ type: 'string' }] as Rule[],
...defaultValidationRulesFactory(t),
[materialNumber]: [
{ type: 'string', message: t('Must be a valid string') },
{ required: true, message: t('Required') },
Expand All @@ -91,12 +88,12 @@ export const validationRulesFactory = (t: TFunction) => {
{ required: true, message: t('Required') },
] as Rule[],
[active]: [{ type: 'boolean' }, { required: true, message: t('Required') }] as Rule[],
[type]: [{ type: 'enum', enum: Object.values(R4GroupTypeCodes), required: true }] as Rule[],
[isAttractiveItem]: [{ type: 'boolean' }] as Rule[],
[isAttractiveItem]: [{ required: true, message: t('Required') }, { type: 'boolean' }] as Rule[],
[availability]: [{ type: 'string' }, { required: true, message: t('Required') }] as Rule[],
[condition]: [{ type: 'string' }] as Rule[],
[appropriateUsage]: [{ type: 'string' }] as Rule[],
[accountabilityPeriod]: [{ type: 'number' }] as Rule[],
[accountabilityPeriod]: [
{ required: true, message: t('Required') },
{ type: 'number' },
] as Rule[],
};
};

Expand Down Expand Up @@ -336,6 +333,7 @@ export const getGroupFormFields = (obj?: IGroup, binary?: IBinary): EusmGroupFor
return {
initialObject: { group: { code: defaultCode } },
active: true,
[isAttractiveItem]: true,
type: R4GroupTypeCodes.SUBSTANCE,
} as EusmGroupFormFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,18 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
return (
<Form
form={form}
requiredMark={false}
{...formItemLayout}
onFinish={(values: GroupFormFields) => {
mutate(values);
}}
initialValues={initialValues}
>
<FormItem id={product} name={product} label={t('Product name')}>
<FormItem
id={product}
rules={validationRules[product]}
name={product}
label={t('Product name')}
>
<ClientSideActionsSelect<IGroup>
fhirBaseUrl={fhirBaseURL}
resourceType={groupResourceType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ test('form validation works', async () => {
const errorMsgs = errorNodes.map((node) => node.textContent);

expect(errorMsgs).toEqual([
'Product is required',
'Delivery date is required',
'Accountability end date is required',
'UNICEF section is required',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ function CommodityForm<

return (
<Form
requiredMark={false}
{...formItemLayout}
onFinish={(values: FormFields) => {
mutate(values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const HealthCareForm = (props: HealthCareFormProps) => {

return (
<Form
requiredMark={false}
{...formItemLayout}
onFinish={(values: HealthCareFormFields) => {
mutate(values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export function useSimpleTabularView<T extends Resource>(
},
keepPreviousData: true,
staleTime: 5000,
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
};
Expand Down

0 comments on commit 6d7beb0

Please sign in to comment.