Skip to content

Commit 4a4ce78

Browse files
committed
tests and fix for removing help items from questionnaire response
1 parent 646dcff commit 4a4ce78

File tree

12 files changed

+107
-18
lines changed

12 files changed

+107
-18
lines changed

CHANGES.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## 16.4.1
2+
3+
- Exclude items with the "help item-control extension from the questionnaire response
4+
5+
```json
6+
{
7+
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
8+
"valueCodeableConcept": {
9+
"coding": [
10+
{
11+
"system": "http://hl7.org/fhir/ValueSet/questionnaire-item-control",
12+
"code": "help"
13+
}
14+
]
15+
}
16+
}
17+
```
18+
119
## 16.4.0
220

321
---

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@helsenorge/refero",
3-
"version": "16.4.0",
3+
"version": "16.4.1",
44
"description": "Refero is a library that uses a fhir r4 schema and creates a interactive form using helsenorge packages.",
55
"keywords": [
66
"react",

src/actions/generateQuestionnaireResponse.ts

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { createQuestionnaireResponseAnswer } from '../util/createQuestionnaireRe
77
import { getCalculatedExpressionExtension, getCopyExtension, getMinOccursExtensionValue } from '../util/extension';
88
import { evaluateFhirpathExpressionToGetString } from '@/util/fhirpathHelper';
99
import ItemType from '../constants/itemType';
10+
import { isHelpItem } from '@/util/help';
11+
12+
const shouldNotAddItemToResponse = (item: QuestionnaireItem): boolean => {
13+
return isHelpItem(item);
14+
};
1015

1116
export function generateQuestionnaireResponse(questionnaire: Questionnaire): QuestionnaireResponse | undefined {
1217
const response: QuestionnaireResponse = {
@@ -27,6 +32,9 @@ export function generateQuestionnaireResponse(questionnaire: Questionnaire): Que
2732
}
2833

2934
for (let j = 0; j < getMinOccurs(i); j++) {
35+
if (shouldNotAddItemToResponse(i)) {
36+
continue;
37+
}
3038
const responseItem = createQuestionnaireResponseItem(i);
3139
addChildrenItemsToResponseItem(i, responseItem);
3240

@@ -45,6 +53,9 @@ function addChildrenItemsToResponseItem(item: QuestionnaireItem, response: Quest
4553
for (let j = 0; j < getMinOccurs(i); j++) {
4654
const responseItem = createQuestionnaireResponseItem(i);
4755
addChildrenItemsToResponseItem(i, responseItem);
56+
if (shouldNotAddItemToResponse(i)) {
57+
continue;
58+
}
4859
addResponseItemtoResponse(item, response, responseItem);
4960
}
5061
});

src/components/formcomponents/choice-common/__tests__/autosuggest-view-spec.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ describe('autosuggest-view', () => {
152152
await userEvent.click(await screen.findByText(/Fyrstekake/i));
153153
await clickButtonTimes(/-repeat-button/i, 1);
154154

155+
await userEvent.type(screen.getAllByLabelText(/Mistenkt legemiddel/i)[1], 'f');
156+
await userEvent.click(await screen.findByText(/Fyrstekake/i));
157+
155158
expect(screen.getByTestId(/-delete-button/i)).toBeInTheDocument();
156159
await clickButtonTimes(/-delete-button/i, 1);
157160

@@ -173,6 +176,9 @@ describe('autosuggest-view', () => {
173176
await userEvent.click(await screen.findByText(/Fyrstekake/i));
174177
await clickButtonTimes(/-repeat-button/i, 1);
175178

179+
await userEvent.type(screen.getAllByLabelText(/Mistenkt legemiddel/i)[1], 'f');
180+
await userEvent.click(await screen.findByText(/Fyrstekake/i));
181+
176182
expect(screen.getByTestId(/-delete-button/i)).toBeInTheDocument();
177183

178184
await clickButtonTimes(/-delete-button/i, 1);

src/components/formcomponents/choice/__tests__/choice-checkbox-view-spec.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Questionnaire } from 'fhir/r4';
2-
import { findByRole, renderRefero, userEvent } from '@test/test-utils.tsx';
2+
import { findByRole, renderRefero, screen, userEvent } from '@test/test-utils.tsx';
33
import { checkboxView as q } from './__data__/index';
44
import { ReferoProps } from '../../../../types/referoProps';
55
import { Extensions } from '../../../../constants/extensions';
@@ -123,6 +123,9 @@ describe('checkbox-view - choice', () => {
123123

124124
await repeatCheckboxTimes(/Ja/i, 1);
125125

126+
const elm2 = screen.getAllByLabelText(/Ja/i);
127+
await userEvent.click(elm2[1]);
128+
126129
expect(getByTestId(/-delete-button/i)).toBeInTheDocument();
127130
await clickButtonTimes(/-delete-button/i, 1);
128131

@@ -136,6 +139,10 @@ describe('checkbox-view - choice', () => {
136139
const { getByTestId, queryByTestId } = createWrapper(questionnaire);
137140

138141
await repeatCheckboxTimes(/Ja/i, 1);
142+
143+
const elm2 = screen.getAllByLabelText(/Ja/i);
144+
await userEvent.click(elm2[1]);
145+
139146
expect(getByTestId(/-delete-button/i)).toBeInTheDocument();
140147

141148
await clickButtonTimes(/-delete-button/i, 1);

src/components/formcomponents/choice/__tests__/choice-radio-view-spec.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Questionnaire } from 'fhir/r4';
2-
import { findByRole, renderRefero, userEvent, waitFor } from '@test/test-utils.tsx';
2+
import { findByRole, renderRefero, screen, userEvent, waitFor } from '@test/test-utils.tsx';
33
import { radioView as q } from './__data__/index';
44
import { ReferoProps } from '../../../../types/referoProps';
55
import { Extensions } from '../../../../constants/extensions';
@@ -122,6 +122,9 @@ describe('Radio-view - choice', () => {
122122

123123
await repeatCheckboxTimes(/Ja/i, 1);
124124

125+
const elm2 = screen.getAllByLabelText(/Ja/i);
126+
await userEvent.click(elm2[1]);
127+
125128
expect(getByTestId(/-delete-button/i)).toBeInTheDocument();
126129
await clickButtonTimes(/-delete-button/i, 1);
127130

@@ -135,6 +138,10 @@ describe('Radio-view - choice', () => {
135138
const { getByTestId, queryByTestId } = await createWrapper(questionnaire);
136139

137140
await repeatCheckboxTimes(/Ja/i, 1);
141+
142+
const elm2 = screen.getAllByLabelText(/Ja/i);
143+
await userEvent.click(elm2[1]);
144+
138145
expect(getByTestId(/-delete-button/i)).toBeInTheDocument();
139146

140147
await clickButtonTimes(/-delete-button/i, 1);

src/components/formcomponents/date/__tests__/date-time-spec.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ describe('Date time', () => {
172172

173173
await repeatDateTimeNTimes(/Dato/i, 'hours-test', 'minutes-test', '12.12.2024', '12', '30', 1);
174174

175+
const dateElement2 = screen.queryAllByLabelText(/Dato/i)[1];
176+
const hoursElement2 = screen.queryAllByTestId('hours-test')[1];
177+
const minutesElement2 = screen.queryAllByTestId('minutes-test')[1];
178+
if (dateElement2 && hoursElement2 && minutesElement2) {
179+
const hoursInput2 = hoursElement2.querySelector('input');
180+
const minutesInput2 = minutesElement2.querySelector('input');
181+
182+
await userEvent.type(dateElement2, '12.12.2024');
183+
184+
if (hoursInput2 && minutesInput2) {
185+
await userEvent.type(hoursInput2, '12');
186+
await userEvent.type(minutesInput2, '30');
187+
}
188+
}
189+
175190
await waitFor(async () => expect(getByTestId(/-delete-button/i)).toBeInTheDocument());
176191

177192
await clickButtonTimes(/-delete-button/i, 1);
@@ -187,6 +202,20 @@ describe('Date time', () => {
187202

188203
await repeatDateTimeNTimes(/Dato/i, 'hours-test', 'minutes-test', '12.12.2024', '12', '30', 1);
189204

205+
const dateElement2 = screen.queryAllByLabelText(/Dato/i)[1];
206+
const hoursElement2 = screen.queryAllByTestId('hours-test')[1];
207+
const minutesElement2 = screen.queryAllByTestId('minutes-test')[1];
208+
if (dateElement2 && hoursElement2 && minutesElement2) {
209+
const hoursInput2 = hoursElement2.querySelector('input');
210+
const minutesInput2 = minutesElement2.querySelector('input');
211+
212+
await userEvent.type(dateElement2, '12.12.2024');
213+
214+
if (hoursInput2 && minutesInput2) {
215+
await userEvent.type(hoursInput2, '12');
216+
await userEvent.type(minutesInput2, '30');
217+
}
218+
}
190219
await waitFor(async () => expect(getByTestId(/-delete-button/i)).toBeInTheDocument());
191220

192221
await clickButtonTimes(/-delete-button/i, 1);

src/components/formcomponents/open-choice/__tests__/openchoice-checkbox-view-spec.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Questionnaire, QuestionnaireItemAnswerOption } from 'fhir/r4';
2-
import { findByRole, renderRefero, userEvent, waitFor } from '@test/test-utils.tsx';
2+
import { findByRole, renderRefero, screen, userEvent, waitFor } from '@test/test-utils.tsx';
33
import { clickButtonTimes, repeatCheckboxTimes, selectCheckboxOption, submitForm } from '../../../../../test/selectors';
44
import { checkboxView as q } from './__data__/index';
55
import { ReferoProps } from '../../../../types/referoProps';
@@ -93,6 +93,10 @@ describe('checkbox-view - openchoice', () => {
9393
const { getByTestId } = await createWrapper(questionnaire);
9494

9595
await repeatCheckboxTimes(/Ja/i, 1);
96+
97+
const elm2 = screen.getAllByLabelText(/Ja/i);
98+
await userEvent.click(elm2[1]);
99+
96100
await clickButtonTimes(/-delete-button/i, 1);
97101

98102
expect(getByTestId(/-delete-confirm-modal/i)).toBeInTheDocument();
@@ -102,6 +106,10 @@ describe('checkbox-view - openchoice', () => {
102106
const { getByTestId, queryByTestId } = await createWrapper(questionnaire);
103107

104108
await repeatCheckboxTimes(/Ja/i, 1);
109+
110+
const elm2 = screen.getAllByLabelText(/Ja/i);
111+
await userEvent.click(elm2[1]);
112+
105113
await clickButtonTimes(/-delete-button/i, 1);
106114
await userEvent.click(await findByRole(getByTestId(/-delete-confirm-modal/i), 'button', { name: /Forkast endringer/i }));
107115
expect(queryByTestId(/-delete-button/i)).not.toBeInTheDocument();

src/components/formcomponents/open-choice/__tests__/openchoice-radio-view-spec.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Questionnaire, QuestionnaireItemAnswerOption } from 'fhir/r4';
2-
import { findByRole, renderRefero, userEvent, waitFor } from '@test/test-utils.tsx';
2+
import { findByRole, renderRefero, screen, userEvent, waitFor } from '@test/test-utils.tsx';
33
import { radioView as q } from './__data__/index';
44
import { ReferoProps } from '../../../../types/referoProps';
55
import { Extensions } from '../../../../constants/extensions';
@@ -110,6 +110,9 @@ describe('Radio-view - choice', () => {
110110

111111
await repeatCheckboxTimes(/Ja/i, 1);
112112

113+
const elm2 = screen.getAllByLabelText(/Ja/i);
114+
await userEvent.click(elm2[1]);
115+
113116
expect(getByTestId(/-delete-button/i)).toBeInTheDocument();
114117
await clickButtonTimes(/-delete-button/i, 1);
115118

@@ -121,6 +124,9 @@ describe('Radio-view - choice', () => {
121124

122125
await repeatCheckboxTimes(/Ja/i, 1);
123126

127+
const elm2 = screen.getAllByLabelText(/Ja/i);
128+
await userEvent.click(elm2[1]);
129+
124130
expect(getByTestId(/-delete-button/i)).toBeInTheDocument();
125131
await clickButtonTimes(/-delete-button/i, 1);
126132

src/components/formcomponents/string/__tests__/__data__/q.json

-8
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@
7171
"url": "http://helsenorge.no/fhir/StructureDefinition/sdf-sublabel",
7272
"valueMarkdown": "**String sublabel**"
7373
},
74-
{
75-
"url": "http://hl7.org/fhir/StructureDefinition/regex",
76-
"valueString": "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
77-
},
78-
{
79-
"url": "http://hl7.org/fhir/StructureDefinition/minLength",
80-
"valueInteger": 10
81-
},
8274
{
8375
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-minOccurs",
8476
"valueInteger": 1

test/selectors.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import exp from 'constants';
21
import { Matcher, screen, userEvent } from './test-utils';
32

43
export async function selectCheckboxOption(id: Matcher): Promise<void> {
@@ -14,6 +13,7 @@ export async function repeatNTimes(input: string, n: number, labelText: Matcher)
1413
for (let i = 0; i < n; i++) {
1514
await userEvent.type(screen.queryAllByLabelText(labelText)[i], input);
1615
await clickButtonTimes(/-repeat-button/i, 1);
16+
await userEvent.type(screen.queryAllByLabelText(labelText)[i + 1], input);
1717
}
1818
}
1919
export async function repeatDateTimeNTimes(
@@ -34,6 +34,7 @@ export async function repeatDateTimeNTimes(
3434
const minutesInput = minutesElement.querySelector('input');
3535

3636
await userEvent.type(dateElement, dateString);
37+
3738
if (hoursInput && minutesInput) {
3839
await userEvent.type(hoursInput, hoursString);
3940
await userEvent.type(minutesInput, minutesString);
@@ -76,9 +77,9 @@ export async function clickByLabelText(id: Matcher): Promise<void> {
7677
expect(elm).toBeInTheDocument();
7778
await userEvent.click(elm);
7879
}
79-
export async function repeatCheckboxTimes(id: Matcher, n: number): Promise<void> {
80+
export async function repeatCheckboxTimes(matcher: Matcher, n: number): Promise<void> {
8081
for (let i = 0; i < n; i++) {
81-
const elm = screen.getAllByLabelText(id);
82+
const elm = screen.getAllByLabelText(matcher);
8283
await userEvent.click(elm[i]);
8384
await clickButtonTimes(/-repeat-button/i, 1);
8485
}
@@ -89,6 +90,9 @@ export async function repeatSliderTimes(linkId: string, n: number): Promise<void
8990
const itemToClick = elm.querySelectorAll('div.slider__track__step')[0];
9091
await userEvent.click(itemToClick);
9192
await clickButtonTimes(/-repeat-button/i, 1);
93+
const elm2 = await screen.findByTestId(`item_${linkId}^${i + 1}-${i + 1}-slider-choice`);
94+
const itemToClick2 = elm2.querySelectorAll('div.slider__track__step')[0];
95+
await userEvent.click(itemToClick2);
9296
}
9397
}
9498
export async function clickSliderValue(linkId: Matcher, index: number, sliderItemIndex: undefined | number = 0): Promise<void> {
@@ -104,6 +108,7 @@ export async function repeatDropDownTimes(
104108
for (let i = 0; i < n; i++) {
105109
await userEvent.selectOptions(screen.getAllByLabelText(id)[i], screen.getAllByRole('option', { name: optionName })[i]);
106110
await clickButtonTimes(/-repeat-button/i, 1);
111+
await userEvent.selectOptions(screen.getAllByLabelText(id)[i + 1], screen.getAllByRole('option', { name: optionName })[i + 1]);
107112
}
108113
}
109114
export async function typeAndTabByLabelText(id: Matcher, value: string): Promise<void> {

0 commit comments

Comments
 (0)