diff --git a/__mocks__/packages/hiv/forms/hts_poc/1.1.json b/__mocks__/packages/hiv/forms/hts_poc/1.1.json index 1696d0b47..92b251970 100644 --- a/__mocks__/packages/hiv/forms/hts_poc/1.1.json +++ b/__mocks__/packages/hiv/forms/hts_poc/1.1.json @@ -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" -} \ No newline at end of file + ] + } + ], + "availableIntents": ["HTS_RETROSPECTIVE", "HTS_HIVTEST", "*"], + "processor": "EncounterFormProcessor", + "uuid": "da24c540-cc83-43bc-978f-c1ef180a497f", + "referencedForms": [], + "encounterType": "79c1f50f-f77d-42e2-ad2a-d29304dde2fe" +} diff --git a/src/form-engine.test.tsx b/src/form-engine.test.tsx index 73ea0c978..dbc5779ad 100644 --- a/src/form-engine.test.tsx +++ b/src/form-engine.test.tsx @@ -44,6 +44,7 @@ import viralLoadStatusForm from '__mocks__/forms/rfe-forms/viral-load-status-for 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; @@ -216,33 +217,6 @@ 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 () => { @@ -870,7 +844,60 @@ 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( { patientUUID={patientUUID} formSessionIntent={intent} visit={visit} - mode="enter" + mode={mode ? mode : 'edit'} />, ); } diff --git a/src/utils/forms-loader.test.ts b/src/utils/forms-loader.test.ts index 3a30ce5f2..e96674555 100644 --- a/src/utils/forms-loader.test.ts +++ b/src/utils/forms-loader.test.ts @@ -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', + }, ], }, ], @@ -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', + }, ], }, ],