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,12 +1,84 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
  import AdverseEvent from './AdverseEvent';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import stu3Example1 from '../../../fixtures/stu3/resources/adverseEvent/example1.json';
7
7
  import r4Example1 from '../../../fixtures/r4/resources/adverseEvent/example1.json';
8
+ import fhirIcons from '../../../fixtures/example-icons';
8
9
 
9
10
  describe('should render component correctly', () => {
11
+ it('component without a fhirIcons props should render a default icon', () => {
12
+ const defaultProps = {
13
+ fhirVersion: fhirVersions.STU3,
14
+ fhirResource: stu3Example1,
15
+ };
16
+
17
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
18
+ const headerIcon = getByAltText('adverse event');
19
+
20
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
21
+ });
22
+
23
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
24
+ const defaultProps = {
25
+ fhirVersion: fhirVersions.STU3,
26
+ fhirResource: stu3Example1,
27
+ fhirIcons: false,
28
+ };
29
+
30
+ const { getByTestId } = render(<AdverseEvent {...defaultProps} />);
31
+ const headerIcon = getByTestId('placeholder');
32
+
33
+ expect(headerIcon).toBeTruthy();
34
+ });
35
+
36
+ it('component with the img as a fhirIcons props should render an img', () => {
37
+ const defaultProps = {
38
+ fhirVersion: fhirVersions.STU3,
39
+ fhirResource: stu3Example1,
40
+ fhirIcons: (
41
+ <img
42
+ src={require('../assets/containers/AdverseEvent/adverse-event.svg')}
43
+ alt="adverse event"
44
+ />
45
+ ),
46
+ };
47
+
48
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
49
+ const headerIcon = getByAltText('adverse event');
50
+
51
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
52
+ });
53
+
54
+ it('component with the resources object as a fhirIcons props should render an img', () => {
55
+ const defaultProps = {
56
+ fhirVersion: fhirVersions.STU3,
57
+ fhirResource: stu3Example1,
58
+ fhirIcons: fhirIcons,
59
+ };
60
+
61
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
62
+ const headerIcon = getByAltText('adverse event');
63
+
64
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
65
+ });
66
+
67
+ it('component with the url as a fhirIcons props should render an img', () => {
68
+ const avatarSrc =
69
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
70
+ const defaultProps = {
71
+ fhirVersion: fhirVersions.STU3,
72
+ fhirResource: stu3Example1,
73
+ fhirIcons: avatarSrc,
74
+ };
75
+
76
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
77
+ const headerIcon = getByAltText('header icon');
78
+
79
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
80
+ });
81
+
10
82
  it('should render with STU3 source data', () => {
11
83
  const defaultProps = {
12
84
  fhirResource: stu3Example1,
@@ -18,7 +90,7 @@ describe('should render component correctly', () => {
18
90
 
19
91
  expect(getByTestId('date').textContent).toEqual('1/29/2017');
20
92
 
21
- expect(getByTestId('type').textContent).toContain('304386008');
93
+ expect(getByTestId('event').textContent).toContain('304386008');
22
94
 
23
95
  expect(getByTestId('description').textContent).toContain(
24
96
  'This was a mild rash',
@@ -44,4 +116,39 @@ describe('should render component correctly', () => {
44
116
 
45
117
  expect(getByTestId('actuality').textContent).toEqual('actual');
46
118
  });
119
+
120
+ it('should fire custom onClick function', () => {
121
+ const defaultProps = {
122
+ fhirResource: r4Example1,
123
+ fhirVersion: fhirVersions.R4,
124
+ };
125
+
126
+ const onClick = jest.fn();
127
+ const { getByRole } = render(
128
+ <AdverseEvent {...defaultProps} onClick={onClick} />,
129
+ );
130
+ const accordion = getByRole('button');
131
+ fireEvent.click(accordion);
132
+
133
+ const attribute = accordion.getAttribute('data-bs-toggle');
134
+ expect(attribute).not.toEqual('collapse');
135
+ expect(onClick).toHaveBeenCalled();
136
+ });
137
+
138
+ it('should not fire custom onClick function', () => {
139
+ const defaultProps = {
140
+ fhirResource: r4Example1,
141
+ fhirVersion: fhirVersions.R4,
142
+ };
143
+
144
+ const onClick = 'test';
145
+ const { getByRole } = render(
146
+ <AdverseEvent {...defaultProps} onClick={onClick} />,
147
+ );
148
+ const accordion = getByRole('button');
149
+ fireEvent.click(accordion);
150
+
151
+ const attribute = accordion.getAttribute('data-bs-toggle');
152
+ expect(attribute).toEqual('collapse');
153
+ });
47
154
  });
@@ -123,7 +123,12 @@ const resourceDTO = (fhirVersion, fhirResource) => {
123
123
  }
124
124
  };
125
125
 
126
- const AllergyIntolerance = ({ fhirResource, fhirVersion, fhirIcons }) => {
126
+ const AllergyIntolerance = ({
127
+ fhirResource,
128
+ fhirVersion,
129
+ fhirIcons,
130
+ onClick,
131
+ }) => {
127
132
  let fhirResourceData = {};
128
133
  try {
129
134
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -231,6 +236,7 @@ const AllergyIntolerance = ({ fhirResource, fhirVersion, fhirIcons }) => {
231
236
  />
232
237
  }
233
238
  bodyContent={<Body tableData={tableData} />}
239
+ onClick={onClick}
234
240
  />
235
241
  </Root>
236
242
  );
@@ -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
  import AllergyIntolerance from './AllergyIntolerance';
4
4
 
5
5
  import exampleAllergyIntoleranceDSTU2 from '../../../fixtures/dstu2/resources/allergyIntolerance/example1.json';
@@ -201,4 +201,39 @@ describe('should render component correctly', () => {
201
201
 
202
202
  expect(queryByTestId('asserter')).toBeNull();
203
203
  });
204
+
205
+ it('should fire custom onClick function', () => {
206
+ const defaultProps = {
207
+ fhirResource: example2AllergyIntoleranceR4,
208
+ fhirVersion: fhirVersions.R4,
209
+ };
210
+
211
+ const onClick = jest.fn();
212
+ const { getByRole } = render(
213
+ <AllergyIntolerance {...defaultProps} onClick={onClick} />,
214
+ );
215
+ const accordion = getByRole('button');
216
+ fireEvent.click(accordion);
217
+
218
+ const attribute = accordion.getAttribute('data-bs-toggle');
219
+ expect(attribute).not.toEqual('collapse');
220
+ expect(onClick).toHaveBeenCalled();
221
+ });
222
+
223
+ it('should not fire custom onClick function', () => {
224
+ const defaultProps = {
225
+ fhirResource: example2AllergyIntoleranceR4,
226
+ fhirVersion: fhirVersions.R4,
227
+ };
228
+
229
+ const onClick = 'test';
230
+ const { getByRole } = render(
231
+ <AllergyIntolerance {...defaultProps} onClick={onClick} />,
232
+ );
233
+ const accordion = getByRole('button');
234
+ fireEvent.click(accordion);
235
+
236
+ const attribute = accordion.getAttribute('data-bs-toggle');
237
+ expect(attribute).toEqual('collapse');
238
+ });
204
239
  });
@@ -144,7 +144,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
144
144
  }
145
145
  };
146
146
 
147
- const Appointment = ({ fhirResource, fhirVersion, fhirIcons }) => {
147
+ const Appointment = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
148
148
  const {
149
149
  description,
150
150
  status,
@@ -253,6 +253,7 @@ const Appointment = ({ fhirResource, fhirVersion, fhirIcons }) => {
253
253
  )}
254
254
  </Body>
255
255
  }
256
+ onClick={onClick}
256
257
  />
257
258
  </Root>
258
259
  );
