-
Notifications
You must be signed in to change notification settings - Fork 85
(feat) O3-4201: Enhance Number Question Labels Display Unit and Range (Min/Max) from Concept #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
035c318
a8f625a
9248fd2
da40307
43ee1f0
3cc336f
3e9a51c
9342a90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really sure about jest.mock('react-i18next', () => ({... |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,22 @@ import { act, render, screen, fireEvent } from '@testing-library/react'; | |
import { useFormProviderContext } from 'src/provider/form-provider'; | ||
import NumberField from './number.component'; | ||
|
||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (key, defaultValueOrOptions, options) => { | ||
|
||
if (typeof defaultValueOrOptions === 'object' && 'fieldDescription' in defaultValueOrOptions) { | ||
return `${defaultValueOrOptions.fieldDescription} ${defaultValueOrOptions.unitsAndRange}`; | ||
} | ||
else if (typeof options === 'object' && 'unitsAndRange' in options) { | ||
return `${options.fieldDescription} ${options.unitsAndRange}`; | ||
} | ||
|
||
return key; | ||
} | ||
}) | ||
})); | ||
|
||
jest.mock('src/provider/form-provider', () => ({ | ||
useFormProviderContext: jest.fn(), | ||
})); | ||
|
@@ -22,6 +38,63 @@ const numberFieldMock = { | |
readonly: false, | ||
}; | ||
|
||
const numberFieldMockWithUnitsAndRange = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to have a more comprehensive set of tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a few more cases (only units, only range, only max) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add one for lowAbsolute only as well? That should cover things. |
||
label: 'Weight', | ||
type: 'obs', | ||
id: 'weight', | ||
questionOptions: { | ||
rendering: 'number', | ||
}, | ||
meta: { | ||
concept: { | ||
units: 'kg', | ||
lowAbsolute: 0, | ||
hiAbsolute: 200, | ||
} | ||
}, | ||
isHidden: false, | ||
isDisabled: false, | ||
readonly: false, | ||
}; | ||
|
||
const numberFieldMockWithUnitsOnly = { | ||
...numberFieldMockWithUnitsAndRange, | ||
meta: { | ||
concept: { | ||
units: 'kg', | ||
} | ||
}, | ||
}; | ||
|
||
const numberFieldMockWithRangeOnly = { | ||
...numberFieldMockWithUnitsAndRange, | ||
meta: { | ||
concept: { | ||
lowAbsolute: 0, | ||
hiAbsolute: 200, | ||
} | ||
}, | ||
}; | ||
|
||
const numberFieldMockWithHiAbsoluteOnly = { | ||
...numberFieldMockWithUnitsAndRange, | ||
meta: { | ||
concept: { | ||
hiAbsolute: 200, | ||
} | ||
}, | ||
}; | ||
|
||
const numberFieldMockWithLowAbsoluteOnly = { | ||
...numberFieldMockWithUnitsAndRange, | ||
meta: { | ||
concept: { | ||
lowAbsolute: 0, | ||
} | ||
}, | ||
}; | ||
|
||
|
||
const renderNumberField = async (props) => { | ||
await act(() => render(<NumberField {...props} />)); | ||
}; | ||
|
@@ -104,4 +177,59 @@ describe('NumberField Component', () => { | |
const inputElement = screen.getByLabelText('Weight(kg):') as HTMLInputElement; | ||
expect(inputElement).toBeDisabled(); | ||
}); | ||
|
||
it('renders units and range', async () => { | ||
await renderNumberField({ | ||
field: numberFieldMockWithUnitsAndRange, | ||
value: '', | ||
errors: [], | ||
warnings: [], | ||
setFieldValue: jest.fn(), | ||
}); | ||
expect(screen.getByLabelText('Weight (0 - 200 kg)')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders units only', async () => { | ||
await renderNumberField({ | ||
field: numberFieldMockWithUnitsOnly, | ||
value: '', | ||
errors: [], | ||
warnings: [], | ||
setFieldValue: jest.fn(), | ||
}); | ||
expect(screen.getByLabelText('Weight (kg)')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders range only', async () => { | ||
await renderNumberField({ | ||
field: numberFieldMockWithRangeOnly, | ||
value: '', | ||
errors: [], | ||
warnings: [], | ||
setFieldValue: jest.fn(), | ||
}); | ||
expect(screen.getByLabelText('Weight (0 - 200)')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders hiAbsolute only', async () => { | ||
await renderNumberField({ | ||
field: numberFieldMockWithHiAbsoluteOnly, | ||
value: '', | ||
errors: [], | ||
warnings: [], | ||
setFieldValue: jest.fn(), | ||
}); | ||
expect(screen.getByLabelText('Weight (<= 200)')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders lowAbsolute only', async () => { | ||
await renderNumberField({ | ||
field: numberFieldMockWithLowAbsoluteOnly, | ||
value: '', | ||
errors: [], | ||
warnings: [], | ||
setFieldValue: jest.fn(), | ||
}); | ||
expect(screen.getByLabelText('Weight (>= 0)')).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import { useRestApiMaxResults } from './useRestApiMaxResults'; | |
type ConceptFetchResponse = FetchResponse<{ results: Array<OpenmrsResource> }>; | ||
|
||
const conceptRepresentation = | ||
'custom:(uuid,display,conceptClass:(uuid,display),answers:(uuid,display),conceptMappings:(conceptReferenceTerm:(conceptSource:(name),code)))'; | ||
'custom:(units,lowAbsolute,hiAbsolute,uuid,display,conceptClass:(uuid,display),answers:(uuid,display),conceptMappings:(conceptReferenceTerm:(conceptSource:(name),code)))'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ibacher when is it necessary to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the values that aren't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we can handle critical icons in a separate PR. |
||
|
||
export function useConcepts(references: Set<string>): { | ||
concepts: Array<OpenmrsResource> | undefined; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without escapeValue: false, / doesn't show correctly, it becomes
/
egBMI (Kg/m2):