Skip to content

Commit

Permalink
(test) O3-2229: Add unit tests for utils.ts file (#747)
Browse files Browse the repository at this point in the history
* 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 <sharmava05@gmail.com>

* (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 <anjulashanaka@gmail.com>
Co-authored-by: Dennis Kigen <kigen.work@gmail.com>
Co-authored-by: CynthiaKamau <cynthiakamau54@gmail.com>
Co-authored-by: Donald Kibet <chelashawdonald@yahoo.com>
Co-authored-by: Jexsie <jessiessebuliba@gmail.com>
Co-authored-by: Vineet Sharma <sharmava05@gmail.com>
  • Loading branch information
7 people authored Jul 13, 2023
1 parent 88a04dc commit 49d5f69
Showing 1 changed file with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 49d5f69

Please sign in to comment.