@@ -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
  import Appointment from './Appointment';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -231,4 +231,39 @@ describe('should render component correctly', () => {
231
231
 
232
232
  expect(getByTestId('reason').textContent).toContain('Clinical Review');
233
233
  });
234
+
235
+ it('should fire custom onClick function', () => {
236
+ const defaultProps = {
237
+ fhirResource: example3AppointmentR4,
238
+ fhirVersion: fhirVersions.R4,
239
+ };
240
+
241
+ const onClick = jest.fn();
242
+ const { getByRole } = render(
243
+ <Appointment {...defaultProps} onClick={onClick} />,
244
+ );
245
+ const accordion = getByRole('button');
246
+ fireEvent.click(accordion);
247
+
248
+ const attribute = accordion.getAttribute('data-bs-toggle');
249
+ expect(attribute).not.toEqual('collapse');
250
+ expect(onClick).toHaveBeenCalled();
251
+ });
252
+
253
+ it('should not fire custom onClick function', () => {
254
+ const defaultProps = {
255
+ fhirResource: example3AppointmentR4,
256
+ fhirVersion: fhirVersions.R4,
257
+ };
258
+
259
+ const onClick = 'test';
260
+ const { getByRole } = render(
261
+ <Appointment {...defaultProps} onClick={onClick} />,
262
+ );
263
+ const accordion = getByRole('button');
264
+ fireEvent.click(accordion);
265
+
266
+ const attribute = accordion.getAttribute('data-bs-toggle');
267
+ expect(attribute).toEqual('collapse');
268
+ });
234
269
  });
