Browse Source

test: extDB offset corrections

pull/5642/head
Raju Udava 2 years ago
parent
commit
f91935b925
  1. 67
      tests/playwright/tests/db/timezone.spec.ts

67
tests/playwright/tests/db/timezone.spec.ts

@ -447,7 +447,10 @@ test.describe('External DB - DateTime column', async () => {
const expectedDisplayValues = { const expectedDisplayValues = {
pg: { pg: {
DatetimeWithoutTz: ['2023-04-27 10:00', '2023-04-27 10:00'], DatetimeWithoutTz: ['2023-04-27 10:00', '2023-04-27 10:00'],
DatetimeWithTz: ['2023-04-27 10:00', getDateTimeInLocalTimeZone('2023-04-27 04:30:00+00:00')], DatetimeWithTz: [
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'),
getDateTimeInLocalTimeZone('2023-04-27 04:30:00+00:00'),
],
}, },
sqlite: { sqlite: {
// without +HH:MM information, display value is same as inserted value // without +HH:MM information, display value is same as inserted value
@ -525,6 +528,10 @@ test.describe('External DB - DateTime column', async () => {
test('Verify display value, UI insert, API response', async () => { test('Verify display value, UI insert, API response', async () => {
// get timezone offset // get timezone offset
const timezoneOffset = new Date().getTimezoneOffset(); 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')}`;
await dashboard.treeView.openBase({ title: 'datetimetable' }); await dashboard.treeView.openBase({ title: 'datetimetable' });
await dashboard.treeView.openTable({ title: 'MyTable' }); await dashboard.treeView.openTable({ title: 'MyTable' });
@ -587,38 +594,42 @@ test.describe('External DB - DateTime column', async () => {
let dateTimeWithoutTz = records.list.map(record => record.DatetimeWithoutTz); let dateTimeWithoutTz = records.list.map(record => record.DatetimeWithoutTz);
let dateTimeWithTz = records.list.map(record => record.DatetimeWithTz); let dateTimeWithTz = records.list.map(record => record.DatetimeWithTz);
const expectedDateTimeWithoutTz = [ let expectedDateTimeWithoutTz = [];
'Thu, 27 Apr 2023 10:00:00 GMT', let expectedDateTimeWithTz = [];
'Thu, 27 Apr 2023 10:00:00 GMT',
'Thu, 27 Apr 2023 10:00:00 GMT', if (isSqlite(context)) {
expectedDateTimeWithoutTz = [
'2023-04-27 10:00:00',
'2023-04-27 10:00:00+05:30',
`2023-04-27 10:00:00${formattedOffset}`,
]; ];
const expectedDateTimeWithTz = [ expectedDateTimeWithTz = [
'Thu, 27 Apr 2023 10:00:00 GMT', '2023-04-27 10:00:00',
'Thu, 27 Apr 2023 10:00:00 GMT', '2023-04-27 10:00:00+05:30',
'Thu, 27 Apr 2023 10:00:00 GMT', `2023-04-27 10:00:00${formattedOffset}`,
]; ];
} else if (isPg(context)) {
if (isMysql(context)) { expectedDateTimeWithoutTz = ['2023-04-27 10:00:00', '2023-04-27 10:00:00', '2023-04-27 10:00:00'];
expectedDateTimeWithoutTz[1] = 'Thu, 27 Apr 2023 04:30:00 GMT'; expectedDateTimeWithTz = [
expectedDateTimeWithTz[1] = 'Thu, 27 Apr 2023 04:30:00 GMT'; '2023-04-27T10:00:00.000Z',
'2023-04-27T04:30:00.000Z',
new Date('2023-04-27T10:00:00').toISOString(),
];
} else if (isMysql(context)) {
expectedDateTimeWithoutTz = ['2023-04-27 10:00:00', '2023-04-27 04:30:00', '2023-04-27 10:00:00'];
expectedDateTimeWithTz = ['2023-04-27 10:00:00', '2023-04-27 04:30:00', '2023-04-27 10:00:00'];
} }
// convert to ISO string, skip seconds part or reset seconds to 00 // reset seconds to 00 using string functions in dateTimeWithoutTz
dateTimeWithoutTz = dateTimeWithoutTz.map(dateTimeStr => { dateTimeWithoutTz = dateTimeWithoutTz.map(
const dateObj = new Date(dateTimeStr); dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19)
dateObj.setSeconds(0); );
dateObj.setMinutes(dateObj.getMinutes() - timezoneOffset); dateTimeWithTz = dateTimeWithTz.map(
return dateObj.toUTCString(); dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19)
}); );
dateTimeWithTz = dateTimeWithTz.map(dateTimeStr => {
const dateObj = new Date(dateTimeStr);
dateObj.setSeconds(0);
dateObj.setMinutes(dateObj.getMinutes() - timezoneOffset);
return dateObj.toUTCString();
});
// console.log(dateTimeWithoutTz); // console.log('dateTimeWithoutTz', dateTimeWithoutTz);
// console.log(dateTimeWithTz); // console.log('dateTimeWithTz', dateTimeWithTz);
expect(dateTimeWithoutTz).toEqual(expectedDateTimeWithoutTz); expect(dateTimeWithoutTz).toEqual(expectedDateTimeWithoutTz);
expect(dateTimeWithTz).toEqual(expectedDateTimeWithTz); expect(dateTimeWithTz).toEqual(expectedDateTimeWithTz);

Loading…
Cancel
Save