Skip to content

Commit

Permalink
(test) O3-3937 Add test coverage around form readonly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Oct 2, 2024
1 parent 29071e5 commit 557e72f
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
79 changes: 79 additions & 0 deletions __mocks__/forms/rfe-forms/read-only-validation-form.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "Test read only",
"pages": [
{
"label": "1",
"sections": [
{
"label": "1",
"isExpanded": "true",
"questions": [
{
"label": "Visit type",
"type": "obs",
"required": false,
"id": "visitType",
"readonly": "true",
"questionOptions": {
"rendering": "select",
"concept": "164181AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"conceptMappings": [
{
"relationship": "SAME-AS",
"type": "CIEL",
"value": "164181"
}
],
"answers": [
{
"concept": "164180AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "New visit"
},
{
"concept": "160530AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "Return visit type"
}
]
},
"validators": []
},
{
"label": "Visit punctuality",
"type": "obs",
"required": false,
"id": "visitPunctuality",
"readonly": "true",
"questionOptions": {
"rendering": "text",
"concept": "160632AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"conceptMappings": [
{
"relationship": "SAME-AS",
"type": "CIEL",
"value": "160632"
},
{
"relationship": "SAME-AS",
"type": "AMPATH",
"value": "1915"
},
{
"relationship": "BROADER-THAN",
"type": "LOINC",
"value": "48767-8"
}
]
},
"validators": []
}
]
}
]
}
],
"processor": "EncounterFormProcessor",
"encounterType": "",
"referencedForms": [],
"uuid": "",
"description": "Test read only"
}
28 changes: 28 additions & 0 deletions src/form-engine.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import externalDataSourceForm from '__mocks__/forms/rfe-forms/external_data_sour
import monthsOnArtForm from '__mocks__/forms/rfe-forms/months-on-art-form.json';
import nextVisitForm from '__mocks__/forms/rfe-forms/next-visit-test-form.json';
import viralLoadStatusForm from '__mocks__/forms/rfe-forms/viral-load-status-form.json';
import readOnlyValidationForm from '__mocks__/forms/rfe-forms/read-only-validation-form.json';

import FormEngine from './form-engine.component';

Expand Down Expand Up @@ -215,6 +216,33 @@ describe('Form engine component', () => {
});
});

describe('Read only mode', () => {
it('should ascertain that each field with readonly = true passed will not be editable', async () => {
await act(async () => {
renderForm(null, readOnlyValidationForm);
});

const visitTypeDropdown = screen.getByRole('combobox', {
name: /visit type/i,
});
const visitPunctualityTextbox = screen.getByLabelText(/visit punctuality/i);

expect(visitTypeDropdown).toBeInTheDocument();
expect(visitTypeDropdown).toHaveClass('cds--list-box__field');

const visitTypeWrapper = visitTypeDropdown.closest('.cds--dropdown');
expect(visitTypeWrapper).toHaveClass('cds--dropdown cds--dropdown--readonly cds--list-box');

expect(visitPunctualityTextbox).toBeInTheDocument();
expect(visitPunctualityTextbox).toHaveClass('cds--text-input');

const visitPunctualityWrapper = visitPunctualityTextbox.closest('.cds--text-input-wrapper');
expect(visitPunctualityWrapper).toHaveClass(
'cds--form-item cds--text-input-wrapper cds--text-input-wrapper--readonly',
);
});
});

describe('conditional answered validation', () => {
it('should fail if the referenced field has a value that does not exist on the referenced answers array', async () => {
await act(async () => {
Expand Down

0 comments on commit 557e72f

Please sign in to comment.