@@ -1,3 +1,10 @@
1
1
  .fhir-resource__Bundle__item {
2
2
  margin-top: 10px;
3
3
  }
4
+
5
+ .fhir-resource__Bundle__rootPadding:first-of-type {
6
+ padding: 8px;
7
+ background: white;
8
+ border-radius: 0.2rem;
9
+ border: 1px solid #dee2e6;
10
+ }
@@ -4,12 +4,12 @@ import _get from 'lodash/get';
4
4
 
5
5
  import fhirVersions from '../fhirResourceVersions';
6
6
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
7
- import { Root, Header, Title, Badge, Body, BadgeSecondary } from '../../ui';
7
+ import { Root, Header, Badge, Body, BadgeSecondary } from '../../ui';
8
8
  import * as FhirResourceTypes from '../../supportedFhirResourceList';
9
9
 
10
10
  import './Bundle.css';
11
11
 
12
- export default function Bundle({ fhirResource, fhirVersion, fhirIcons }) {
12
+ export default function Bundle({ fhirResource, fhirVersion }) {
13
13
  const commonDTO = fhirResource => {
14
14
  const type = _get(fhirResource, 'type', null);
15
15
  const total = _get(fhirResource, 'total');
@@ -51,11 +51,14 @@ export default function Bundle({ fhirResource, fhirVersion, fhirIcons }) {
51
51
  .filter(Boolean);
52
52
 
53
53
  return (
54
- <Root name="Bundle">
55
- <Header>
56
- {type && <Title data-testid="title">{type}</Title>}
57
- {total && <Badge data-testid="total">{total}</Badge>}
58
- </Header>
54
+ <Root name="Bundle" className="fhir-resource__Bundle__rootPadding">
55
+ <Header
56
+ resourceName="Bundle"
57
+ title={type}
58
+ badges={!isNaN(total) && <Badge data-testid="total">{total}</Badge>}
59
+ capitalize
60
+ isNoIcon
61
+ />
59
62
  <Body>
60
63
  {resources.length > 0 &&
61
64
  resources.map((resource, index) => {
@@ -71,14 +74,15 @@ export default function Bundle({ fhirResource, fhirVersion, fhirIcons }) {
71
74
  key={`${resource.id}-${index}`}
72
75
  >
73
76
  {resourceType && (
74
- <BadgeSecondary data-testid="resourceType">
75
- {resourceType}
76
- </BadgeSecondary>
77
+ <div className="mx-20">
78
+ <BadgeSecondary data-testid="resourceType">
79
+ {resourceType}
80
+ </BadgeSecondary>
81
+ </div>
77
82
  )}
78
83
  <FhirComponent
79
84
  fhirResource={resource}
80
85
  fhirVersion={fhirVersion}
81
- fhirIcons={fhirIcons}
82
86
  />
83
87
  </div>
84
88
  );
@@ -17,8 +17,6 @@ import r4Example3 from '../../../fixtures/r4/resources/bundle/example3.json';
17
17
  import r4Example4 from '../../../fixtures/r4/resources/bundle/example4.json';
18
18
  import fhirVersions from '../fhirResourceVersions';
19
19
 
20
- import fhirIcons from '../../../fixtures/example-icons';
21
-
22
20
  export default {
23
21
  title: 'Bundle',
24
22
  };
@@ -26,133 +24,69 @@ export default {
26
24
  export const Example1OfDSTU2 = () => {
27
25
  const fhirResource = object('Resource', dstu2Example1);
28
26
  return (
29
- <Bundle
30
- fhirResource={fhirResource}
31
- fhirVersion={fhirVersions.DSTU2}
32
- fhirIcons={fhirIcons}
33
- />
27
+ <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.DSTU2} />
34
28
  );
35
29
  };
36
30
 
37
31
  export const Example2OfDSTU2 = () => {
38
32
  const fhirResource = object('Resource', dstu2Example2);
39
33
  return (
40
- <Bundle
41
- fhirResource={fhirResource}
42
- fhirVersion={fhirVersions.DSTU2}
43
- fhirIcons={fhirIcons}
44
- />
34
+ <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.DSTU2} />
45
35
  );
46
36
  };
47
37
 
48
38
  export const Example3OfDSTU2 = () => {
49
39
  const fhirResource = object('Resource', dstu2Example3);
50
40
  return (
51
- <Bundle
52
- fhirResource={fhirResource}
53
- fhirVersion={fhirVersions.DSTU2}
54
- fhirIcons={fhirIcons}
55
- />
41
+ <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.DSTU2} />
56
42
  );
57
43
  };
58
44
 
59
45
  export const Example4OfDSTU2 = () => {
60
46
  const fhirResource = object('Resource', dstu2Example4);
61
47
  return (
62
- <Bundle
63
- fhirResource={fhirResource}
64
- fhirVersion={fhirVersions.DSTU2}
65
- fhirIcons={fhirIcons}
66
- />
48
+ <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.DSTU2} />
67
49
  );
68
50
  };
69
51
 
70
52
  export const Example1OfSTU3 = () => {
71
53
  const fhirResource = object('Resource', stu3Example1);
72
- return (
73
- <Bundle
74
- fhirResource={fhirResource}
75
- fhirVersion={fhirVersions.STU3}
76
- fhirIcons={fhirIcons}
77
- />
78
- );
54
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />;
79
55
  };
80
56
 
81
57
  export const Example2OfSTU3 = () => {
82
58
  const fhirResource = object('Resource', stu3Example2);
83
- return (
84
- <Bundle
85
- fhirResource={fhirResource}
86
- fhirVersion={fhirVersions.STU3}
87
- fhirIcons={fhirIcons}
88
- />
89
- );
59
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />;
90
60
  };
91
61
 
92
62
  export const Example3OfSTU3 = () => {
93
63
  const fhirResource = object('Resource', stu3Example3);
94
- return (
95
- <Bundle
96
- fhirResource={fhirResource}
97
- fhirVersion={fhirVersions.STU3}
98
- fhirIcons={fhirIcons}
99
- />
100
- );
64
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />;
101
65
  };
102
66
 
103
67
  export const Example4OfSTU3 = () => {
104
68
  const fhirResource = object('Resource', stu3Example4);
105
- return (
106
- <Bundle
107
- fhirResource={fhirResource}
108
- fhirVersion={fhirVersions.STU3}
109
- fhirIcons={fhirIcons}
110
- />
111
- );
69
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />;
112
70
  };
113
71
 
114
72
  export const Example1OfR4 = () => {
115
73
  const fhirResource = object('Resource', r4Example1);
116
- return (
117
- <Bundle
118
- fhirResource={fhirResource}
119
- fhirVersion={fhirVersions.R4}
120
- fhirIcons={fhirIcons}
121
- />
122
- );
74
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
123
75
  };
124
76
 
125
77
  export const Example2OfR4 = () => {
126
78
  const fhirResource = object('Resource', r4Example2);
127
- return (
128
- <Bundle
129
- fhirResource={fhirResource}
130
- fhirVersion={fhirVersions.R4}
131
- fhirIcons={fhirIcons}
132
- />
133
- );
79
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
134
80
  };
135
81
 
136
82
  export const Example3OfR4 = () => {
137
83
  const fhirResource = object('Resource', r4Example3);
138
- return (
139
- <Bundle
140
- fhirResource={fhirResource}
141
- fhirVersion={fhirVersions.R4}
142
- fhirIcons={fhirIcons}
143
- />
144
- );
84
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
145
85
  };
146
86
 
147
87
  export const Example4OfR4 = () => {
148
88
  const fhirResource = object('Resource', r4Example4);
149
- return (
150
- <Bundle
151
- fhirResource={fhirResource}
152
- fhirVersion={fhirVersions.R4}
153
- fhirIcons={fhirIcons}
154
- />
155
- );
89
+ return <Bundle fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
156
90
  };
157
91
 
158
92
  // export const ExampleWithoutFHIRVersionProperty = () => {
@@ -8,8 +8,6 @@ import dstu2Example2 from '../../../fixtures/dstu2/resources/bundle/example3.jso
8
8
  import stu3Example1 from '../../../fixtures/stu3/resources/bundle/example1.json';
9
9
  import r4Example1 from '../../../fixtures/r4/resources/bundle/example1.json';
10
10
 
11
- import fhirIcons from '../../../fixtures/example-icons';
12
-
13
11
  describe('Bundle should render component correctly', () => {
14
12
  it('should render component correctly with DSTU2 source data', () => {
15
13
  const defaultProps = {
@@ -31,7 +29,6 @@ describe('Bundle should render component correctly', () => {
31
29
  const defaultProps = {
32
30
  fhirVersion: fhirVersions.DSTU2,
33
31
  fhirResource: dstu2Example2,
34
- fhirIcons: fhirIcons,
35
32
  };
36
33
  const { getByText, getAllByTestId } = render(<Bundle {...defaultProps} />);
37
34
  expect(getAllByTestId('title').map(title => title.textContent)).toEqual([
@@ -162,7 +162,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
162
162
  }
163
163
  };
164
164
 
165
- const CarePlan = ({ fhirResource, fhirVersion, fhirIcons }) => {
165
+ const CarePlan = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
166
166
  let fhirResourceData = {};
167
167
  try {
168
168
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -304,6 +304,7 @@ const CarePlan = ({ fhirResource, fhirVersion, fhirIcons }) => {
304
304
  )}
305
305
  </Body>
306
306
  }
307
+ onClick={onClick}
307
308
  />
308
309
  </Root>
309
310
  );
@@ -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
  import CarePlan from './CarePlan';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -111,8 +111,9 @@ describe('should render component correctly', () => {
111
111
  expect(getByTestId('activity').textContent).toContain('3141-9');
112
112
  expect(getByTestId('intent').textContent).toEqual('plan');
113
113
  expect(getByTestId('description').textContent).toContain('Manage obesity');
114
- expect(getByTestId('subject').textContent).toContain('Peter James');
115
- expect(getByTestId('subject').textContent).toContain('Patient/example');
114
+ expect(getByTestId('subject').textContent).toContain(
115
+ 'Peter James Chalmers',
116
+ );
116
117
  expect(getByTestId('author').textContent).toContain('Dr Adam Careful');
117
118
  expect(getByTestId('periodEnd').textContent).toEqual('6/1/2017');
118
119
  expect(getByTestId('basedOn').textContent).toEqual(
@@ -136,8 +137,9 @@ describe('should render component correctly', () => {
136
137
  expect(getByTestId('intent').textContent).toEqual('plan');
137
138
  expect(getByTestId('goals').textContent).toEqual('Goal/example');
138
139
  expect(getByTestId('description').textContent).toContain('Manage obesity');
139
- expect(getByTestId('subject').textContent).toContain('Peter James');
140
- expect(getByTestId('subject').textContent).toContain('Patient/example');
140
+ expect(getByTestId('subject').textContent).toContain(
141
+ 'Peter James Chalmers',
142
+ );
141
143
  expect(getByTestId('author').textContent).toContain('Dr Adam Careful');
142
144
  expect(getByTestId('periodEnd').textContent).toEqual('6/1/2017');
143
145
  expect(getByTestId('basedOn').textContent).toEqual(
@@ -160,8 +162,42 @@ describe('should render component correctly', () => {
160
162
  expect(getByTestId('intent').textContent).toEqual('plan');
161
163
  expect(getByTestId('goals').textContent).toEqual('#goal');
162
164
  expect(getByTestId('subject').textContent).toContain('Eve Everywoman');
163
- expect(getByTestId('subject').textContent).toContain('Patient/1');
164
165
  expect(getByTestId('periodStart').textContent).toEqual('1/1/2013');
165
166
  expect(getByTestId('periodEnd').textContent).toEqual('10/1/2013');
166
167
  });
168
+
169
+ it('should fire custom onClick function', () => {
170
+ const defaultProps = {
171
+ fhirResource: example2CarePlanR4,
172
+ fhirVersion: fhirVersions.R4,
173
+ };
174
+
175
+ const onClick = jest.fn();
176
+ const { getByRole } = render(
177
+ <CarePlan {...defaultProps} onClick={onClick} />,
178
+ );
179
+ const accordion = getByRole('button');
180
+ fireEvent.click(accordion);
181
+
182
+ const attribute = accordion.getAttribute('data-bs-toggle');
183
+ expect(attribute).not.toEqual('collapse');
184
+ expect(onClick).toHaveBeenCalled();
185
+ });
186
+
187
+ it('should not fire custom onClick function', () => {
188
+ const defaultProps = {
189
+ fhirResource: example2CarePlanR4,
190
+ fhirVersion: fhirVersions.R4,
191
+ };
192
+
193
+ const onClick = 'test';
194
+ const { getByRole } = render(
195
+ <CarePlan {...defaultProps} onClick={onClick} />,
196
+ );
197
+ const accordion = getByRole('button');
198
+ fireEvent.click(accordion);
199
+
200
+ const attribute = accordion.getAttribute('data-bs-toggle');
201
+ expect(attribute).toEqual('collapse');
202
+ });
167
203
  });