Skip to content

(tests) O3-4316: Add unit tests for obsGroup type questions #416

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rdwaynedehoedt
Copy link

@rdwaynedehoedt rdwaynedehoedt commented Mar 13, 2025

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

This PR adds unit tests for obsGroup type questions in the form engine. The tests validate the proper rendering and functionality of obsGroup components, ensuring they correctly handle nested observations and maintain data integrity.

Screenshots

N/A - This PR focuses on unit tests without UI changes.

Related Issue

https://openmrs.atlassian.net/browse/O3-4316

Other

The added tests improve coverage for the obsGroup functionality which was previously untested.

@rdwaynedehoedt
Copy link
Author

Hi @NethmiRodrigo , could you review this PR Thanks!

Copy link
Collaborator

@NethmiRodrigo NethmiRodrigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rdwaynedehoedt! Left a couple of suggestions:

},
},
],
} as ObsGroupQuestion,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this as ObsGroupQuestion required?

Comment on lines +80 to +93
render(
<FormFieldProvider initialFormField={initialFormField}>
<QuestionModal
closeModal={mockCloseModal}
schema={mockSchema}
pageIndex={0}
sectionIndex={0}
questionIndex={0}
onSchemaChange={mockOnSchemaChange}
resetIndices={mockResetIndices}
formField={initialFormField}
/>
</FormFieldProvider>,
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to have the `renderComponent as a separate function like so -

function renderComponent() {
render(
<FormFieldProvider initialFormField={formField}>
<PatientIdentifierTypeQuestion />
</FormFieldProvider>,
);

);

expect(screen.getByText(/Question type/i)).toBeInTheDocument();
expect(screen.getByText(/Rendering type/i)).toBeInTheDocument();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also make sure that the button Add grouped question is visible

Comment on lines +22 to +26
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key, defaultValue) => defaultValue || key,
}),
}));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? We already have a mock for react-i18next in https://github.com/openmrs/openmrs-esm-form-builder/blob/main/__mocks__/react-i18next.js

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test for things like adding a grouped question renders the input fields for another question and that deleting an obsgroup question does actually delete it

label: 'Vital Signs',
type: 'obsGroup',
questionOptions: {
rendering: 'group' as RenderType,
Copy link
Contributor

@Bharath-K-Shetty Bharath-K-Shetty Mar 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need explicit casting here?

label: 'Blood Pressure',
type: 'obs',
questionOptions: {
rendering: 'text' as RenderType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rendering: 'text' as RenderType,
rendering: 'text' ,

label: 'Temperature',
type: 'obs',
questionOptions: {
rendering: 'number' as RenderType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rendering: 'number' as RenderType,
rendering: 'number',

@NethmiRodrigo NethmiRodrigo changed the title O3-4316 : Add unit tests for obsGroup type questions (tests) O3-4316: Add unit tests for obsGroup type questions Mar 17, 2025
@rdwaynedehoedt rdwaynedehoedt marked this pull request as draft March 18, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants