From 05f26beda67eb8f5ffe530e383ad105fe820a54b Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Tue, 23 May 2023 08:25:23 +0530 Subject: [PATCH 1/4] test: enable datetime diff for sqlite Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- tests/playwright/tests/db/timezone.spec.ts | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/tests/playwright/tests/db/timezone.spec.ts b/tests/playwright/tests/db/timezone.spec.ts index ca7c341710..71a2326b75 100644 --- a/tests/playwright/tests/db/timezone.spec.ts +++ b/tests/playwright/tests/db/timezone.spec.ts @@ -657,24 +657,21 @@ test.describe.serial('External DB - DateTime column', async () => { dateTime: '2024-04-27 10:00:00', }); - if (!isSqlite(context)) { - // SQLite : output is in decimal format; MySQL & Postgres : output is in integer format - await verifyFormula({ - formula: [ - 'DATETIME_DIFF({DatetimeWithoutTz}, {DatetimeWithTz}, "days")', - 'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "days")', - ], - expectedDisplayValue: ['-366', '366'], - }); + await verifyFormula({ + formula: [ + 'DATETIME_DIFF({DatetimeWithoutTz}, {DatetimeWithTz}, "days")', + 'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "days")', + ], + expectedDisplayValue: ['-366', '366'], + }); - await verifyFormula({ - formula: [ - 'DATETIME_DIFF({DatetimeWithoutTz}, {DatetimeWithTz}, "months")', - 'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "months")', - ], - expectedDisplayValue: ['-12', '12'], - }); - } + await verifyFormula({ + formula: [ + 'DATETIME_DIFF({DatetimeWithoutTz}, {DatetimeWithTz}, "months")', + 'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "months")', + ], + expectedDisplayValue: ['-12', '12'], + }); }); test('Verify display value, UI insert, API response', async () => { From 270a15889713409715dbbeaf1e0d7f4756430225 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Tue, 23 May 2023 08:26:22 +0530 Subject: [PATCH 2/4] test: logs cleanup Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- tests/playwright/tests/db/timezone.spec.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/playwright/tests/db/timezone.spec.ts b/tests/playwright/tests/db/timezone.spec.ts index 71a2326b75..c966c2b9c8 100644 --- a/tests/playwright/tests/db/timezone.spec.ts +++ b/tests/playwright/tests/db/timezone.spec.ts @@ -802,9 +802,6 @@ test.describe.serial('External DB - DateTime column', async () => { dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19) ); - console.log('dateTimeWithoutTz', dateTimeWithoutTz); - console.log('dateTimeWithTz', dateTimeWithTz); - expect(dateTimeWithoutTz).toEqual(expectedDateTimeWithoutTz); expect(dateTimeWithTz).toEqual(expectedDateTimeWithTz); }); @@ -938,9 +935,6 @@ test.describe('Ext DB MySQL : DB Timezone configured as HKT', () => { dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19) ); - console.log('dateTimeWithoutTz', dateTimeWithoutTz); - console.log('dateTimeWithTz', dateTimeWithTz); - expect(dateTimeWithoutTz).toEqual(expectedDateTimeWithoutTz); expect(dateTimeWithTz).toEqual(expectedDateTimeWithTz); }); From 7d3e9b3a98b02f6cb1f3444dc7e3a0459aeb26a7 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Tue, 23 May 2023 08:30:35 +0530 Subject: [PATCH 3/4] test: common routine for browser timezone Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- tests/playwright/tests/db/timezone.spec.ts | 13 +++---------- tests/playwright/tests/utils/general.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/playwright/tests/db/timezone.spec.ts b/tests/playwright/tests/db/timezone.spec.ts index c966c2b9c8..a30c7e4d35 100644 --- a/tests/playwright/tests/db/timezone.spec.ts +++ b/tests/playwright/tests/db/timezone.spec.ts @@ -6,6 +6,7 @@ import { Api, UITypes } from 'nocodb-sdk'; import { ProjectsPage } from '../../pages/ProjectsPage'; import { isMysql, isPg, isSqlite } from '../../setup/db'; import { getKnexConfig } from '../utils/config'; +import { getBrowserTimezoneOffset } from '../utils/general'; let api: Api, records: any[]; const columns = [ @@ -680,11 +681,7 @@ test.describe.serial('External DB - DateTime column', async () => { await dashboard.rootPage.waitForTimeout(2000); // get timezone offset - const timezoneOffset = new Date().getTimezoneOffset(); - const hours = Math.floor(Math.abs(timezoneOffset) / 60); - const minutes = Math.abs(timezoneOffset % 60); - const sign = timezoneOffset <= 0 ? '+' : '-'; - const formattedOffset = `${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; + const formattedOffset = getBrowserTimezoneOffset(); await dashboard.treeView.openBase({ title: 'datetimetable' }); await dashboard.treeView.openTable({ title: 'MyTable' }); @@ -844,11 +841,7 @@ test.describe('Ext DB MySQL : DB Timezone configured as HKT', () => { } // get timezone offset - const timezoneOffset = new Date().getTimezoneOffset(); - const hours = Math.floor(Math.abs(timezoneOffset) / 60); - const minutes = Math.abs(timezoneOffset % 60); - const sign = timezoneOffset <= 0 ? '+' : '-'; - const formattedOffset = `${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; + const formattedOffset = getBrowserTimezoneOffset(); // connect after timezone is set await connectToExtDb(context); diff --git a/tests/playwright/tests/utils/general.ts b/tests/playwright/tests/utils/general.ts index 56a9e1a2b3..45e9c6c817 100644 --- a/tests/playwright/tests/utils/general.ts +++ b/tests/playwright/tests/utils/general.ts @@ -50,4 +50,14 @@ function getDefaultPwd() { return 'Password123.'; } -export { getTextExcludeIconText, isSubset, getIconText, getDefaultPwd }; +function getBrowserTimezoneOffset() { + // get timezone offset + const timezoneOffset = new Date().getTimezoneOffset(); + const hours = Math.floor(Math.abs(timezoneOffset) / 60); + const minutes = Math.abs(timezoneOffset % 60); + const sign = timezoneOffset <= 0 ? '+' : '-'; + const formattedOffset = `${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; + return formattedOffset; +} + +export { getTextExcludeIconText, isSubset, getIconText, getDefaultPwd, getBrowserTimezoneOffset }; From 63ad4a4781418737a1d432acf38a8f57eec51e80 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Tue, 23 May 2023 09:16:44 +0530 Subject: [PATCH 4/4] test: validate formula API response Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- tests/playwright/tests/db/timezone.spec.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/playwright/tests/db/timezone.spec.ts b/tests/playwright/tests/db/timezone.spec.ts index a30c7e4d35..d547926881 100644 --- a/tests/playwright/tests/db/timezone.spec.ts +++ b/tests/playwright/tests/db/timezone.spec.ts @@ -604,9 +604,11 @@ test.describe.serial('External DB - DateTime column', async () => { async function verifyFormula({ formula, expectedDisplayValue, + verifyApiResponse = true, }: { formula: string[]; expectedDisplayValue: string[]; + verifyApiResponse?: boolean; }) { // Update formula column to compute "month" instead of "day" await api.dbTableColumn.update(table_data.columns[3].id, { @@ -636,6 +638,22 @@ test.describe.serial('External DB - DateTime column', async () => { columnHeader: 'formula-2', value: expectedDisplayValue[1], }); + + // verify API response + if (verifyApiResponse) { + const records = await api.dbTableRow.list('noco', context.project.id, table_data.id, { limit: 10 }); + const formattedOffset = getBrowserTimezoneOffset(); + + // console.log(getDateTimeInUTCTimeZone(`${expectedDisplayValue[0]}${formattedOffset}`)); + // console.log(getDateTimeInUTCTimeZone(`${expectedDisplayValue[1]}${formattedOffset}`)); + + expect(records.list[2]['formula-1']).toEqual( + getDateTimeInUTCTimeZone(`${expectedDisplayValue[0]}${formattedOffset}`) + ); + expect(records.list[2]['formula-2']).toEqual( + getDateTimeInUTCTimeZone(`${expectedDisplayValue[1]}${formattedOffset}`) + ); + } } // verify display value for formula columns (formula-1, formula-2) @@ -664,6 +682,7 @@ test.describe.serial('External DB - DateTime column', async () => { 'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "days")', ], expectedDisplayValue: ['-366', '366'], + verifyApiResponse: false, }); await verifyFormula({ @@ -672,6 +691,7 @@ test.describe.serial('External DB - DateTime column', async () => { 'DATETIME_DIFF({DatetimeWithTz}, {DatetimeWithoutTz}, "months")', ], expectedDisplayValue: ['-12', '12'], + verifyApiResponse: false, }); });