Files
nocodb/tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts
Ramesh Mane 56b5264177 Nc feat/new date time cell UI (#8546)
* feat(nc-gui): new date picker setup

* feat(nc-gui): new date picker

* fix(nc-gui): date cell form view validation issue

* fix(nc-gui): disable date cell type support in mobile view

* fix(nc-gui): small changes

* feat(nc-gui): new cell year and month picker

* fix(nc-gui): add updated date time picker setup

* feat: update date time cell picker

* fix(nc-gui): add now option in time picker

* fix(nc-gui): small changes

* fix(nc-gui): add support to update month, year from date picker

* fix(nc-gui): update date picker select mont/year flow

* fix(test): date selector test case

* fix(nc-gui): update dateTime cell time picker

* fix(test): update time picker test case

* chore(nc-gui): lint

* fix(nc-gui): invalid date issue

* fix(nc-gui): date time picker tab issue

* fix(nc-gui): year cell test fail issue

* fix(nc-gui): date picker filter test fail issue

* fix(test): survey form test fail issue

* fix(test): update year field fill handler test case

* fix(test): update bulk update test

* fix(nc-gui): datetime multiple api call issue

* fix(test): update timezone related test

* fix(test): timezone related test update

* fix(nc-gui): tab focus issue

* fix(test): filter datetime test udpate

* fix(test): ai review changes

* fix(nc-gui): date picker font weight issue

* fix(nc-gui): update year picker font weight

* fix(nc-gui): show full date from date time cell instead of truncate

* fix(nc-gui): date time picker ui changes

* fix(nc-gui): date time cell width issue

* fix(nc-gui): update datetime time option width according to time format

* fix(nc-gui): disable datetime input if cell is readonly

* fic(nc-gui): add new time picker

* feat(nc-gui): update time picker

* chore(nc-gui): cleanup unwanted code

* fix(test): update time cell test cases

* fix(nc-gui): multiple api calls

* fix(test): update time cell filter & bulk update test cases

* fix(test): revert unrelated changes

* fix(nc-gui): pr review changes

* fix(nc-gui): add clear datetime cell icon in non grid view
2024-05-23 18:18:24 +05:30

153 lines
4.6 KiB
TypeScript

import { Locator } from '@playwright/test';
import { CellPageObject } from '.';
import BasePage from '../../../Base';
export class DateTimeCellPageObject extends BasePage {
readonly cell: CellPageObject;
constructor(cell: CellPageObject) {
super(cell.rootPage);
this.cell = cell;
}
get({ index, columnHeader }: { index?: number; columnHeader: string }) {
return this.cell.get({ index, columnHeader });
}
async open({ index, columnHeader }: { index: number; columnHeader: string }) {
await this.rootPage.locator('.nc-grid-add-new-cell').click();
await this.rootPage.waitForTimeout(100);
await this.cell.dblclick({
index,
columnHeader,
});
}
async save() {
await this.rootPage.locator('button:has-text("Ok"):visible').click();
}
async selectDate({
// date formats in `YYYY-MM-DD`
date,
skipDate = false,
index,
columnHeader,
locator,
}: {
date: string;
skipDate?: boolean;
index?: number;
columnHeader?: string;
locator?: Locator;
}) {
// title date format needs to be YYYY-MM-DD
const [year, month, day] = date.split('-');
const dateLocator = locator ? locator : this.get({ index, columnHeader });
await dateLocator.click();
await dateLocator.locator('.nc-date-input').click();
// configure year
await this.rootPage.locator('.nc-year-picker-btn:visible').waitFor();
await this.rootPage.locator('.nc-year-picker-btn:visible').click();
await this.rootPage.locator('.nc-year-picker-btn:visible').waitFor();
let flag = true;
while (flag) {
const firstVisibleYear = await this.rootPage.locator('.nc-year-item').first().textContent();
const lastVisibleYear = await this.rootPage.locator('.nc-year-item').last().textContent();
if (+year >= +firstVisibleYear && +year <= +lastVisibleYear) {
flag = false;
} else if (+year < +firstVisibleYear) {
await this.rootPage.locator('.nc-prev-page-btn').click();
} else if (+year > +lastVisibleYear) {
await this.rootPage.locator('.nc-next-page-btn').click();
}
}
await this.rootPage.locator(`span[title="${year}"]`).waitFor();
await this.rootPage.locator(`span[title="${year}"]`).click({ force: true });
if (skipDate) {
await this.rootPage.locator(`span[title="${year}-${month}"]`).click();
return;
}
// configure month
await this.rootPage.locator('.nc-month-picker-btn:visible').click();
await this.rootPage.locator(`span[title="${year}-${month}"]`).click();
// configure day
await this.rootPage.locator(`span[title="${year}-${month}-${day}"]:visible`).click();
}
async selectTime({
// hour: 0 - 23
// minute: 0 - 59
// second: 0 - 59
hour,
minute,
second,
index,
columnHeader,
fillValue,
selectFromPicker = false,
locator,
}: {
hour: number;
minute: number;
second?: number | null;
index?: number;
columnHeader?: string;
fillValue: string;
selectFromPicker?: boolean;
locator?: Locator;
}) {
const timeLocator = locator ? locator : this.get({ index, columnHeader });
await timeLocator.click();
const timeInput = timeLocator.locator('.nc-time-input');
await timeInput.click();
const dropdown = this.rootPage.locator('.nc-picker-datetime.active');
await dropdown.waitFor({ state: 'visible' });
if (!selectFromPicker) {
await timeInput.fill(fillValue);
await this.rootPage.keyboard.press('Enter');
await this.rootPage.keyboard.press('Escape');
} else {
await dropdown
.locator(`[data-testid="time-option-${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}"]`)
.scrollIntoViewIfNeeded();
await dropdown
.locator(`[data-testid="time-option-${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}"]`)
.click();
}
await dropdown.waitFor({ state: 'hidden' });
}
async close() {
await this.rootPage.keyboard.press('Escape');
}
async setDateTime({ index, columnHeader, dateTime }: { index: number; columnHeader: string; dateTime: string }) {
const [date, time] = dateTime.split(' ');
const [hour, minute, _second] = time.split(':');
await this.open({ index, columnHeader });
await this.selectDate({ date, index, columnHeader });
await this.selectTime({ hour: +hour, minute: +minute, index, columnHeader, fillValue: time });
}
clickDateInput = async (locator: Locator) => {
await locator.locator('.nc-date-input').click();
};
clickTimeInput = async (locator: Locator) => {
await locator.locator('.nc-time-input').click();
};
}