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

Merged
merged 2 commits into from
Oct 23, 2024
Merged
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
63 changes: 63 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,63 @@
{
"name": "Test read only",
"pages": [
{
"label": "1",
"sections": [
{
"label": "1",
"isExpanded": "true",
"questions": [
{
"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": []
},
{
"label": "Visit notes",
"type": "obs",
"required": false,
"id": "visitNotes",
"readonly": "true",
"questionOptions": {
"rendering": "text",
"concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"conceptMappings": []
},
"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"
}
47 changes: 45 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,56 @@ describe('Form engine component', () => {
});
});

function renderForm(formUUID, formJson, intent?: string) {
describe('Read only mode', () => {
it('should ensure that each read-only field is not editable', async () => {
await act(async () => {
renderForm(null, readOnlyValidationForm);
});

const visitPunctualityTextbox = screen.getByLabelText(/visit punctuality/i);
expect(visitPunctualityTextbox).toHaveAttribute('readonly');

const visitNotesTextbox = screen.getByLabelText(/visit notes/i);
expect(visitNotesTextbox).toHaveAttribute('readonly');
});
});

describe('Form view mode', () => {
it('should ensure that the form is not editable in 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');
});
Comment on lines +878 to +880
Copy link
Member

Choose a reason for hiding this comment

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

Can you also assert that the "Save" button is disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it on line 884


const interactiveElements = screen.queryAllByRole('textbox', { hidden: false });
expect(interactiveElements).toHaveLength(0);
expect(screen.queryByRole('button', { name: /save/i })).toBeDisabled();
});
});

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',
},
Comment on lines +130 to +138
Copy link
Member

Choose a reason for hiding this comment

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

Do you need this?

],
},
],
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',
},
Comment on lines +258 to +266
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-10-18 at 17 38 57

Removing this block brings this error

],
},
],
Expand Down