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

fix(renderer): pass field property to when in sequence and not #1423

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const parseCondition = (condition, values, field) => {
if (condition.sequence) {
return condition.sequence.reduce(
(acc, curr) => {
const result = parseCondition(curr, values);
const result = parseCondition(curr, values, field);

return {
sets: [...acc.sets, ...(result.set ? [result.set] : [])],
Expand All @@ -90,7 +90,7 @@ export const parseCondition = (condition, values, field) => {
}

if (condition.not) {
return !parseCondition(condition.not, values).result ? positiveResult : negativeResult;
return !parseCondition(condition.not, values, field).result ? positiveResult : negativeResult;
}

const finalWhen = typeof condition.when === 'function' ? condition.when(field) : condition.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,46 @@ describe('parseCondition', () => {
expect(whenSpyX).toHaveBeenCalledWith(field);
expect(whenSpyY).toHaveBeenCalledWith(field);
});

it('when is function in sequence', () => {
const whenSpy = jest.fn().mockImplementation(() => 'x');

condition = {
sequence: [
{
when: whenSpy,
is: 'yes',
},
],
};

values = {
x: 'yes',
};

expect(parseCondition(condition, values, field)).toEqual({ ...positiveResult, sets: [] });
expect(whenSpy).toHaveBeenCalledWith(field);
});

it('when is function in not', () => {
const whenSpy = jest.fn().mockImplementation(() => 'x');

condition = {
not: [
{
when: whenSpy,
is: 'yes',
},
],
};

values = {
x: 'yes',
};

expect(parseCondition(condition, values, field)).toEqual(negativeResult);
expect(whenSpy).toHaveBeenCalledWith(field);
});
});

it('simple condition - custom function', () => {
Expand Down
Loading