Browse Source

test: add playwright tests for formula

pull/7019/head
Pranav C 1 year ago
parent
commit
22a05c0403
  1. 28
      packages/nocodb/src/db/functionMappings/commonFns.ts
  2. 30
      packages/nocodb/src/db/functionMappings/pg.ts
  3. 2
      tests/playwright/.env.example
  4. 61
      tests/playwright/tests/db/columns/columnFormula.spec.ts

28
packages/nocodb/src/db/functionMappings/commonFns.ts

@ -191,4 +191,32 @@ export default {
builder: knex.raw('? ${colAlias}', [pt.arguments.length]),
};
},
ROUNDDOWN: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
let precisionBuilder = knex.raw('0');
if (pt.arguments[1]) {
const { builder } = await fn(pt.arguments[1]);
precisionBuilder = builder;
}
return {
builder: knex.raw(
`ROUND(FLOOR((${valueBuilder}) * POWER(10, ${precisionBuilder})) / POWER(10, ${precisionBuilder}))${colAlias}`,
),
};
},
ROUNDUP: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
let precisionBuilder = knex.raw('0');
if (pt.arguments[1]) {
const { builder } = await fn(pt.arguments[1]);
precisionBuilder = builder;
}
return {
builder: knex.raw(
`ROUND(CEIL((${valueBuilder}) * POWER(10, ${precisionBuilder})) / POWER(10, ${precisionBuilder}))${colAlias}`,
),
};
},
};

30
packages/nocodb/src/db/functionMappings/pg.ts

@ -253,36 +253,6 @@ const pg = {
),
};
},
// todo: move to common and use existing functions
ROUNDDOWN: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
let precisionBuilder = knex.raw('0');
if (pt.arguments[1]) {
const { builder } = await fn(pt.arguments[1]);
precisionBuilder = builder;
}
return {
builder: knex.raw(
`ROUND(FLOOR(${valueBuilder} * POWER(10, ${precisionBuilder})) / POWER(10, ${precisionBuilder}))${colAlias}`,
),
};
},
ROUNDUP: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
let precisionBuilder = knex.raw('0');
if (pt.arguments[1]) {
const { builder } = await fn(pt.arguments[1]);
precisionBuilder = builder;
}
return {
builder: knex.raw(
`ROUND(CEIL(${valueBuilder} * POWER(10, ${precisionBuilder})) / POWER(10, ${precisionBuilder}))${colAlias}`,
),
};
},
VALUE: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const value = (await fn(pt.arguments[0])).builder.toString();

2
tests/playwright/.env.example

@ -1 +1 @@
E2E_DEV_DB_TYPE=sqlite
E2E_DEV_DB_TYPE=sqlite

61
tests/playwright/tests/db/columns/columnFormula.spec.ts

@ -14,7 +14,7 @@ import { enableQuickRun, isPg, isSqlite } from '../../../setup/db';
* Adana 2006-02-15 04:45:25 663 Baha Blanca Parkway Turkey
*/
const formulaDataByDbType = (context: NcContext, index: number) => {
if (index === 0)
if (index === false)
return [
{
formula: '1 + 1',
@ -76,6 +76,63 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
formula: `DATETIME_DIFF("2023/01/12", "2023/10/14", "y")`,
result: ['0', '0', '0', '0', '0'],
},
{
formula: 'IF({CityId} == 1, "TRUE", BLANK())',
result: ['TRUE', '', '', '', ''],
},
{
formula: 'EVEN({CityId})',
result: ['2', '2', '4', '4', '6'],
},
{
formula: 'ODD({CityId})',
result: ['1', '3', '3', '5', '5'],
},
{
formula: 'VALUE("12ab-c345")',
result: ['-12345', '-12345', '-12345', '-12345', '-12345'],
},
{
formula: 'TRUE()',
result: ['1', '1', '1', '1', '1'],
},
{
formula: 'FALSE()',
result: ['0', '0', '0', '0', '0'],
},
{
formula: 'REGEX_MATCH({City}, "a[a-z]a")',
result: ['false', 'false', 'false', 'false', 'true'],
},
{
formula: 'REGEX_EXTRACT({City}, "a[a-z]a")',
result: ['', '', '', '', 'ana'],
},
{
formula: 'REGEX_REPLACE({City}, "a[a-z]a","...")',
result: ['A Corua (La Corua)', 'Abha', 'Abu Dhabi', 'Acua', 'Ad...'],
},
{
formula: '"City Name: " & {City}',
result: [
'City Name: A Corua (La Corua)',
'City Name: Abha',
'City Name: Abu Dhabi',
'City Name: Acua',
'City Name: Adana',
],
},
{
formula: 'ROUNDDOWN({CityId} + 2.49, 1)',
result: ['3', '4', '5', '6', '7'],
},
{
formula: 'ROUNDUP({CityId} + 2.49, 1)',
result: ['4', '5', '6', '7', '8'],
},
];
else
return [
@ -216,7 +273,7 @@ test.describe('Virtual Columns', () => {
await dashboard.closeTab({ title: 'City' });
}
test('Formula - suite 0', async () => {
test.only('Formula - suite 0', async () => {
await formulaTestSpec(0);
});
test('Formula - suite 1', async () => {

Loading…
Cancel
Save