Skip to content

Commit

Permalink
Added full enableWhen yup schema support
Browse files Browse the repository at this point in the history
Added tests for each enableWhen operator cases
  • Loading branch information
qscgyjqscgyj committed Dec 3, 2024
1 parent b940047 commit c7c4358
Show file tree
Hide file tree
Showing 11 changed files with 1,211 additions and 179 deletions.
152 changes: 152 additions & 0 deletions src/utils/__tests__/enableWhen/equal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import {
CONTROL_ITEM_LINK_ID,
generateQAndQRData,
QuestionnaireData,
testEnableWhenCases,
ENABLE_WHEN_TESTS_TITLE,
} from './utils';

const ENABLE_WHEN_EQUAL_QUESTIONAIRES: QuestionnaireData[] = [
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { integer: 1 },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { integer: 1 } }],
},
{
linkId: 'q2',
answer: [],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { string: 'test' },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'test2' } }],
},
{
linkId: 'q2',
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { string: 'test1' },
},
{
question: 'q2',
operator: '=',
answer: { string: 'test2' },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'test1' } }],
},
{
linkId: 'q2',
answer: [{ value: { string: 'test2' } }],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { string: 'test1' },
},
{
question: 'q2',
operator: '=',
answer: { string: 'test2' },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'asd' } }],
},
{
linkId: 'q2',
answer: [{ value: { string: 'test2' } }],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableBehavior: 'any',
enableWhen: [
{
question: 'q1',
operator: '=',
answer: { Coding: { code: 'test1', display: 'test1' } },
},
{
question: 'q2',
operator: '=',
answer: { Coding: { code: 'test2', display: 'test2' } },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { Coding: { code: 'asd', display: 'asd' } } }],
},
{
linkId: 'q2',
answer: [{ value: { Coding: { code: 'test2', display: 'test2' } } }],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
];

describe('Enable when: "="', () => {
test.each(ENABLE_WHEN_EQUAL_QUESTIONAIRES)(ENABLE_WHEN_TESTS_TITLE, testEnableWhenCases);
});
120 changes: 0 additions & 120 deletions src/utils/__tests__/enableWhen/equalOperator.test.ts

This file was deleted.

Loading

0 comments on commit c7c4358

Please sign in to comment.