多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

77 lines
2.0 KiB

import {
FormulaDataTypes,
validateFormulaAndExtractTreeWithType,
} from './formulaHelpers';
import UITypes from './UITypes';
describe('Formula parsing and type validation', () => {
it('Simple formula', async () => {
const result = await validateFormulaAndExtractTreeWithType({
formula: '1 + 2',
columns: [],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});
expect(result.dataType).toEqual(FormulaDataTypes.NUMERIC);
});
it('Formula with IF condition', async () => {
const result = await validateFormulaAndExtractTreeWithType({
formula: 'IF({column}, "Found", BLANK())',
columns: [
{
id: 'cid',
title: 'column',
uidt: UITypes.Number,
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});
expect(result.dataType).toEqual(FormulaDataTypes.STRING);
});
it('Complex formula', async () => {
const result = await validateFormulaAndExtractTreeWithType({
formula:
'SWITCH({column2},"value1",IF({column1}, "Found", BLANK()),"value2", 2)',
columns: [
{
id: 'id1',
title: 'column1',
uidt: UITypes.Number,
},
{
id: 'id2',
title: 'column2',
uidt: UITypes.SingleLineText,
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});
expect(result.dataType).toEqual(FormulaDataTypes.STRING);
const result1 = await validateFormulaAndExtractTreeWithType({
formula: 'SWITCH({column2},"value1",IF({column1}, 1, 2),"value2", 2)',
columns: [
{
id: 'id1',
title: 'column1',
uidt: UITypes.Number,
},
{
id: 'id2',
title: 'column2',
uidt: UITypes.SingleLineText,
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});
expect(result1.dataType).toEqual(FormulaDataTypes.NUMERIC);
});
});