Browse Source

test: use dayjs

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5384/head
Raju Udava 2 years ago
parent
commit
c60e93278c
  1. 11
      tests/playwright/package-lock.json
  2. 1
      tests/playwright/package.json
  3. 38
      tests/playwright/tests/filters.spec.ts

11
tests/playwright/package-lock.json generated

@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.1",
"dayjs": "^1.11.7",
"express": "^4.18.2",
"nocodb-sdk": "file:../../packages/nocodb-sdk",
"xlsx": "^0.18.5"
@ -1183,6 +1184,11 @@
"node": ">= 8"
}
},
"node_modules/dayjs": {
"version": "1.11.7",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz",
"integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ=="
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -5796,6 +5802,11 @@
"which": "^2.0.1"
}
},
"dayjs": {
"version": "1.11.7",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz",
"integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ=="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",

1
tests/playwright/package.json

@ -44,6 +44,7 @@
},
"dependencies": {
"body-parser": "^1.20.1",
"dayjs": "^1.11.7",
"express": "^4.18.2",
"nocodb-sdk": "file:../../packages/nocodb-sdk",
"xlsx": "^0.18.5"

38
tests/playwright/tests/filters.spec.ts

@ -5,6 +5,7 @@ import { ToolbarPage } from '../pages/Dashboard/common/Toolbar';
import { UITypes } from 'nocodb-sdk';
import { Api } from 'nocodb-sdk';
import { rowMixedValue } from '../setup/xcdb-records';
import dayjs from 'dayjs';
let dashboard: DashboardPage, toolbar: ToolbarPage;
let context: any;
@ -654,19 +655,23 @@ test.describe('Filter Tests: Select based', () => {
// Date & Time related
//
test.describe('Filter Tests: Date based', () => {
const today = new Date().setHours(0, 0, 0, 0);
const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1)).setHours(0, 0, 0, 0);
const yesterday = new Date(new Date().setDate(new Date().getDate() - 1)).setHours(0, 0, 0, 0);
const oneWeekAgo = new Date(new Date().setDate(new Date().getDate() - 7)).setHours(0, 0, 0, 0);
const oneWeekFromNow = new Date(new Date().setDate(new Date().getDate() + 7)).setHours(0, 0, 0, 0);
const oneMonthAgo = new Date(new Date().setMonth(new Date().getMonth() - 1)).setHours(0, 0, 0, 0);
const oneMonthFromNow = new Date(new Date().setMonth(new Date().getMonth() + 1)).setHours(0, 0, 0, 0);
const daysAgo45 = new Date(new Date().setDate(new Date().getDate() - 45)).setHours(0, 0, 0, 0);
const daysFromNow45 = new Date(new Date().setDate(new Date().getDate() + 45)).setHours(0, 0, 0, 0);
const thisMonth15 = new Date(new Date().setDate(15)).setHours(0, 0, 0, 0);
const oneYearAgo = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).setHours(0, 0, 0, 0);
const oneYearFromNow = new Date(new Date().setFullYear(new Date().getFullYear() + 1)).setHours(0, 0, 0, 0);
function getUTCEpochTime(date) {
return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0, 0);
}
test.describe.only('Filter Tests: Date based', () => {
const today = getUTCEpochTime(new Date());
const tomorrow = getUTCEpochTime(new Date(new Date().setDate(new Date().getDate() + 1)));
const yesterday = getUTCEpochTime(new Date(new Date().setDate(new Date().getDate() - 1)));
const oneWeekAgo = getUTCEpochTime(new Date(new Date().setDate(new Date().getDate() - 7)));
const oneWeekFromNow = getUTCEpochTime(new Date(new Date().setDate(new Date().getDate() + 7)));
const oneMonthAgo = getUTCEpochTime(dayjs().subtract(1, 'month').toDate());
const oneMonthFromNow = getUTCEpochTime(dayjs().add(1, 'month').toDate());
const daysAgo45 = getUTCEpochTime(new Date(new Date().setDate(new Date().getDate() - 45)));
const daysFromNow45 = getUTCEpochTime(new Date(new Date().setDate(new Date().getDate() + 45)));
const thisMonth15 = getUTCEpochTime(new Date(new Date().setDate(15)));
const oneYearAgo = getUTCEpochTime(new Date(new Date().setFullYear(new Date().getFullYear() - 1)));
const oneYearFromNow = getUTCEpochTime(new Date(new Date().setFullYear(new Date().getFullYear() + 1)));
async function dateTimeBasedFilterTest(dataType, setCount) {
await dashboard.closeTab({ title: 'Team & Auth' });
@ -679,8 +684,7 @@ test.describe('Filter Tests: Date based', () => {
// records array with time set to 00:00:00; store time in unix epoch
const recordsTimeSetToZero = records.list.map(r => {
const date = new Date(r[dataType]);
date.setHours(0, 0, 0, 0);
return date.getTime();
return getUTCEpochTime(date);
});
const isFilterList = [
@ -977,11 +981,11 @@ test.describe('Filter Tests: Date based', () => {
});
test('Date : filters-1', async () => {
await dateTimeBasedFilterTest('Date', 1);
await dateTimeBasedFilterTest('Date', 0);
});
test('Date : filters-2', async () => {
await dateTimeBasedFilterTest('Date', 2);
await dateTimeBasedFilterTest('Date', 1);
});
});

Loading…
Cancel
Save