From 49d5f6902a251abc6a8558e725eede42b4d0dda7 Mon Sep 17 00:00:00 2001 From: Ayush <54752747+ayush-AI@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:05:58 +0530 Subject: [PATCH] (test) O3-2229: Add unit tests for utils.ts file (#747) * added test for utils.ts * resolved review commits * (feat) Remove filtering todays queue entries on frontend (#752) * (refactor): Display all active visits by removing filter for showing only today's active visits (#755) * (refactor): changed activeVisits.idNumber assignment for improved code robustness (#756) * (feat) O3-2100: Unknown patient name and estimated DOB config (#697) Co-authored-by: Vineet Sharma * (test) O3-2225/6: Add tests for cancel-patient-edit.component and delete-identifier-confirmation-modal (#750) * removed the extra types --------- Co-authored-by: Anjula Shanaka Co-authored-by: Dennis Kigen Co-authored-by: CynthiaKamau Co-authored-by: Donald Kibet Co-authored-by: Jexsie Co-authored-by: Vineet Sharma --- .../custom-input/identifier/utils.test.ts | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.test.ts diff --git a/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.test.ts b/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.test.ts new file mode 100644 index 000000000..5f3bd0c02 --- /dev/null +++ b/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.test.ts @@ -0,0 +1,81 @@ +import { isUniqueIdentifierTypeForOffline, shouldBlockPatientIdentifierInOfflineMode } from './utils'; + +interface IdentifierTypeOptions { + uniquenessBehavior?: 'UNIQUE' | 'LOCATION' | 'NON_UNIQUE'; + manualEntryEnabled?: boolean; + automaticGenerationEnabled?: boolean; +} + +function createIdentifierType(options: IdentifierTypeOptions) { + return { + uniquenessBehavior: options.uniquenessBehavior, + identifierSources: [ + { + uuid: 'identifier-source-uuid', + name: 'Identifier Source Name', + autoGenerationOption: { + manualEntryEnabled: options.manualEntryEnabled, + automaticGenerationEnabled: options.automaticGenerationEnabled, + }, + }, + ], + name: 'Identifier Type Name', + required: true, + uuid: 'identifier-type-uuid', + fieldName: 'identifierFieldName', + format: 'identifierFormat', + isPrimary: true, + }; +} + +describe('shouldBlockPatientIdentifierInOfflineMode function', () => { + it('should return false if identifierType is not unique', () => { + const identifierType = createIdentifierType({ uniquenessBehavior: null }); + + const result = shouldBlockPatientIdentifierInOfflineMode(identifierType); + + expect(result).toBe(false); + }); + + it('should return false if identifierType is unique and no manual entry is enabled', () => { + const identifierType = createIdentifierType({ uniquenessBehavior: null }); + + const result = shouldBlockPatientIdentifierInOfflineMode(identifierType); + + expect(result).toBe(false); + }); + + it('should return true if identifierType is unique and manual entry is enabled', () => { + const identifierType = createIdentifierType({ manualEntryEnabled: true, uniquenessBehavior: 'UNIQUE' }); + + const result = shouldBlockPatientIdentifierInOfflineMode(identifierType); + + expect(result).toBe(true); + }); +}); + +describe('isUniqueIdentifierTypeForOffline function', () => { + it('should return true if uniquenessBehavior is UNIQUE', () => { + const identifierType = createIdentifierType({ uniquenessBehavior: 'UNIQUE' }); + + const result = isUniqueIdentifierTypeForOffline(identifierType); + + expect(result).toBe(true); + }); + + it('should return true if uniquenessBehavior is LOCATION', () => { + const identifierType = createIdentifierType({ uniquenessBehavior: 'LOCATION' }); + + const result = isUniqueIdentifierTypeForOffline(identifierType); + + expect(result).toBe(true); + }); + + it('should return false for other uniqueness behaviors', () => { + const identifierType = createIdentifierType({ uniquenessBehavior: null }); + + const result = isUniqueIdentifierTypeForOffline(identifierType); + + expect(result).toBe(false); + }); +});