Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added isItemEnabled util to use it for enable when schema #393

Merged
merged 10 commits into from
Dec 9, 2024
Merged
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' } },
ruscoder marked this conversation as resolved.
Show resolved Hide resolved
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { Coding: { code: 'asd', display: 'asd' } } }],
},
{
linkId: 'q2',
answer: [{ value: { Coding: { code: 'test2', display: 'Different display' } } }],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
];

describe('Enable when: "="', () => {
test.each(ENABLE_WHEN_EQUAL_QUESTIONAIRES)(ENABLE_WHEN_TESTS_TITLE, testEnableWhenCases);
});
152 changes: 152 additions & 0 deletions src/utils/__tests__/enableWhen/exists.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_EXISTS_QUESTIONAIRES: QuestionnaireData[] = [
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: 'exists',
answer: { boolean: true },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'test1' } }],
},
{
linkId: 'q2',
answer: [],
},
{
linkId: CONTROL_ITEM_LINK_ID,
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: 'exists',
answer: { boolean: false },
},
],
qrItem: [
{
linkId: 'q1',
answer: [{ value: { string: 'test2' } }],
},
{
linkId: 'q2',
answer: [],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableWhen: [
{
question: 'q1',
operator: 'exists',
answer: { boolean: true },
},
{
question: 'q2',
operator: 'exists',
answer: { boolean: true },
},
],
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: 'exists',
answer: { boolean: true },
},
{
question: 'q2',
operator: 'exists',
answer: { boolean: true },
},
],
qrItem: [
{
linkId: 'q1',
answer: [],
},
{
linkId: 'q2',
answer: [{ value: { string: 'test2' } }],
},
],
}),
},
{
...generateQAndQRData({
type: 'integer',
enableBehavior: 'any',
enableWhen: [
{
question: 'q1',
operator: 'exists',
answer: { boolean: true },
},
{
question: 'q2',
operator: 'exists',
answer: { boolean: false },
},
],
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: "exists"', () => {
test.each(ENABLE_WHEN_EXISTS_QUESTIONAIRES)(ENABLE_WHEN_TESTS_TITLE, testEnableWhenCases);
});
Loading
Loading