2021-05-16 15:21:55 +02:00
|
|
|
import WhenClause from './WhenClause';
|
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
describe('WhenClause', () => {
|
2021-05-16 15:21:55 +02:00
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
test('should work with simple condition', async () => {
|
2021-05-16 15:21:55 +02:00
|
|
|
const wc = new WhenClause('test1 && test2');
|
|
|
|
|
|
|
|
expect(wc.evaluate({
|
|
|
|
test1: true,
|
|
|
|
test2: true,
|
|
|
|
})).toBe(true);
|
|
|
|
|
|
|
|
expect(wc.evaluate({
|
|
|
|
test1: true,
|
|
|
|
test2: false,
|
|
|
|
})).toBe(false);
|
|
|
|
});
|
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
test('should work with parenthesis', async () => {
|
2021-05-16 15:21:55 +02:00
|
|
|
const wc = new WhenClause('(test1 && test2) || test3 && (test4 && !test5)');
|
|
|
|
|
|
|
|
expect(wc.evaluate({
|
|
|
|
test1: true,
|
|
|
|
test2: true,
|
|
|
|
test3: true,
|
|
|
|
test4: true,
|
|
|
|
test5: true,
|
|
|
|
})).toBe(true);
|
|
|
|
|
|
|
|
expect(wc.evaluate({
|
|
|
|
test1: false,
|
|
|
|
test2: true,
|
|
|
|
test3: false,
|
|
|
|
test4: false,
|
|
|
|
test5: true,
|
|
|
|
})).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|