Skip to content
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

(test) O3-3937 Add test coverage around form readonly mode #401

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
177 changes: 91 additions & 86 deletions __mocks__/packages/hiv/forms/hts_poc/1.1.json
Original file line number Diff line number Diff line change
@@ -1,91 +1,96 @@
{
"name": "Test HTS POC",
"pages": [
"name": "Test HTS POC",
"pages": [
{
"label": "Screening",
"sections": [
{
"label": "Screening",
"sections": [
"label": "Testing history",
"isExpanded": "true",
"questions": [
{
"label": "When was the HIV test conducted?",
"type": "obs",
"questionOptions": {
"rendering": "date",
"concept": "164400AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"weeksList": ""
},
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"label": "Testing history",
"isExpanded": "true",
"questions": [
{
"label": "When was the HIV test conducted?",
"type": "obs",
"questionOptions": {
"rendering": "date",
"concept": "164400AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"weeksList": ""
},
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
}
],
"behaviours": [
{
"intent": "HTS_RETROSPECTIVE",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
}
]
},
{
"intent": "HTS_HIVTEST",
"required": "true"
},
{
"intent": "",
"required": "false",
"hide": {
"hideWhenExpression": "hivTestConducted !== 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3'"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
}
]
}
],
"id": "dateTestPerformed"
}
]
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
}
],
"behaviours": [
{
"intent": "HTS_RETROSPECTIVE",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
}
]
},
{
"intent": "HTS_HIVTEST",
"required": "true"
},
{
"intent": "",
"required": "false",
"hide": {
"hideWhenExpression": "hivTestConducted !== 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3'"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
}
]
}
]
],
"id": "dateTestPerformed"
},
{
"label": "Question title",
"type": "obs",
"questionOptions": {
"rendering": "text",
"concept": "193e8a03-1581-46e9-b0a4-17c55fa2649f"
},
"id": "sampleQuestion"
}
]
}
],
"availableIntents": [
"HTS_RETROSPECTIVE",
"HTS_HIVTEST",
"*"
],
"processor": "EncounterFormProcessor",
"uuid": "da24c540-cc83-43bc-978f-c1ef180a497f",
"referencedForms": [],
"encounterType": "79c1f50f-f77d-42e2-ad2a-d29304dde2fe"
}
]
}
],
"availableIntents": ["HTS_RETROSPECTIVE", "HTS_HIVTEST", "*"],
"processor": "EncounterFormProcessor",
"uuid": "da24c540-cc83-43bc-978f-c1ef180a497f",
"referencedForms": [],
"encounterType": "79c1f50f-f77d-42e2-ad2a-d29304dde2fe"
}
59 changes: 57 additions & 2 deletions src/form-engine.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ 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';
import { type SessionMode } from './types';

const patientUUID = '8673ee4f-e2ab-4077-ba55-4980f408773e';
const visit = mockVisit;
Expand Down Expand Up @@ -842,15 +844,68 @@ describe('Form engine component', () => {
});
});

function renderForm(formUUID, formJson, intent?: string) {
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('Form view mode', () => {
it('should ascertain that fields cannot be edited on view mode', async () => {
await act(async () => {
renderForm(null, htsPocForm, null, 'view');
});
const testingHistoryButton = screen.getByRole('button', { name: /Testing history/i });
expect(testingHistoryButton).toBeInTheDocument();

const hivTestButton = screen.getByRole('button', { name: /When was the HIV test conducted\?:/i });
expect(hivTestButton).toBeInTheDocument();

const blankFields = screen.getAllByText(/\(Blank\)/i);
blankFields.forEach((blankField) => {
expect(blankField).toBeInTheDocument();
});

const inputs = screen.queryAllByRole('textbox');
inputs.forEach((input) => {
expect(input).toHaveAttribute('readonly');
});

const interactiveElements = screen.queryAllByRole('textbox', { hidden: false });
expect(interactiveElements).toHaveLength(0);
});
});

function renderForm(formUUID, formJson, intent?: string, mode?: SessionMode) {
render(
<FormEngine
formJson={formJson}
formUUID={formUUID}
patientUUID={patientUUID}
formSessionIntent={intent}
visit={visit}
mode="enter"
mode={mode ? mode : 'enter'}
/>,
);
}
Expand Down
18 changes: 18 additions & 0 deletions src/utils/forms-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ describe('Forms loader - getForm', () => {
],
id: 'dateTestPerformed',
},
{
id: 'sampleQuestion',
label: 'Question title',
questionOptions: {
concept: '193e8a03-1581-46e9-b0a4-17c55fa2649f',
rendering: 'text',
},
type: 'obs',
},
],
},
],
Expand Down Expand Up @@ -246,6 +255,15 @@ describe('Forms loader - getForm', () => {
],
id: 'dateTestPerformed',
},
{
id: 'sampleQuestion',
label: 'Question title',
questionOptions: {
concept: '193e8a03-1581-46e9-b0a4-17c55fa2649f',
rendering: 'text',
},
type: 'obs',
},
],
},
],
Expand Down