-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ent-registration-app/src/patient-registration/input/custom-input/identifier/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters