Browse Source

test: date datatype filter tests

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5185/head
Raju Udava 2 years ago
parent
commit
fea0340262
  1. 17
      tests/playwright/pages/Dashboard/common/Toolbar/Filter.ts
  2. 259
      tests/playwright/tests/filters.spec.ts

17
tests/playwright/pages/Dashboard/common/Toolbar/Filter.ts

@ -84,6 +84,23 @@ export class ToolbarFilterPage extends BasePage {
if (value) { if (value) {
let fillFilter: any = null; let fillFilter: any = null;
switch (dataType) { switch (dataType) {
case UITypes.Date:
if (opSubType === 'exact date') {
await this.get().locator('.nc-filter-value-select').click();
await this.rootPage.locator(`.ant-picker-dropdown:visible`);
await this.rootPage.locator(`.ant-picker-cell-inner:has-text("${value}")`).click();
} else {
fillFilter = () => this.rootPage.locator('.nc-filter-value-select > input').last().fill(value);
await this.waitForResponse({
uiAction: fillFilter,
httpMethodsToMatch: ['GET'],
requestUrlPathToMatch: isLocallySaved ? `/api/v1/db/public/` : `/api/v1/db/data/noco/`,
});
await this.toolbar.parent.dashboard.waitForLoaderToDisappear();
await this.toolbar.parent.waitLoading();
break;
}
break;
case UITypes.Duration: case UITypes.Duration:
await this.get().locator('.nc-filter-value-select').locator('input').fill(value); await this.get().locator('.nc-filter-value-select').locator('input').fill(value);
break; break;

259
tests/playwright/tests/filters.spec.ts

@ -596,7 +596,7 @@ test.describe('Filter Tests: Select based', () => {
// Date & Time related // Date & Time related
// //
test.describe.skip('Filter Tests: Date & Time related', () => { test.describe('Filter Tests: Date & Time related', () => {
async function dateTimeBasedFilterTest(dataType) { async function dateTimeBasedFilterTest(dataType) {
await dashboard.closeTab({ title: 'Team & Auth' }); await dashboard.closeTab({ title: 'Team & Auth' });
await dashboard.treeView.openTable({ title: 'dateTimeBased' }); await dashboard.treeView.openTable({ title: 'dateTimeBased' });
@ -605,80 +605,259 @@ test.describe.skip('Filter Tests: Date & Time related', () => {
await dashboard.gotoSettings(); await dashboard.gotoSettings();
await dashboard.settings.toggleNullEmptyFilters(); await dashboard.settings.toggleNullEmptyFilters();
// store date in YYYY-MM-DD format // records array with time set to 00:00:00; store time in unix epoch
const today = new Date().toISOString().split('T')[0]; const recordsTimeSetToZero = records.list.map(r => {
const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1)).toISOString().split('T')[0]; const date = new Date(r[dataType]);
const yesterday = new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().split('T')[0]; date.setHours(0, 0, 0, 0);
const oneWeekAgo = new Date(new Date().setDate(new Date().getDate() - 7)).toISOString().split('T')[0]; return date.getTime();
const oneWeekFromNow = new Date(new Date().setDate(new Date().getDate() + 7)).toISOString().split('T')[0]; });
const oneMonthAgo = new Date(new Date().setMonth(new Date().getMonth() - 1)).toISOString().split('T')[0];
const oneMonthFromNow = new Date(new Date().setMonth(new Date().getMonth() + 1)).toISOString().split('T')[0];
const daysAgo45 = new Date(new Date().setDate(new Date().getDate() + 45)).toISOString().split('T')[0];
const daysFromNow45 = new Date(new Date().setDate(new Date().getDate() - 45)).toISOString().split('T')[0];
console.log(today); 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);
const isFilterList = [
{
opSub: 'today',
rowCount: recordsTimeSetToZero.filter(r => r === today).length,
},
{
opSub: 'tomorrow',
rowCount: recordsTimeSetToZero.filter(r => r === tomorrow).length,
},
{
opSub: 'yesterday',
rowCount: recordsTimeSetToZero.filter(r => r === yesterday).length,
},
{
opSub: 'one week ago',
rowCount: recordsTimeSetToZero.filter(r => r === oneWeekAgo).length,
},
{
opSub: 'one week from now',
rowCount: recordsTimeSetToZero.filter(r => r === oneWeekFromNow).length,
},
{
opSub: 'one month ago',
rowCount: recordsTimeSetToZero.filter(r => r === oneMonthAgo).length,
},
{
opSub: 'one month from now',
rowCount: recordsTimeSetToZero.filter(r => r === oneMonthFromNow).length,
},
{
opSub: 'number of days ago',
value: 45,
rowCount: recordsTimeSetToZero.filter(r => r === daysAgo45).length,
},
{
opSub: 'number of days from now',
value: 45,
rowCount: recordsTimeSetToZero.filter(r => r === daysFromNow45).length,
},
{
opSub: 'exact date',
value: 15,
rowCount: recordsTimeSetToZero.filter(r => r === thisMonth15).length,
},
];
const filterList = [ for (let i = 0; i < isFilterList.length; i++) {
await verifyFilter({
column: dataType,
opType: 'is',
opSubType: isFilterList[i].opSub,
value: isFilterList[i]?.value?.toString() || '',
result: { rowCount: isFilterList[i].rowCount },
dataType: dataType,
});
}
// mutually exclusive of "is" filter list
for (let i = 0; i < isFilterList.length; i++) {
await verifyFilter({
column: dataType,
opType: 'is not',
opSubType: isFilterList[i].opSub,
value: isFilterList[i]?.value?.toString() || '',
result: { rowCount: 800 - isFilterList[i].rowCount },
dataType: dataType,
});
}
// "is after" filter list
const isAfterFilterList = [
{ {
op: 'is',
opSub: 'today', opSub: 'today',
rowCount: records.list.filter(r => r[dataType].split('T')[0] === today).length, rowCount: recordsTimeSetToZero.filter(r => r > today).length,
}, },
{ {
op: 'is',
opSub: 'tomorrow', opSub: 'tomorrow',
rowCount: records.list.filter(r => r[dataType].split('T')[0] === tomorrow).length, rowCount: recordsTimeSetToZero.filter(r => r > tomorrow).length,
}, },
{ {
op: 'is',
opSub: 'yesterday', opSub: 'yesterday',
rowCount: records.list.filter(r => r[dataType].split('T')[0] === yesterday).length, rowCount: recordsTimeSetToZero.filter(r => r > yesterday).length,
}, },
{ {
op: 'is', opSub: 'one week ago',
opSub: 'oneWeekAgo', rowCount: recordsTimeSetToZero.filter(r => r > oneWeekAgo).length,
rowCount: records.list.filter(r => r[dataType].split('T')[0] === oneWeekAgo).length,
}, },
{ {
op: 'is', opSub: 'one week from now',
opSub: 'oneWeekFromNow', rowCount: recordsTimeSetToZero.filter(r => r > oneWeekFromNow).length,
rowCount: records.list.filter(r => r[dataType].split('T')[0] === oneWeekFromNow).length,
}, },
{ {
op: 'is', opSub: 'one month ago',
opSub: 'oneMonthAgo', rowCount: recordsTimeSetToZero.filter(r => r > oneMonthAgo).length,
rowCount: records.list.filter(r => r[dataType].split('T')[0] === oneMonthAgo).length,
}, },
{ {
op: 'is', opSub: 'one month from now',
opSub: 'oneMonthFromNow', rowCount: recordsTimeSetToZero.filter(r => r > oneMonthFromNow).length,
rowCount: records.list.filter(r => r[dataType].split('T')[0] === oneMonthFromNow).length,
}, },
{ {
op: 'is', opSub: 'number of days ago',
opSub: 'daysAgo',
value: 45, value: 45,
rowCount: records.list.filter(r => r[dataType].split('T')[0] === daysAgo45).length, rowCount: recordsTimeSetToZero.filter(r => r > daysAgo45).length,
}, },
{ {
op: 'is', opSub: 'number of days from now',
opSub: 'daysFromNow',
value: 45, value: 45,
rowCount: records.list.filter(r => r[dataType].split('T')[0] === daysFromNow45).length, rowCount: recordsTimeSetToZero.filter(r => r > daysFromNow45).length,
},
{
opSub: 'exact date',
value: 15,
rowCount: recordsTimeSetToZero.filter(r => r > thisMonth15).length,
},
];
for (let i = 0; i < isAfterFilterList.length; i++) {
await verifyFilter({
column: dataType,
opType: 'is after',
opSubType: isAfterFilterList[i].opSub,
value: isAfterFilterList[i]?.value?.toString() || '',
result: { rowCount: isAfterFilterList[i].rowCount },
dataType: dataType,
});
}
for (let i = 0; i < isAfterFilterList.length; i++) {
await verifyFilter({
column: dataType,
opType: 'is on or after',
opSubType: isAfterFilterList[i].opSub,
value: isAfterFilterList[i]?.value?.toString() || '',
result: { rowCount: 1 + isAfterFilterList[i].rowCount },
dataType: dataType,
});
}
for (let i = 0; i < isAfterFilterList.length; i++) {
await verifyFilter({
column: dataType,
opType: 'is before',
opSubType: isAfterFilterList[i].opSub,
value: isAfterFilterList[i]?.value?.toString() || '',
result: { rowCount: 800 - isAfterFilterList[i].rowCount - 1 },
dataType: dataType,
});
}
for (let i = 0; i < isAfterFilterList.length; i++) {
await verifyFilter({
column: dataType,
opType: 'is on or before',
opSubType: isAfterFilterList[i].opSub,
value: isAfterFilterList[i]?.value?.toString() || '',
result: { rowCount: 800 - isAfterFilterList[i].rowCount },
dataType: dataType,
});
}
// "is within" filter list
const isWithinFilterList = [
{
opSub: 'the past week',
rowCount: recordsTimeSetToZero.filter(r => r >= oneWeekAgo && r <= today).length,
},
{
opSub: 'the past month',
rowCount: recordsTimeSetToZero.filter(r => r >= oneMonthAgo && r <= today).length,
},
{
opSub: 'the past year',
rowCount: recordsTimeSetToZero.filter(r => r >= oneYearAgo && r <= today).length,
},
{
opSub: 'the next week',
rowCount: recordsTimeSetToZero.filter(r => r >= today && r <= oneWeekFromNow).length,
},
{
opSub: 'the next month',
rowCount: recordsTimeSetToZero.filter(r => r >= today && r <= oneMonthFromNow).length,
},
{
opSub: 'the next year',
rowCount: recordsTimeSetToZero.filter(r => r >= today && r <= oneYearFromNow).length,
},
{
opSub: 'the next number of days',
value: 45,
rowCount: recordsTimeSetToZero.filter(r => r >= today && r <= daysFromNow45).length,
},
{
opSub: 'the past number of days',
value: 45,
rowCount: recordsTimeSetToZero.filter(r => r >= daysAgo45 && r <= today).length,
},
];
for (let i = 0; i < isWithinFilterList.length; i++) {
await verifyFilter({
column: dataType,
opType: 'is within',
opSubType: isWithinFilterList[i].opSub,
value: isWithinFilterList[i]?.value?.toString() || '',
result: { rowCount: isWithinFilterList[i].rowCount },
dataType: dataType,
});
}
// rest of the filters (without subop type)
const filterList = [
{
opType: 'is blank',
rowCount: records.list.filter(r => r[dataType] === null || r[dataType] === '').length,
},
{
opType: 'is not blank',
rowCount: records.list.filter(r => r[dataType] !== null && r[dataType] !== '').length,
}, },
]; ];
for (let i = 0; i < filterList.length; i++) { for (let i = 0; i < filterList.length; i++) {
await verifyFilter({ await verifyFilter({
column: dataType, column: dataType,
opType: filterList[i].op, opType: filterList[i].opType,
opSubType: filterList[i].opSub, opSubType: null,
value: filterList[i]?.value?.toString() || '', value: null,
result: { rowCount: filterList[i].rowCount }, result: { rowCount: filterList[i].rowCount },
dataType: dataType, dataType: dataType,
}); });
} }
} }
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
context = await setup({ page }); context = await setup({ page });
dashboard = new DashboardPage(page, context.project); dashboard = new DashboardPage(page, context.project);

Loading…
Cancel
Save