Skip to content

Commit

Permalink
moved adding initial answer to confirmations outside loop and changed…
Browse files Browse the repository at this point in the history
… the testdata
  • Loading branch information
rinrub authored and AG-83 committed Feb 27, 2024
1 parent 9d816eb commit fcd6608
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/reducers/__tests__/__data__/repeatableBoolean/q.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{
"linkId": "1.0.4",
"text": "Far",
"type": "boolean",
"type": "group",
"repeats": false,
"item": [
{ "linkId": "1.0.4.0", "text": "Fullblod", "type": "boolean" },
Expand Down
4 changes: 3 additions & 1 deletion src/reducers/__tests__/repeatableBoolean-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ describe('Given a questionnaire with multiple repeatable booleans', () => {

it('Then repeated item should have an answer with 3 items', () => {
const repeatedResponseItem = getResponseItem('1.0.4', newState, pathify('1', '1.0^1', '1.0.4')) as QuestionnaireResponseItem;
console.log('newState', JSON.stringify(newState, null, 2));

console.log('repeatedResponseItem', repeatedResponseItem);
if (!repeatedResponseItem) return fail();

if (!repeatedResponseItem.answer) return fail();

expect(repeatedResponseItem.answer.length).toBe(1);

const answer = repeatedResponseItem.answer[0];

console.log('answer', answer);
if (!answer || !answer.item) return fail();

expect(answer.item.length).toBe(3);
Expand Down
3 changes: 2 additions & 1 deletion src/reducers/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function reduce(state: Form, action: NewValueAction): Form {
}

export function getResponseItem(linkId: string, state: Form, path: Array<Path>): QuestionnaireResponseItem | undefined {
if (linkId === path[path.length - 1].linkId) return getResponseItemWithPath(path, state.FormData);
const condition = linkId === path[path.length - 1].linkId;
if (condition) return getResponseItemWithPath(path, state.FormData);
}

export function createGlobalStateWithQuestionnaire(q: Questionnaire, qr: QuestionnaireResponse): GlobalState {
Expand Down
11 changes: 7 additions & 4 deletions src/reducers/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ function copyItem(
copyItem(source.item[i], newResponseItem, questionnaireDraft, questionnaire);
}
const defItem = getQuestionnaireDefinitionItem(source.linkId, questionnaireDraft.item);

if (defItem?.type === itemType.BOOLEAN) {
const answer = createQuestionnaireResponseAnswer(defItem);
if (answer) {
target.answer = [answer];
}
}
if (defItem && defItem.type !== itemType.ATTATCHMENT) {
for (let i = 0; source.answer && i < source.answer.length; i++) {
if (!source.answer[i].item || source.answer[i].item?.length === 0) {
Expand Down Expand Up @@ -283,9 +288,7 @@ function copyItem(
target.answer.push(targetAnswer);
}
}
if (defItem?.type === itemType.BOOLEAN) {
target.answer = addInitialValueToBooleanItem(defItem);
}

return target;
}

Expand Down

0 comments on commit fcd6608

Please sign in to comment.