|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import { test } from '@playwright/test'; |
|
|
|
|
import { DashboardPage } from '../../../pages/Dashboard'; |
|
|
|
|
import setup, { NcContext, unsetup } from '../../../setup'; |
|
|
|
|
import { enableQuickRun, isPg, isSqlite } from '../../../setup/db'; |
|
|
|
|
import { enableQuickRun, isMysql, isPg, isSqlite } from '../../../setup/db'; |
|
|
|
|
|
|
|
|
|
// Add formula to be verified here & store expected results for 5 rows
|
|
|
|
|
// Column data from City table (Sakila DB)
|
|
|
|
@ -19,6 +19,7 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
|
|
|
|
|
{ |
|
|
|
|
formula: '1 + 1', |
|
|
|
|
result: ['2', '2', '2', '2', '2'], |
|
|
|
|
unSupDbType: [], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formula: 'ADD({CityId}, {CountryId}) + AVG({CityId}, {CountryId}) + LEN({City})', |
|
|
|
@ -92,6 +93,7 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
|
|
|
|
|
{ |
|
|
|
|
formula: 'VALUE("12ab-c345")', |
|
|
|
|
result: ['-12345', '-12345', '-12345', '-12345', '-12345'], |
|
|
|
|
unSupDbType: ['sqlite3'], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formula: 'TRUE()', |
|
|
|
@ -101,19 +103,6 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
|
|
|
|
|
formula: 'FALSE()', |
|
|
|
|
result: ['0', '0', '0', '0', '0'], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formula: 'REGEX_MATCH({City}, "a[a-z]a")', |
|
|
|
|
result: ['0', '0', '0', '0', '1'], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
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: [ |
|
|
|
@ -137,12 +126,30 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
|
|
|
|
|
formula: 'RECORD_ID()', |
|
|
|
|
result: ['1', '2', '3', '4', '5'], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formula: 'REGEX_MATCH({City}, "a[a-z]a")', |
|
|
|
|
result: ['0', '0', '0', '0', '1'], |
|
|
|
|
unSupDbType: ['sqlite3'], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
// TODO: this is bug in mysql, its being case in-sensitive.
|
|
|
|
|
formula: 'REGEX_EXTRACT({City}, "a[a-z]a")', |
|
|
|
|
result: ['', '', '', '', 'ana'], |
|
|
|
|
unSupDbType: ['sqlite3'], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
// TODO: this is bug in mysql, its being case in-sensitive.
|
|
|
|
|
formula: 'REGEX_REPLACE({City}, "a[a-z]a","...")', |
|
|
|
|
result: ['A Corua (La Corua)', 'Abha', 'Abu Dhabi', 'Acua', 'Ad...'], |
|
|
|
|
unSupDbType: ['sqlite3'], |
|
|
|
|
}, |
|
|
|
|
]; |
|
|
|
|
else |
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
formula: `DATETIME_DIFF("2023/10/14", "2023/01/12", "y")`, |
|
|
|
|
result: ['0', '0', '0', '0', '0'], |
|
|
|
|
unSupDbType: [], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formula: `DATETIME_DIFF("2023-01-12", "2021-08-29", "y")`, |
|
|
|
@ -180,9 +187,16 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
|
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formula: `LOG({CityId}) + EXP({CityId}) + POWER({CityId}, 3) + SQRT({CountryId})`, |
|
|
|
|
result: isPg(context) |
|
|
|
|
result: |
|
|
|
|
isPg(context) || isSqlite(context) |
|
|
|
|
? ['13.04566088154786', '24.74547123273205', '57.61253379902822', '126.94617671688704', '283.9609869087087'] |
|
|
|
|
: ['13.04566088154786', '25.137588417628013', '58.23402483297667', '127.73041108667896', '284.8714548168068'], |
|
|
|
|
: [ |
|
|
|
|
'13.04566088154786', |
|
|
|
|
'25.137588417628013', |
|
|
|
|
'58.23402483297667', |
|
|
|
|
'127.73041108667896', |
|
|
|
|
'284.8714548168068', |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formula: `NOW()`, |
|
|
|
@ -245,26 +259,29 @@ test.describe('Virtual Columns', () => {
|
|
|
|
|
async function formulaTestSpec(index: number) { |
|
|
|
|
// close 'Team & Auth' tab
|
|
|
|
|
const formulaData = formulaDataByDbType(context, index); |
|
|
|
|
const dbType = context.base.sources[0].type; |
|
|
|
|
await dashboard.closeTab({ title: 'Team & Auth' }); |
|
|
|
|
|
|
|
|
|
await dashboard.treeView.openTable({ title: 'City' }); |
|
|
|
|
// Create formula column
|
|
|
|
|
// Create dummy formula column which will then be updated for every testcase
|
|
|
|
|
await dashboard.grid.column.create({ |
|
|
|
|
title: 'NC_MATH_0', |
|
|
|
|
type: 'Formula', |
|
|
|
|
formula: formulaData[1].formula, |
|
|
|
|
formula: '1 + 1', |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// verify different formula's
|
|
|
|
|
for (let i = 1; i < formulaData.length; i++) { |
|
|
|
|
// Sqlite does not support log function
|
|
|
|
|
if (isSqlite(context) && formulaData[i].formula.includes('LOG(')) continue; |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < formulaData.length; i++) { |
|
|
|
|
await dashboard.grid.column.openEdit({ |
|
|
|
|
title: 'NC_MATH_0', |
|
|
|
|
type: 'Formula', |
|
|
|
|
formula: formulaData[i].formula, |
|
|
|
|
}); |
|
|
|
|
if (formulaData[i].unSupDbType?.includes(dbType)) { |
|
|
|
|
// assert for message not supported or greyed out save button.
|
|
|
|
|
await dashboard.grid.column.saveFail({ errorMessage: 'Invalid Formula' }); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
await dashboard.grid.column.save({ isUpdated: true }); |
|
|
|
|
if (formulaData[i].formula !== `NOW()`) { |
|
|
|
|
await formulaResultVerify({ |
|
|
|
|