Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Oct 2, 2024
1 parent 557e72f commit 7a498c2
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 115 deletions.
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"
}
85 changes: 56 additions & 29 deletions src/form-engine.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -870,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 : 'edit'}
/>,
);
}
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

0 comments on commit 7a498c2

Please sign in to comment.