Browse Source

Merge pull request #5384 from nocodb/test/date-suite-use-dayjs

test: use dayjs
pull/5390/head
Raju Udava 2 years ago committed by GitHub
parent
commit
7c030e8392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      tests/playwright/package-lock.json
  2. 1
      tests/playwright/package.json
  3. 20
      tests/playwright/pages/Dashboard/TreeView.ts
  4. 36
      tests/playwright/tests/filters.spec.ts

11
tests/playwright/package-lock.json generated

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

1
tests/playwright/package.json

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

20
tests/playwright/pages/Dashboard/TreeView.ts

@ -23,10 +23,24 @@ export class TreeViewPage extends BasePage {
} }
async verifyVisibility({ isVisible }: { isVisible: boolean }) { async verifyVisibility({ isVisible }: { isVisible: boolean }) {
if (isVisible) { await this.rootPage.waitForTimeout(1000);
await expect(this.get()).toBeVisible();
const domElement = await this.get();
// get width of treeview dom element
const width = (await domElement.boundingBox()).width;
// if (isVisible) {
// await expect(this.get()).toBeVisible();
// } else {
// await expect(this.get()).not.toBeVisible();
// }
// border for treeview is 1px
// if not-visible, width should be < 5;
if (!isVisible) {
expect(width).toBeLessThan(5);
} else { } else {
await expect(this.get()).not.toBeVisible(); expect(width).toBeGreaterThan(5);
} }
} }

36
tests/playwright/tests/filters.spec.ts

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

Loading…
Cancel
Save