Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rinrub committed Feb 12, 2024
1 parent c9695de commit c2dacd1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ describe('gtable-utils-spec', () => {
];
const columns = columnsForRowIndex(answerItems, 0);
expect(columns).toEqual([
{ id: 'default-question-linkId', index: 0, value: 'Answer 1' },
{ id: 'default-question-linkId', index: 1, value: 'Another Answer 1' },
{ id: 'default-question-linkId', index: 0, value: 'Answer 1', type: ItemType.TEXT },
{ id: 'default-question-linkId', index: 1, value: 'Another Answer 1', type: ItemType.TEXT },
]);
});

Expand All @@ -137,8 +137,8 @@ describe('gtable-utils-spec', () => {
];
const columns = columnsForRowIndex(answerItems, 1);
expect(columns).toEqual([
{ id: 'default-question-linkId', index: 0, value: '' },
{ id: 'default-question-linkId', index: 1, value: '' },
{ id: 'default-question-linkId', index: 0, value: '', type: ItemType.TEXT },
{ id: 'default-question-linkId', index: 1, value: '', type: ItemType.TEXT },
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
getStandardTableObject,
needsExtraColumn,
} from '../utils';
import { QuestionnaireItem, QuestionnaireResponse, QuestionnaireResponseItem, Resource } from '../../../../../../types/fhir';

import * as choiceUtils from '../../../../../../util/choice';

import * as tableUtils from '../../utils';
import { QuestionnaireItemWithAnswers } from '../../interface';
import { QuestionnaireResponseItem, QuestionnaireItem, QuestionnaireResponse, Resource } from 'fhir/r4';
jest.mock('../../utils');
jest.mock('../../../../../../util/choice');

Expand Down Expand Up @@ -264,25 +264,44 @@ describe('createBodyRows', () => {
});

describe('createRowsFromAnswersCodes', () => {
beforeEach(() => {
jest.spyOn(choiceUtils, 'getSystemForItem');
});
afterEach(() => {
jest.restoreAllMocks();
});
it('should create rows from the given response item and choice values', () => {
const item: QuestionnaireResponseItem = {
(choiceUtils.getSystemForItem as jest.Mock).mockImplementation(() => {
return 'sys';
});
const item: QuestionnaireItemWithAnswers = {
linkId: '1',
type: ItemType.CHOICE,
answer: [{ valueCoding: { code: '1' } }],
};

const choiceValues: Options[] = [
{ type: '1', label: 'Option A' },
{ type: '2', label: 'Option B' },
];
const rows = createRowsFromAnswersCodes(item, choiceValues);
const rows = createRowsFromAnswersCodes(item, choiceValues, 'sys', []);
expect(rows).toEqual([
{ id: '1-1', index: 1, value: 'X' },
{ id: '2-2', index: 2, value: '' },
{ id: '1-1', index: 1, value: 'X', type: ItemType.CHOICE },
{ id: '2-2', index: 2, value: '', type: ItemType.CHOICE },
]);
});

it('should return an empty array if no choice values are provided', () => {
const item: QuestionnaireResponseItem = {
const item: QuestionnaireItemWithAnswers = {
linkId: '1',
type: ItemType.CHOICE,
answerOption: [
{
valueCoding: {
system: 'sys',
},
},
],
answer: [{ valueCoding: { code: '1' } }],
};
const rows = createRowsFromAnswersCodes(item);
Expand Down Expand Up @@ -324,10 +343,10 @@ describe('createColumnsFromAnswers', () => {
];
const columns = createColumnsFromAnswers(item, choiceValues);
expect(columns).toEqual([
{ value: 'Question 1', index: 0, id: '1-question' },
{ value: '', index: 1, id: '1-1' },
{ value: '', index: 2, id: '2-2' },
{ value: '', index: 3, id: '1-answer' },
{ value: 'Question 1', index: 0, id: '1-question', type: ItemType.CHOICE },
{ value: '', index: 1, id: '1-1', type: ItemType.CHOICE },
{ value: '', index: 2, id: '2-2', type: ItemType.CHOICE },
{ value: '', index: 3, id: '1-answer', type: ItemType.CHOICE },
]);
});

Expand All @@ -354,8 +373,8 @@ describe('createColumnsFromAnswers', () => {
};
const columns = createColumnsFromAnswers(item);
expect(columns).toEqual([
{ value: 'Question 1', index: 0, id: '1-question' },
{ value: '', index: 1, id: '1-answer' },
{ value: 'Question 1', index: 0, id: '1-question', type: ItemType.CHOICE },
{ value: '', index: 1, id: '1-answer', type: ItemType.CHOICE },
]);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/formcomponents/table/tables/table/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Options } from '@helsenorge/form/components/radio-group';
import { IStandardTable, IStandardTableColumn, IStandardTableRow } from './interface';
import codeSystems from '../../../../../constants/codingsystems';
import ItemType, { IItemType } from '../../../../../constants/itemType';
import { getContainedOptions, getOptions, getSystemForItem } from '../../../../../util/choice';
import { getContainedOptions, getSystemForItem } from '../../../../../util/choice';
import { QuestionnaireItemWithAnswers } from '../interface';
import {
getDisplayFromCodingSystem,
Expand Down
1 change: 0 additions & 1 deletion src/util/choice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export function getSystemForItem(item: QuestionnaireItem, containedResources?: R
if (item.answerValueSet && item.answerValueSet.startsWith('#')) {
const id: string = item.answerValueSet.replace('#', '');
const resource = getContainedResource(id, containedResources);
console.log(resource);

if (resource && resource.compose) {
return resource.compose.include[0].system;
Expand Down

0 comments on commit c2dacd1

Please sign in to comment.