fhir-react 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.stylelintrc +6 -2
  4. package/README.md +19 -1
  5. package/build/index.js +15 -11
  6. package/build/style.css +7 -7
  7. package/package.json +55 -54
  8. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  9. package/src/assets/containers/Generic/generic.svg +3 -0
  10. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  11. package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
  12. package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
  13. package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
  14. package/src/components/containers/Accordion/Accordion.js +21 -13
  15. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  16. package/src/components/datatypes/Coding/Coding.js +7 -3
  17. package/src/components/datatypes/Reference/Reference.js +7 -5
  18. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  19. package/src/components/resources/AdverseEvent/AdverseEvent.js +81 -42
  20. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +12 -2
  21. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  22. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +7 -1
  23. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
  24. package/src/components/resources/Appointment/Appointment.js +2 -1
  25. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  26. package/src/components/resources/Bundle/Bundle.css +7 -0
  27. package/src/components/resources/Bundle/Bundle.js +15 -11
  28. package/src/components/resources/Bundle/Bundle.stories.js +12 -78
  29. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  30. package/src/components/resources/CarePlan/CarePlan.js +2 -1
  31. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  32. package/src/components/resources/CareTeam/CareTeam.js +72 -50
  33. package/src/components/resources/CareTeam/CareTeam.stories.js +20 -3
  34. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  35. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  36. package/src/components/resources/Claim/Claim.js +2 -1
  37. package/src/components/resources/Claim/Claim.test.js +32 -1
  38. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  39. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  40. package/src/components/resources/ClaimResponse/ClaimResponse.js +137 -83
  41. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +15 -2
  42. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  43. package/src/components/resources/ClaimResponse/Item.js +44 -9
  44. package/src/components/resources/ClaimResponse/Items.js +5 -4
  45. package/src/components/resources/Condition/Condition.js +3 -3
  46. package/src/components/resources/Condition/Condition.test.js +37 -4
  47. package/src/components/resources/Coverage/Coverage.js +2 -1
  48. package/src/components/resources/Coverage/Coverage.test.js +36 -1
  49. package/src/components/resources/Device/Device.js +2 -1
  50. package/src/components/resources/Device/Device.test.js +36 -1
  51. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +7 -2
  52. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
  53. package/src/components/resources/DocumentReference/DocumentReference.js +7 -2
  54. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  55. package/src/components/resources/Encounter/Encounter.js +2 -1
  56. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  57. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +2 -0
  58. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  59. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +7 -2
  60. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  61. package/src/components/resources/Generic/Generic.js +20 -7
  62. package/src/components/resources/Generic/Generic.stories.js +2 -1
  63. package/src/components/resources/Generic/Generic.test.js +26 -7
  64. package/src/components/resources/Goal/Goal.js +2 -3
  65. package/src/components/resources/Goal/Goal.test.js +32 -1
  66. package/src/components/resources/Immunization/Immunization.js +2 -2
  67. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  68. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  69. package/src/components/resources/List/Entries.js +3 -3
  70. package/src/components/resources/List/List.js +135 -88
  71. package/src/components/resources/List/List.stories.js +38 -5
  72. package/src/components/resources/List/List.test.js +105 -1
  73. package/src/components/resources/Location/Location.js +65 -47
  74. package/src/components/resources/Location/Location.stories.js +11 -4
  75. package/src/components/resources/Location/Location.test.js +106 -4
  76. package/src/components/resources/Medication/Medication.js +2 -1
  77. package/src/components/resources/Medication/Medication.test.js +36 -1
  78. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +86 -62
  79. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +7 -0
  80. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  81. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  82. package/src/components/resources/MedicationDispense/MedicationDispense.js +68 -68
  83. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +7 -0
  84. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  85. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +115 -66
  86. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +6 -0
  87. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  88. package/src/components/resources/MedicationOrder/MedicationOrder.js +2 -3
  89. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  90. package/src/components/resources/MedicationRequest/MedicationRequest.js +2 -1
  91. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  92. package/src/components/resources/MedicationStatement/MedicationStatement.js +7 -2
  93. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  94. package/src/components/resources/Observation/Observation.js +2 -1
  95. package/src/components/resources/Observation/Observation.test.js +30 -1
  96. package/src/components/resources/Organization/Organization.js +3 -2
  97. package/src/components/resources/Organization/Organization.test.js +36 -1
  98. package/src/components/resources/Patient/Patient.js +2 -0
  99. package/src/components/resources/Patient/Patient.test.js +31 -2
  100. package/src/components/resources/Practitioner/Practitioner.js +2 -1
  101. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  102. package/src/components/resources/PractitionerRole/PractitionerRole.js +50 -29
  103. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +7 -0
  104. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  105. package/src/components/resources/Procedure/Procedure.js +2 -2
  106. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  107. package/src/components/resources/Questionnaire/Group.js +53 -0
  108. package/src/components/resources/Questionnaire/Items.js +45 -0
  109. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  110. package/src/components/resources/Questionnaire/Questionnaire.js +31 -170
  111. package/src/components/resources/Questionnaire/Questionnaire.stories.js +8 -0
  112. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  113. package/src/components/resources/Questionnaire/Questions.js +40 -0
  114. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  115. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  116. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  117. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  118. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  119. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +52 -236
  120. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +8 -0
  121. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  122. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  123. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  124. package/src/components/resources/ReferralRequest/ReferralRequest.js +65 -40
  125. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  126. package/src/components/resources/RelatedPerson/RelatedPerson.js +151 -0
  127. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +46 -0
  128. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  129. package/src/components/resources/RelatedPerson/index.js +3 -0
  130. package/src/components/resources/ResearchStudy/ResearchStudy.js +160 -130
  131. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +2 -0
  132. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  133. package/src/components/ui/index.js +22 -9
  134. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  135. package/src/fixtures/example-icons.jsx +42 -0
  136. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  137. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  138. package/src/style.scss +3 -1
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
 
4
4
  import MedicationAdministration from './MedicationAdministration';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -7,8 +7,89 @@ import dstu2Example1 from '../../../fixtures/dstu2/resources/medicationAdministr
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/medicationAdministration/example1.json';
8
8
  import r4Example1 from '../../../fixtures/r4/resources/medicationAdministration/example1.json';
9
9
  import r4Example2 from '../../../fixtures/r4/resources/medicationAdministration/example3.json';
10
+ import fhirIcons from '../../../fixtures/example-icons';
10
11
 
11
12
  describe('should render MedicationAdministration component properly', () => {
13
+ it('component without a fhirIcons props should render a default icon', () => {
14
+ const defaultProps = {
15
+ fhirVersion: fhirVersions.DSTU2,
16
+ fhirResource: dstu2Example1,
17
+ };
18
+
19
+ const { getByAltText } = render(
20
+ <MedicationAdministration {...defaultProps} />,
21
+ );
22
+ const headerIcon = getByAltText('medication administration');
23
+
24
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
25
+ });
26
+
27
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
28
+ const defaultProps = {
29
+ fhirVersion: fhirVersions.DSTU2,
30
+ fhirResource: dstu2Example1,
31
+ fhirIcons: false,
32
+ };
33
+
34
+ const { getByTestId } = render(
35
+ <MedicationAdministration {...defaultProps} />,
36
+ );
37
+ const headerIcon = getByTestId('placeholder');
38
+
39
+ expect(headerIcon).toBeTruthy();
40
+ });
41
+
42
+ it('component with the img as a fhirIcons props should render an img', () => {
43
+ const defaultProps = {
44
+ fhirVersion: fhirVersions.DSTU2,
45
+ fhirResource: dstu2Example1,
46
+ fhirIcons: (
47
+ <img
48
+ src={require('../assets/containers/MedicationAdministration/medication-administration.svg')}
49
+ alt="pill gets swallowed"
50
+ />
51
+ ),
52
+ };
53
+
54
+ const { getByAltText } = render(
55
+ <MedicationAdministration {...defaultProps} />,
56
+ );
57
+ const headerIcon = getByAltText('pill gets swallowed');
58
+
59
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
60
+ });
61
+
62
+ it('component with the resources object as a fhirIcons props should render an img', () => {
63
+ const defaultProps = {
64
+ fhirVersion: fhirVersions.DSTU2,
65
+ fhirResource: dstu2Example1,
66
+ fhirIcons: fhirIcons,
67
+ };
68
+
69
+ const { getByAltText } = render(
70
+ <MedicationAdministration {...defaultProps} />,
71
+ );
72
+ const headerIcon = getByAltText('pill gets swallowed');
73
+
74
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
75
+ });
76
+
77
+ it('component with the url as a fhirIcons props should render an img', () => {
78
+ const avatarSrc =
79
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
80
+ const defaultProps = {
81
+ fhirVersion: fhirVersions.DSTU2,
82
+ fhirResource: dstu2Example1,
83
+ fhirIcons: avatarSrc,
84
+ };
85
+
86
+ const { getByAltText } = render(
87
+ <MedicationAdministration {...defaultProps} />,
88
+ );
89
+ const headerIcon = getByAltText('header icon');
90
+
91
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
92
+ });
12
93
  it('should render with DSTU2 source data', () => {
13
94
  const defaultProps = {
14
95
  fhirResource: dstu2Example1,
@@ -108,4 +189,39 @@ describe('should render MedicationAdministration component properly', () => {
108
189
  expect(getByTestId('dosageRoute').textContent).toContain('Oral Route');
109
190
  expect(getByTestId('dosageQuantity').textContent).toEqual('2 TAB');
110
191
  });
192
+
193
+ it('should fire custom onClick function', () => {
194
+ const defaultProps = {
195
+ fhirResource: r4Example2,
196
+ fhirVersion: fhirVersions.R4,
197
+ };
198
+
199
+ const onClick = jest.fn();
200
+ const { getByRole } = render(
201
+ <MedicationAdministration {...defaultProps} onClick={onClick} />,
202
+ );
203
+ const accordion = getByRole('button');
204
+ fireEvent.click(accordion);
205
+
206
+ const attribute = accordion.getAttribute('data-bs-toggle');
207
+ expect(attribute).not.toEqual('collapse');
208
+ expect(onClick).toHaveBeenCalled();
209
+ });
210
+
211
+ it('should not fire custom onClick function', () => {
212
+ const defaultProps = {
213
+ fhirResource: r4Example2,
214
+ fhirVersion: fhirVersions.R4,
215
+ };
216
+
217
+ const onClick = 'test';
218
+ const { getByRole } = render(
219
+ <MedicationAdministration {...defaultProps} onClick={onClick} />,
220
+ );
221
+ const accordion = getByRole('button');
222
+ fireEvent.click(accordion);
223
+
224
+ const attribute = accordion.getAttribute('data-bs-toggle');
225
+ expect(attribute).toEqual('collapse');
226
+ });
111
227
  });
@@ -0,0 +1,25 @@
1
+ import { MissingValue, TableCell, TableRow } from '../../ui';
2
+ import CodeableConcept from '../../datatypes/CodeableConcept';
3
+ import React from 'react';
4
+
5
+ const DosageInstruction = props => {
6
+ const empty = <MissingValue />;
7
+ const {
8
+ timing = empty,
9
+ route = empty,
10
+ doseQuantity = empty,
11
+ additionalInstructions = empty,
12
+ } = props.item;
13
+ return (
14
+ <TableRow>
15
+ <TableCell data-testid="dosageTiming">{timing}</TableCell>
16
+ <TableCell data-testid="dosageRoute">{route}</TableCell>
17
+ <TableCell data-testid="dosageQuantity">{doseQuantity}</TableCell>
18
+ <TableCell data-testid="dosageAdditionalInstructions">
19
+ <CodeableConcept fhirData={additionalInstructions} />
20
+ </TableCell>
21
+ </TableRow>
22
+ );
23
+ };
24
+
25
+ export default DosageInstruction;
@@ -9,37 +9,14 @@ import fhirVersions from '../fhirResourceVersions';
9
9
  import {
10
10
  Root,
11
11
  Header,
12
- Title,
13
12
  Body,
14
- Value,
15
13
  ValueSection,
16
14
  Table,
17
15
  TableHeader,
18
- TableCell,
19
16
  TableRow,
20
- MissingValue,
21
17
  } from '../../ui';
22
- import CodeableConcept from '../../datatypes/CodeableConcept/CodeableConcept';
23
-
24
- const DosageInstruction = props => {
25
- const empty = <MissingValue />;
26
- const {
27
- timing = empty,
28
- route = empty,
29
- doseQuantity = empty,
30
- additionalInstructions = empty,
31
- } = props.item;
32
- return (
33
- <TableRow>
34
- <TableCell data-testid="dosageTiming">{timing}</TableCell>
35
- <TableCell data-testid="dosageRoute">{route}</TableCell>
36
- <TableCell data-testid="dosageQuantity">{doseQuantity}</TableCell>
37
- <TableCell data-testid="dosageAdditionalInstructions">
38
- <CodeableConcept fhirData={additionalInstructions} />
39
- </TableCell>
40
- </TableRow>
41
- );
42
- };
18
+ import Accordion from '../../containers/Accordion';
19
+ import DosageInstruction from './DosageInstruction';
43
20
 
44
21
  const commonDTO = fhirResource => {
45
22
  const typeCoding = _get(fhirResource, 'type.coding.0');
@@ -182,8 +159,12 @@ const resourceDTO = (fhirVersion, fhirResource) => {
182
159
  }
183
160
  };
184
161
 
185
- const MedicationDispense = props => {
186
- const { fhirResource, fhirVersion } = props;
162
+ const MedicationDispense = ({
163
+ fhirResource,
164
+ fhirVersion,
165
+ fhirIcons,
166
+ onClick,
167
+ }) => {
187
168
  let fhirResourceData = {};
188
169
  try {
189
170
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -201,49 +182,68 @@ const MedicationDispense = props => {
201
182
  whenPrepared,
202
183
  } = fhirResourceData;
203
184
 
185
+ const tableData = [
186
+ {
187
+ label: 'Medication',
188
+ testId: 'medicationCoding',
189
+ data: medicationCoding && <Coding fhirData={medicationCoding} />,
190
+ status: medicationCoding,
191
+ },
192
+ {
193
+ label: 'Prepared',
194
+ testId: 'whenPrepared',
195
+ data: whenPrepared && <Date fhirData={whenPrepared} isBlack />,
196
+ status: whenPrepared,
197
+ },
198
+ {
199
+ label: 'Type',
200
+ testId: 'typeCoding',
201
+ data: typeCoding && <Coding fhirData={typeCoding} />,
202
+ status: typeCoding,
203
+ },
204
+ ];
205
+
204
206
  return (
205
207
  <Root name="MedicationDispense">
206
- {medicationTitle && (
207
- <Header>
208
- <Title>{medicationTitle}</Title>
209
- </Header>
210
- )}
211
- <Body>
212
- {medicationCoding && (
213
- <Value label="Medication" data-testid="medicationCoding">
214
- <Coding fhirData={medicationCoding} />
215
- </Value>
216
- )}
217
- {whenPrepared && (
218
- <Value label="Prepared" data-testid="whenPrepared">
219
- <Date fhirData={whenPrepared} />
220
- </Value>
221
- )}
222
- {typeCoding && (
223
- <Value label="Type" data-testid="typeCoding">
224
- <Coding fhirData={typeCoding} />
225
- </Value>
226
- )}
227
- {hasDosageInstruction && (
228
- <ValueSection label="Dosage instruction">
229
- <Table>
230
- <thead>
231
- <TableRow>
232
- <TableHeader>Timing</TableHeader>
233
- <TableHeader>Route</TableHeader>
234
- <TableHeader>Dose quantity</TableHeader>
235
- <TableHeader>Additional instructions</TableHeader>
236
- </TableRow>
237
- </thead>
238
- <tbody data-testid="hasDosageInstruction">
239
- {dosageInstructionData.map((item, i) => (
240
- <DosageInstruction key={`item-${i}`} item={item} />
241
- ))}
242
- </tbody>
243
- </Table>
244
- </ValueSection>
245
- )}
246
- </Body>
208
+ <Accordion
209
+ headerContent={
210
+ <Header
211
+ resourceName="MedicationDispense"
212
+ title={medicationTitle}
213
+ icon={fhirIcons}
214
+ />
215
+ }
216
+ bodyContent={
217
+ <Body tableData={tableData}>
218
+ {hasDosageInstruction && (
219
+ <ValueSection
220
+ label="Dosage instruction"
221
+ marginTop={medicationCoding || whenPrepared || typeCoding}
222
+ >
223
+ <Table>
224
+ <thead>
225
+ <TableRow>
226
+ <TableHeader>Timing</TableHeader>
227
+ <TableHeader>Route</TableHeader>
228
+ <TableHeader>Dose quantity</TableHeader>
229
+ <TableHeader>Additional instructions</TableHeader>
230
+ </TableRow>
231
+ </thead>
232
+ <tbody
233
+ data-testid="hasDosageInstruction"
234
+ className="border-top-0"
235
+ >
236
+ {dosageInstructionData.map((item, i) => (
237
+ <DosageInstruction key={`item-${i}`} item={item} />
238
+ ))}
239
+ </tbody>
240
+ </Table>
241
+ </ValueSection>
242
+ )}
243
+ </Body>
244
+ }
245
+ onClick={onClick}
246
+ />
247
247
  </Root>
248
248
  );
249
249
  };
@@ -10,6 +10,8 @@ import stu3Example1 from '../../../fixtures/stu3/resources/medicationDispense/ex
10
10
  import stu3Example2 from '../../../fixtures/stu3/resources/medicationDispense/example2.json';
11
11
  import R4Example1 from '../../../fixtures/r4/resources/medicationDispense/example1.json';
12
12
  import R4Example2 from '../../../fixtures/r4/resources/medicationDispense/example2.json';
13
+ import fhirIcons from '../../../fixtures/example-icons';
14
+ import MedicationDispenseIcon from '../../../assets/containers/MedicationDispense/medication-dispense.svg';
13
15
 
14
16
  export default {
15
17
  title: 'MedicationDispense',
@@ -21,6 +23,7 @@ export const DefaultVisualizationDSTU2 = () => {
21
23
  <MedicationDispense
22
24
  fhirResource={fhirResource}
23
25
  fhirVersion={fhirVersions.DSTU2}
26
+ fhirIcons={require('../../../assets/containers/MedicationDispense/medication-dispense.svg')}
24
27
  />
25
28
  );
26
29
  };
@@ -31,6 +34,7 @@ export const Example2OfDSTU2 = () => {
31
34
  <MedicationDispense
32
35
  fhirResource={fhirResource}
33
36
  fhirVersion={fhirVersions.DSTU2}
37
+ fhirIcons={MedicationDispenseIcon}
34
38
  />
35
39
  );
36
40
  };
@@ -41,6 +45,7 @@ export const Example1OfSTU3 = () => {
41
45
  <MedicationDispense
42
46
  fhirResource={fhirResource}
43
47
  fhirVersion={fhirVersions.STU3}
48
+ fhirIcons={fhirIcons}
44
49
  />
45
50
  );
46
51
  };
@@ -51,6 +56,7 @@ export const Example2OfSTU3 = () => {
51
56
  <MedicationDispense
52
57
  fhirResource={fhirResource}
53
58
  fhirVersion={fhirVersions.STU3}
59
+ fhirIcons={false}
54
60
  />
55
61
  );
56
62
  };
@@ -61,6 +67,7 @@ export const Example1OfR4 = () => {
61
67
  <MedicationDispense
62
68
  fhirResource={fhirResource}
63
69
  fhirVersion={fhirVersions.R4}
70
+ fhirIcons={'random text'}
64
71
  />
65
72
  );
66
73
  };
@@ -1,13 +1,85 @@
1
1
  import React from 'react';
2
- import { render, within } from '@testing-library/react';
2
+ import { fireEvent, render, within } from '@testing-library/react';
3
3
  import MedicationDispense from './MedicationDispense';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import dstu2Example1 from '../../../fixtures/dstu2/resources/medicationDispense/example1.json';
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/medicationDispense/example1.json';
8
8
  import R4Example2 from '../../../fixtures/r4/resources/medicationDispense/example2.json';
9
+ import fhirIcons from '../../../fixtures/example-icons';
9
10
 
10
11
  describe('should render Device component properly', () => {
12
+ it('component without a fhirIcons props should render a default icon', () => {
13
+ const defaultProps = {
14
+ fhirVersion: fhirVersions.DSTU2,
15
+ fhirResource: dstu2Example1,
16
+ };
17
+
18
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
19
+ const headerIcon = getByAltText('medication dispense');
20
+
21
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
22
+ });
23
+
24
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
25
+ const defaultProps = {
26
+ fhirVersion: fhirVersions.DSTU2,
27
+ fhirResource: dstu2Example1,
28
+ fhirIcons: false,
29
+ };
30
+
31
+ const { getByTestId } = render(<MedicationDispense {...defaultProps} />);
32
+ const headerIcon = getByTestId('placeholder');
33
+
34
+ expect(headerIcon).toBeTruthy();
35
+ });
36
+
37
+ it('component with the img as a fhirIcons props should render an img', () => {
38
+ const defaultProps = {
39
+ fhirVersion: fhirVersions.DSTU2,
40
+ fhirResource: dstu2Example1,
41
+ fhirIcons: (
42
+ <img
43
+ src={require('../assets/containers/MedicationDispense/medication-dispense.svg')}
44
+ alt="medication dispense"
45
+ />
46
+ ),
47
+ };
48
+
49
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
50
+ const headerIcon = getByAltText('medication dispense');
51
+
52
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
53
+ });
54
+
55
+ it('component with the resources object as a fhirIcons props should render an img', () => {
56
+ const defaultProps = {
57
+ fhirVersion: fhirVersions.DSTU2,
58
+ fhirResource: dstu2Example1,
59
+ fhirIcons: fhirIcons,
60
+ };
61
+
62
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
63
+ const headerIcon = getByAltText('medication dispense');
64
+
65
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
66
+ });
67
+
68
+ it('component with the url as a fhirIcons props should render an img', () => {
69
+ const avatarSrc =
70
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
71
+ const defaultProps = {
72
+ fhirVersion: fhirVersions.DSTU2,
73
+ fhirResource: dstu2Example1,
74
+ fhirIcons: avatarSrc,
75
+ };
76
+
77
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
78
+ const headerIcon = getByAltText('header icon');
79
+
80
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
81
+ });
82
+
11
83
  it('should render with DSTU2 source data', () => {
12
84
  const defaultProps = {
13
85
  fhirResource: dstu2Example1,
@@ -84,4 +156,39 @@ describe('should render Device component properly', () => {
84
156
  ),
85
157
  ).toEqual(['Ordered(ordered)', 'Ordered(ordered)', 'Ordered(ordered)']);
86
158
  });
159
+
160
+ it('should fire custom onClick function', () => {
161
+ const defaultProps = {
162
+ fhirResource: R4Example2,
163
+ fhirVersion: fhirVersions.R4,
164
+ };
165
+
166
+ const onClick = jest.fn();
167
+ const { getByRole } = render(
168
+ <MedicationDispense {...defaultProps} onClick={onClick} />,
169
+ );
170
+ const accordion = getByRole('button');
171
+ fireEvent.click(accordion);
172
+
173
+ const attribute = accordion.getAttribute('data-bs-toggle');
174
+ expect(attribute).not.toEqual('collapse');
175
+ expect(onClick).toHaveBeenCalled();
176
+ });
177
+
178
+ it('should not fire custom onClick function', () => {
179
+ const defaultProps = {
180
+ fhirResource: R4Example2,
181
+ fhirVersion: fhirVersions.R4,
182
+ };
183
+
184
+ const onClick = 'test';
185
+ const { getByRole } = render(
186
+ <MedicationDispense {...defaultProps} onClick={onClick} />,
187
+ );
188
+ const accordion = getByRole('button');
189
+ fireEvent.click(accordion);
190
+
191
+ const attribute = accordion.getAttribute('data-bs-toggle');
192
+ expect(attribute).toEqual('collapse');
193
+ });
87
194
  });