Browse Source

feat(playwright): datetime tests

pull/4593/head
Wing-Kam Wong 2 years ago
parent
commit
34ffcd5215
  1. 21
      tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts
  2. 61
      tests/playwright/tests/columnDateTime.spec.ts

21
tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts

@ -14,18 +14,25 @@ export class DateTimeCellPageObject extends BasePage {
} }
async open({ index, columnHeader }: { index: number; columnHeader: string }) { async open({ index, columnHeader }: { index: number; columnHeader: string }) {
await this.rootPage.locator('.nc-grid-add-new-cell').click();
await this.cell.dblclick({ await this.cell.dblclick({
index, index,
columnHeader, columnHeader,
}); });
} }
async save() {
await this.rootPage.locator('button:has-text("Ok")').click();
}
async selectDate({ async selectDate({
// date in format `YYYY-MM-DD` // date formats in `YYYY-MM-DD`
date, date,
}: { }: {
date: string; date: string;
}) { }) {
// title date format needs to be YYYY-MM-DD
await this.rootPage.locator(`td[title="${date}"]`).click(); await this.rootPage.locator(`td[title="${date}"]`).click();
} }
@ -37,19 +44,19 @@ export class DateTimeCellPageObject extends BasePage {
minute, minute,
second, second,
}: { }: {
hour: string; hour: number;
minute: string; minute: number;
second?: string; second?: number | null;
}) { }) {
await this.rootPage await this.rootPage
.locator(`.ant-picker-time-panel-column:nth-child(1) > ant-picker-time-panel-cell:nth-child(${hour})`) .locator(`.ant-picker-time-panel-column:nth-child(1) > .ant-picker-time-panel-cell:nth-child(${hour + 1})`)
.click(); .click();
await this.rootPage await this.rootPage
.locator(`.ant-picker-time-panel-column:nth-child(2) > ant-picker-time-panel-cell:nth-child(${minute})`) .locator(`.ant-picker-time-panel-column:nth-child(2) > .ant-picker-time-panel-cell:nth-child(${minute + 1})`)
.click(); .click();
if (second != null) { if (second != null) {
await this.rootPage await this.rootPage
.locator(`.ant-picker-time-panel-column:nth-child(3) > ant-picker-time-panel-cell:nth-child(${second})`) .locator(`.ant-picker-time-panel-column:nth-child(3) > .ant-picker-time-panel-cell:nth-child(${second + 1})`)
.click(); .click();
} }
} }

61
tests/playwright/tests/columnDateTime.spec.ts

@ -2,59 +2,57 @@ import { test } from '@playwright/test';
import { DashboardPage } from '../pages/Dashboard'; import { DashboardPage } from '../pages/Dashboard';
import setup from '../setup'; import setup from '../setup';
// Storing one additional dummy value "10" at end of every input array
// this will trigger update to previously committed data
const dateTimeData = [ const dateTimeData = [
{ {
dateFormat: 'YYYY-MM-DD', dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm', timeFormat: 'HH:mm',
date: '2022-12-12', date: '2022-12-12',
hour: '10', hour: 10,
minute: '20', minute: 20,
output: '2022-12-12 10:20', output: '2022-12-12 10:20',
}, },
{ {
dateFormat: 'YYYY-MM-DD', dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm:ss', timeFormat: 'HH:mm:ss',
date: '2022-12-12', date: '2022-12-11',
hour: '20', hour: 20,
minute: '30', minute: 30,
second: '40', second: 40,
output: '2022-12-12 20:30:40', output: '2022-12-11 20:30:40',
}, },
{ {
dateFormat: 'YYYY/MM/DD', dateFormat: 'YYYY/MM/DD',
timeFormat: 'HH:mm', timeFormat: 'HH:mm',
date: '2022/12/12', date: '2022-12-13',
hour: '10', hour: 10,
minute: '20', minute: 20,
output: '2022/12/12 10:20', output: '2022/12/13 10:20',
}, },
{ {
dateFormat: 'YYYY/MM/DD', dateFormat: 'YYYY/MM/DD',
timeFormat: 'HH:mm:ss', timeFormat: 'HH:mm:ss',
date: '2022/12/12', date: '2022-12-14',
hour: '5', hour: 5,
minute: '30', minute: 30,
second: '40', second: 40,
output: '2022/12/12 05:30:40', output: '2022/12/14 05:30:40',
}, },
{ {
dateFormat: 'DD-MM-YYYY', dateFormat: 'DD-MM-YYYY',
timeFormat: 'HH:mm', timeFormat: 'HH:mm',
date: '25-11-2022', date: '2022-12-10',
hour: '3', hour: 4,
minute: '20', minute: 30,
output: '12-12-2022 03:20', output: '10-12-2022 04:30',
}, },
{ {
dateFormat: 'DD-MM-YYYY', dateFormat: 'DD-MM-YYYY',
timeFormat: 'HH:mm:ss', timeFormat: 'HH:mm:ss',
date: '25-11-2022', date: '2022-12-26',
hour: '2', hour: 2,
minute: '30', minute: 30,
second: '40', second: 40,
output: '25-11-2022 02:30:40', output: '26-12-2022 02:30:40',
}, },
]; ];
@ -86,6 +84,8 @@ test.describe('DateTime Column', () => {
timeFormat: dateTimeData[i].timeFormat, timeFormat: dateTimeData[i].timeFormat,
}); });
await dashboard.grid.column.save({ isUpdated: true });
await dashboard.grid.cell.dateTime.open({ await dashboard.grid.cell.dateTime.open({
index: 0, index: 0,
columnHeader: 'NC_DATETIME_0', columnHeader: 'NC_DATETIME_0',
@ -94,13 +94,16 @@ test.describe('DateTime Column', () => {
await dashboard.grid.cell.dateTime.selectDate({ await dashboard.grid.cell.dateTime.selectDate({
date: dateTimeData[i].date, date: dateTimeData[i].date,
}); });
await dashboard.grid.cell.dateTime.selectTime({ await dashboard.grid.cell.dateTime.selectTime({
hour: dateTimeData[i].hour, hour: dateTimeData[i].hour,
minute: dateTimeData[i].minute, minute: dateTimeData[i].minute,
second: dateTimeData[i].second,
}); });
await dashboard.grid.cell.dateTime.close();
await dashboard.grid.cell.verify({ await dashboard.grid.cell.dateTime.save();
await dashboard.grid.cell.verifyDateCell({
index: 0, index: 0,
columnHeader: 'NC_DATETIME_0', columnHeader: 'NC_DATETIME_0',
value: dateTimeData[i].output, value: dateTimeData[i].output,

Loading…
Cancel
Save