-
Notifications
You must be signed in to change notification settings - Fork 21
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
1 parent
db9efd9
commit f9cc81c
Showing
3 changed files
with
305 additions
and
3 deletions.
There are no files selected for viewing
187 changes: 187 additions & 0 deletions
187
packages/fhir-group-management/src/components/LocationInventory/tests/fixtures.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,187 @@ | ||
import { IValueSet } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IValueSet'; | ||
import dayjs from 'dayjs'; | ||
|
||
export const productQuantity = 32; | ||
export const mockResourceId = '67bb848e-f049-41f4-9c75-3b726664db67'; | ||
|
||
export const unicefValuesetConcept = { | ||
system: 'http://smartregister.org/CodeSystem/eusm-unicef-sections', | ||
code: 'ANC.End.26', | ||
display: 'No complications', | ||
}; | ||
|
||
export const donorValuesetConcept = { | ||
system: 'http://smartregister.org/CodeSystem/eusm-donors', | ||
code: 'ANC.donor', | ||
display: 'Donor', | ||
}; | ||
|
||
export const expandedValueSets = { | ||
resourceType: 'ValueSet', | ||
id: '2826', | ||
url: 'http://fhir.org/guides/who/anc-cds/ValueSet/anc-end-26', | ||
status: 'active', | ||
compose: { | ||
include: [ | ||
{ | ||
system: 'http://smartregister.org/CodeSystem/eusm-unicef-sections', | ||
concept: [ | ||
{ | ||
code: 'ANC.End.26', | ||
display: 'No complications', | ||
}, | ||
{ | ||
code: 'ANC.End.27', | ||
display: 'Postpartum haemorrhage', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
expansion: { | ||
offset: 0, | ||
parameter: [ | ||
{ | ||
name: 'offset', | ||
valueInteger: 0, | ||
}, | ||
{ | ||
name: 'count', | ||
valueInteger: 1000, | ||
}, | ||
], | ||
contains: [unicefValuesetConcept], | ||
}, | ||
} as IValueSet; | ||
|
||
export const productCharacteristics = [ | ||
{ | ||
code: { | ||
coding: [ | ||
{ | ||
code: '98734231', | ||
display: 'Unicef Section', | ||
system: 'http://smartregister.org/codes', | ||
}, | ||
], | ||
}, | ||
valueCodeableConcept: { | ||
coding: [ | ||
{ | ||
code: 'ANC.End.26', | ||
display: 'No complications', | ||
system: 'http://smartregister.org/CodeSystem/eusm-unicef-sections', | ||
}, | ||
], | ||
text: 'No complications', | ||
}, | ||
}, | ||
{ | ||
code: { | ||
coding: [ | ||
{ | ||
code: '45981276', | ||
display: 'Donor', | ||
system: 'http://smartregister.org/codes', | ||
}, | ||
], | ||
}, | ||
valueCodeableConcept: { | ||
coding: [ | ||
{ | ||
code: 'ANC.donor', | ||
display: 'Donor', | ||
system: 'http://smartregister.org/CodeSystem/eusm-donors', | ||
}, | ||
], | ||
text: 'Donor', | ||
}, | ||
}, | ||
{ | ||
code: { | ||
coding: [ | ||
{ | ||
code: '33467722', | ||
display: 'Quantity ', | ||
system: 'http://smartregister.org/codes', | ||
}, | ||
], | ||
}, | ||
valueQuantity: { | ||
value: productQuantity, | ||
}, | ||
}, | ||
]; | ||
|
||
export const formValues = { | ||
product: '6f3980e0-d1d6-4a7a-a950-939f3ca7b301', | ||
quantity: productQuantity, | ||
deliveryDate: dayjs('2024-03-25T08:24:51.149Z'), | ||
accountabilityEndDate: dayjs('2024-03-26T08:24:53.645Z'), | ||
unicefSection: | ||
'{"code":"ANC.End.26","display":"No complications","system":"http://smartregister.org/CodeSystem/eusm-unicef-sections"}', | ||
donor: | ||
'{"code":"ANC.donor","display":"Donor","system":"http://smartregister.org/CodeSystem/eusm-donors"}', | ||
poNumber: '12345', | ||
serialNumber: '890', | ||
}; | ||
|
||
export const locationResourcePayload = { | ||
resourceType: 'Group', | ||
id: mockResourceId, | ||
active: true, | ||
actual: false, | ||
type: 'substance', | ||
identifier: [ | ||
{ | ||
use: 'secondary', | ||
type: { | ||
coding: [ | ||
{ | ||
system: 'http://smartregister.org/codes', | ||
code: 'PONUM', | ||
display: 'PO Number', | ||
}, | ||
], | ||
text: 'PO Number', | ||
}, | ||
value: '12345', | ||
}, | ||
{ | ||
type: { | ||
coding: [ | ||
{ | ||
code: 'SERNUM', | ||
display: 'Serial Number', | ||
system: 'http://smartregister.org/codes', | ||
}, | ||
], | ||
text: 'Serial Number', | ||
}, | ||
use: 'official', | ||
value: '890', | ||
}, | ||
], | ||
member: [ | ||
{ | ||
entity: { | ||
reference: 'Group/6f3980e0-d1d6-4a7a-a950-939f3ca7b301', | ||
}, | ||
period: { | ||
start: '2024-03-25T08:24:51.149Z', | ||
end: '2024-03-26T08:24:53.645Z', | ||
}, | ||
inactive: false, | ||
}, | ||
], | ||
characteristic: productCharacteristics, | ||
code: { | ||
coding: [ | ||
{ | ||
system: 'http://smartregister.org/codes', | ||
code: '78991122', | ||
display: 'Supply Inventory', | ||
}, | ||
], | ||
}, | ||
}; |
115 changes: 115 additions & 0 deletions
115
packages/fhir-group-management/src/components/LocationInventory/tests/utils.test.tsx
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,115 @@ | ||
import { | ||
handleDisabledPastDates, | ||
handleDisabledFutureDates, | ||
getValuesetSelectOptions, | ||
isAttractiveProduct, | ||
productAccountabilityMonths, | ||
getMember, | ||
generateCharacteristics, | ||
getLocationInventoryPayload, | ||
} from '../utils'; | ||
import dayjs from 'dayjs'; | ||
import { | ||
expandedValueSets, | ||
unicefValuesetConcept, | ||
donorValuesetConcept, | ||
productCharacteristics, | ||
formValues, | ||
locationResourcePayload, | ||
mockResourceId, | ||
productQuantity, | ||
} from './fixtures'; | ||
import { commodity1 } from '../../CommodityAddEdit/Eusm/tests/fixtures'; | ||
import { attractiveCharacteristicCode } from '../../../helpers/utils'; | ||
|
||
jest.mock('uuid', () => { | ||
const actual = jest.requireActual('uuid'); | ||
return { | ||
...actual, | ||
v4: () => mockResourceId, | ||
}; | ||
}); | ||
|
||
describe('fhir-group-management/src/components/LocationInventory/utils', () => { | ||
it('handleDisabledPastDates and handleDisabledFutureDates works as expected', () => { | ||
const now = dayjs(); | ||
const future = now.add(2, 'day'); | ||
const past = now.subtract(2, 'day'); | ||
// handleDisabledPastDates | ||
expect(handleDisabledPastDates()).toEqual(false); | ||
expect(handleDisabledPastDates(now)).toEqual(false); | ||
expect(handleDisabledPastDates(future)).toEqual(false); | ||
expect(handleDisabledPastDates(past)).toEqual(true); | ||
// handleDisabledFutureDates | ||
expect(handleDisabledFutureDates()).toEqual(false); | ||
expect(handleDisabledFutureDates(now)).toEqual(true); | ||
expect(handleDisabledFutureDates(future)).toEqual(true); | ||
expect(handleDisabledFutureDates(past)).toEqual(false); | ||
}); | ||
|
||
it('getValuesetSelectOptions works as expected', () => { | ||
expect(getValuesetSelectOptions(expandedValueSets)).toEqual([ | ||
{ | ||
label: 'No complications', | ||
value: JSON.stringify({ | ||
code: 'ANC.End.26', | ||
display: 'No complications', | ||
system: 'http://smartregister.org/CodeSystem/eusm-unicef-sections', | ||
}), | ||
}, | ||
{ | ||
label: 'Postpartum haemorrhage', | ||
value: JSON.stringify({ | ||
code: 'ANC.End.27', | ||
display: 'Postpartum haemorrhage', | ||
system: 'http://smartregister.org/CodeSystem/eusm-unicef-sections', | ||
}), | ||
}, | ||
]); | ||
}); | ||
|
||
it('get attractive items works as expected', () => { | ||
const noAttractiveCharacteristic = commodity1.characteristic?.filter( | ||
(char) => char.code.coding?.[0].code !== attractiveCharacteristicCode | ||
); | ||
const newCommodity = { | ||
...commodity1, | ||
characteristic: noAttractiveCharacteristic, | ||
}; | ||
expect(isAttractiveProduct()).toEqual(false); | ||
expect(isAttractiveProduct(commodity1)).toEqual(true); | ||
expect(isAttractiveProduct(newCommodity)).toEqual(false); | ||
}); | ||
|
||
it('get item accounterbility months works as expected', () => { | ||
expect(productAccountabilityMonths()).toEqual(undefined); | ||
expect(productAccountabilityMonths(commodity1)).toEqual(12); | ||
}); | ||
|
||
it('get resource member works as expected', () => { | ||
const startDate = dayjs(); | ||
const endDate = dayjs().add(2, 'day'); | ||
expect(getMember('productId', startDate, endDate)).toEqual([ | ||
{ | ||
entity: { | ||
reference: 'Group/productId', | ||
}, | ||
period: { | ||
start: new Date(startDate.toDate()).toISOString(), | ||
end: new Date(endDate.toDate()).toISOString(), | ||
}, | ||
inactive: false, | ||
}, | ||
]); | ||
}); | ||
|
||
it('get resource characteristics works as expected', () => { | ||
expect( | ||
generateCharacteristics(unicefValuesetConcept, donorValuesetConcept, productQuantity) | ||
).toEqual(productCharacteristics); | ||
}); | ||
|
||
it('generate location inventory payload works as expected', () => { | ||
expect(getLocationInventoryPayload(formValues, false)).toEqual(locationResourcePayload); | ||
}); | ||
}); |
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