mirror of
https://gitlab.com/bramw/baserow.git
synced 2024-11-25 00:46:46 +00:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import parseBaserowFormula from '@baserow/modules/core/formula/parser/parser'
|
|
import JavascriptExecutor from '@baserow/modules/core/formula/parser/javascriptExecutor'
|
|
import {
|
|
VALID_FORMULA_TESTS,
|
|
INVALID_FORMULA_TESTS,
|
|
} from '@baserow_test_cases/formula_runtime_cases'
|
|
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
|
|
describe('JavascriptExecutor', () => {
|
|
let testApp = null
|
|
beforeAll(() => {
|
|
testApp = new TestApp()
|
|
})
|
|
|
|
test.each(VALID_FORMULA_TESTS)(
|
|
'should correctly resolve the formula %s',
|
|
({ formula, result, context }) => {
|
|
const tree = parseBaserowFormula(formula)
|
|
expect(
|
|
new JavascriptExecutor(
|
|
{
|
|
get(name) {
|
|
return testApp.store.$registry.get('runtimeFormulaFunction', name)
|
|
},
|
|
},
|
|
context
|
|
).visit(tree)
|
|
).toEqual(result)
|
|
}
|
|
)
|
|
|
|
test.each(INVALID_FORMULA_TESTS)(
|
|
'should correctly raise an error for formula %s',
|
|
({ formula, context }) => {
|
|
const tree = parseBaserowFormula(formula)
|
|
expect(() =>
|
|
new JavascriptExecutor(
|
|
{
|
|
get(name) {
|
|
return testApp.store.$registry.get('runtimeFormulaFunction', name)
|
|
},
|
|
},
|
|
context
|
|
).visit(tree)
|
|
).toThrow()
|
|
}
|
|
)
|
|
})
|