Skip to content

Commit

Permalink
Add tests for the removing ID function
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Sep 20, 2024
1 parent 2c66724 commit 3fa35cf
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/smart-forms-renderer/src/tests/removeId.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) ABN 41 687 119 230.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { expect, test } from '@jest/globals';
import { removeInternalIdsFromResponse } from '../utils';
import { qrRemoveIdResult, qrRemoveIdSample } from './test-data/removeIdSample';
import { qMyPatient } from '../stories/assets/questionnaires/QIdRemoverDebugger';

test('item.initial is properly pre-filled into QuestionnaireResponse', () => {
const outputResponse = removeInternalIdsFromResponse(qMyPatient, qrRemoveIdSample);

expect(outputResponse).toStrictEqual(qrRemoveIdResult);
});
101 changes: 101 additions & 0 deletions packages/smart-forms-renderer/src/tests/test-data/removeIdSample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import type { QuestionnaireResponse } from 'fhir/r4';

export const qrRemoveIdSample: QuestionnaireResponse = {
resourceType: 'QuestionnaireResponse',
status: 'in-progress',
questionnaire: 'http://canshare.co.nz/questionnaire/myPatient1',
item: [
{
linkId: 'myPatient1',
text: 'myPatient1',
item: [
{
linkId: 'myPatient1.name',
text: 'name *',
item: [
{
linkId: 'myPatient1.name.first',
text: 'firstName *',
answer: [
{
id: 'myPatient1.name.first-repeat-000000',
valueString: '1st firstName 1.0'
}
]
}
]
},
{
linkId: 'myPatient1.name',
text: 'name *',
item: [
{
linkId: 'myPatient1.name.first',
text: 'firstName *',
answer: [
{
id: 'myPatient1.name.first-repeat-000000',
valueString: '2nd firstName 1.0'
},
{
id: 'myPatient1.name.first-repeat-O-r6YSxx81TBFf_yiHWk6',
valueString: '2nd firstName 2.0'
},
{
id: 'myPatient1.name.first-repeat-ZQR77gdy6utsT_JkbuHKc'
}
]
}
]
}
]
}
]
};

export const qrRemoveIdResult: QuestionnaireResponse = {
resourceType: 'QuestionnaireResponse',
status: 'in-progress',
questionnaire: 'http://canshare.co.nz/questionnaire/myPatient1',
item: [
{
linkId: 'myPatient1',
text: 'myPatient1',
item: [
{
linkId: 'myPatient1.name',
text: 'name *',
item: [
{
linkId: 'myPatient1.name.first',
text: 'firstName *',
answer: [
{
valueString: '1st firstName 1.0'
}
]
}
]
},
{
linkId: 'myPatient1.name',
text: 'name *',
item: [
{
linkId: 'myPatient1.name.first',
text: 'firstName *',
answer: [
{
valueString: '2nd firstName 1.0'
},
{
valueString: '2nd firstName 2.0'
}
]
}
]
}
]
}
]
};

0 comments on commit 3fa35cf

Please sign in to comment.