Skip to content

Commit

Permalink
WIP: Add test to cover problems with isEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
projkov committed Nov 20, 2023
1 parent a7d93ae commit 196b62f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sdc-qrf/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export function mapResponseToForm(resource: QuestionnaireResponse, questionnaire
}

function initialToQuestionnaireResponseItemAnswer(initial: QuestionnaireItemInitial[] | undefined) {
return (initial ?? []).map(({ value }) => ({ value } as QuestionnaireResponseItemAnswer));
return (initial ?? []).map(({ value }) => ({ value }) as QuestionnaireResponseItemAnswer);
}

export function findAnswersForQuestionsRecursive(linkId: string, values?: FormItems): any | null {
Expand Down Expand Up @@ -738,3 +738,7 @@ export function parseFhirQueryExpression(expression: string, context: ItemContex

return [resourceType, searchParams];
}

export function isValueEmpty(value: any) {
return _.isEmpty(value);
}
24 changes: 24 additions & 0 deletions sdc-qrf/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Questionnaire, QuestionnaireResponse } from 'shared/src/contrib/aidbox'
import { allergiesQuestionnaire } from './resources/questionnaire';
import {
getEnabledQuestions,
isValueEmpty,
mapFormToResponse,
mapResponseToForm,
removeDisabledAnswers,
Expand Down Expand Up @@ -741,3 +742,26 @@ describe('enableWhen exists logic for non-repeatable groups primitives', () => {
expect(actualQR).toEqual(expectedQR);
});
});

describe('isValueEmpty method test', () => {
const valueTypeList = [
{ value: 1, expect: false },
{ value: 0, expect: false },
{ value: 1.1, expect: false },
{ value: 'a', expect: false },
{ value: true, expect: false },
{ value: false, expect: false },
{ value: { a: 1 }, expect: false },
{ value: ['a'], expect: false },
{ value: '', expect: true },
{ value: [], expect: true },
{ value: {}, expect: true },
{ value: undefined, expect: true },
{ value: null, expect: true },
{ value: NaN, expect: true },
];

test.each(valueTypeList)('isValueEmpty works correctly for type %s', async (valueType) => {
expect(isValueEmpty(valueType.value)).toEqual(valueType.expect);
});
});

0 comments on commit 196b62f

Please sign in to comment.