(test) O3-3939: Add test to repeat component#385
(test) O3-3939: Add test to repeat component#385WodPachua wants to merge 6 commits intoopenmrs:mainfrom
Conversation
|
@WodPachua are you still working on this? |
|
Was trying to add another/more tests... had made the draft for your review if am on the right track |
src/components/repeat/repeat.test.ts
Outdated
| it('Should update field ID in expressions when adding repeated fields', () => { | ||
| const expression = "infantStatus !== 'someValue'"; | ||
| const fieldIds = ['birthDate', 'infantStatus', 'deathDate']; | ||
| const updatedExpression = updateFieldIdInExpression(expression, 2, fieldIds); | ||
|
|
||
| expect(updatedExpression).toEqual("infantStatus_2 !== 'someValue'"); | ||
| }); |
There was a problem hiding this comment.
@WodPachua I like the test but the scope of work begs for testing the repeat component itself and not just the helpers. You want to render a form with a "repeatable" field, and then test out things like:
- Asserting that clicking the "Add" button clones the field at origin
- Test out submission (Assert that both the origin and its instances' values are submitted successfully)
- Edit mode (Assert that a repeat field with instances is properly initialised (hydrated) as expected)
|
@WodPachua are you still working on this? |
|
|
Have already noted the changes proposed on slack |
|
@WodPachua you probably want to do something like this. |
samuelmale
left a comment
There was a problem hiding this comment.
@WodPachua sorry for the delayed review.
| import React, { act } from 'react'; | ||
|
|
||
| describe('RepeatingFieldComponent - handleExpressionFieldIdUpdate', () => { | ||
| it('Should handle update of expression with ids in repeat group', () => { |
There was a problem hiding this comment.
| it('Should handle update of expression with ids in repeat group', () => { | |
| it('Should update field IDs when repeat index is greater than 1', () => { |
| ); | ||
| }); | ||
|
|
||
| it('Should handle update of expression with ids not in repeat group', () => { |
There was a problem hiding this comment.
| it('Should handle update of expression with ids not in repeat group', () => { | |
| it('Should not update field IDs when repeat index equals 1', () => { |
| const mockUsePatient = jest.mocked(usePatient); | ||
| const mockUseSession = jest.mocked(useSession); | ||
|
|
||
| global.ResizeObserver = require('resize-observer-polyfill'); |
| }; | ||
|
|
||
| beforeEach(() => { | ||
| Object.defineProperty(window, 'i18next', { |
| formJson={repeatingComponentTestForm as FormSchema} | ||
| patientUUID="8673ee4f-e2ab-4077-ba55-4980f408773e" | ||
| mode={mode} | ||
| encounterUUID={mode === 'edit' ? 'a8817ad2-ef92-46c8-bbf7-db336505027c' : null} |
There was a problem hiding this comment.
@WodPachua, Do you have any test cases covering the "edit mode"? If not, can we define some?
| const clonedField = screen.getByLabelText(/Contact relationship/i); | ||
| expect(clonedField).toBeInTheDocument(); |
There was a problem hiding this comment.
Can you confirm that there are two fields with the label "Contact relationship" that never existed on the initial render?
| await waitFor(() => { | ||
| expect(mockContext.methods.getValues).toHaveBeenCalledWith(expect.objectContaining({ | ||
| patientContactRelationship: 'Child', | ||
| phoneNumber: '123456789', | ||
| })); |
There was a problem hiding this comment.
Can you also provide values for the instances so that we end up with a submission like:
{
patientContactRelationship: 'Child',
patientContactRelationship_2: 'foo',
phoneNumber: '123456789',
phoneNumber_2: 'bar'
}
Requirements
Summary
Added test to the repeat component in the form engine
Screenshots
Related Issue
O3-3939
Other