178 lines
5.0 KiB
TypeScript
178 lines
5.0 KiB
TypeScript
import { Page } from '@playwright/test';
|
|
|
|
/**
|
|
* Date picker panel identifiers
|
|
*/
|
|
export const DatePickerPanels = {
|
|
MIN_DATE: 'MinimumDt',
|
|
MAX_DATE: 'MaximumDt',
|
|
} as const;
|
|
|
|
/**
|
|
* Set the minimum date in the TimeSpan filter panel
|
|
* @param page - Playwright page object
|
|
* @param date - Date string in YYYY-MM-DD format or Date object
|
|
*/
|
|
export async function setMinDate(page: Page, date: string | Date): Promise<void> {
|
|
const dateStr = formatDateForInput(date);
|
|
const dateInput = page.locator('input[name="MinimumDt"]');
|
|
await dateInput.fill(dateStr);
|
|
await page.waitForTimeout(300);
|
|
}
|
|
|
|
/**
|
|
* Set the maximum date in the TimeSpan filter panel
|
|
* @param page - Playwright page object
|
|
* @param date - Date string in YYYY-MM-DD format or Date object
|
|
*/
|
|
export async function setMaxDate(page: Page, date: string | Date): Promise<void> {
|
|
const dateStr = formatDateForInput(date);
|
|
const dateInput = page.locator('input[name="MaximumDt"]');
|
|
await dateInput.fill(dateStr);
|
|
await page.waitForTimeout(300);
|
|
}
|
|
|
|
/**
|
|
* Set both minimum and maximum dates in the TimeSpan filter panel
|
|
* @param page - Playwright page object
|
|
* @param minDate - Minimum date string in YYYY-MM-DD format or Date object
|
|
* @param maxDate - Maximum date string in YYYY-MM-DD format or Date object
|
|
*/
|
|
export async function setDateRange(page: Page, minDate: string | Date, maxDate: string | Date): Promise<void> {
|
|
await setMinDate(page, minDate);
|
|
await setMaxDate(page, maxDate);
|
|
}
|
|
|
|
/**
|
|
* Get the current minimum date value
|
|
* @param page - Playwright page object
|
|
* @returns The date value as a string
|
|
*/
|
|
export async function getMinDate(page: Page): Promise<string> {
|
|
const dateInput = page.locator('input[name="MinimumDt"]');
|
|
return await dateInput.inputValue();
|
|
}
|
|
|
|
/**
|
|
* Get the current maximum date value
|
|
* @param page - Playwright page object
|
|
* @returns The date value as a string
|
|
*/
|
|
export async function getMaxDate(page: Page): Promise<string> {
|
|
const dateInput = page.locator('input[name="MaximumDt"]');
|
|
return await dateInput.inputValue();
|
|
}
|
|
|
|
/**
|
|
* Clear the minimum date field
|
|
* @param page - Playwright page object
|
|
*/
|
|
export async function clearMinDate(page: Page): Promise<void> {
|
|
const dateInput = page.locator('input[name="MinimumDt"]');
|
|
await dateInput.clear();
|
|
await page.waitForTimeout(300);
|
|
}
|
|
|
|
/**
|
|
* Clear the maximum date field
|
|
* @param page - Playwright page object
|
|
*/
|
|
export async function clearMaxDate(page: Page): Promise<void> {
|
|
const dateInput = page.locator('input[name="MaximumDt"]');
|
|
await dateInput.clear();
|
|
await page.waitForTimeout(300);
|
|
}
|
|
|
|
/**
|
|
* Clear both date fields
|
|
* @param page - Playwright page object
|
|
*/
|
|
export async function clearDateRange(page: Page): Promise<void> {
|
|
await clearMinDate(page);
|
|
await clearMaxDate(page);
|
|
}
|
|
|
|
/**
|
|
* Check if the TimeSpan filter panel is visible
|
|
* @param page - Playwright page object
|
|
* @returns true if visible
|
|
*/
|
|
export async function isTimeSpanPanelVisible(page: Page): Promise<boolean> {
|
|
const panel = page.locator('text=Filter by Time Span');
|
|
return await panel.isVisible({ timeout: 2000 }).catch(() => false);
|
|
}
|
|
|
|
/**
|
|
* Format a date for input into the date picker
|
|
* @param date - Date string or Date object
|
|
* @returns Date string in MM/DD/YYYY format (Radzen date picker format)
|
|
*/
|
|
function formatDateForInput(date: string | Date): string {
|
|
let d: Date;
|
|
|
|
if (typeof date === 'string') {
|
|
// Parse YYYY-MM-DD format
|
|
const parts = date.split('-');
|
|
if (parts.length === 3) {
|
|
d = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]));
|
|
} else {
|
|
d = new Date(date);
|
|
}
|
|
} else {
|
|
d = date;
|
|
}
|
|
|
|
// Format as MM/DD/YYYY for Radzen DatePicker
|
|
const month = String(d.getMonth() + 1).padStart(2, '0');
|
|
const day = String(d.getDate()).padStart(2, '0');
|
|
const year = d.getFullYear();
|
|
|
|
return `${month}/${day}/${year}`;
|
|
}
|
|
|
|
/**
|
|
* Common date ranges for testing
|
|
*/
|
|
export const TestDateRanges = {
|
|
/** Recent date range: 2020-01-01 to 2020-09-01 */
|
|
RECENT: {
|
|
min: '2020-01-01',
|
|
max: '2020-09-01',
|
|
},
|
|
/** Mid-range dates: 2018-01-01 to 2019-12-31 */
|
|
MID_RANGE: {
|
|
min: '2018-01-01',
|
|
max: '2019-12-31',
|
|
},
|
|
/** Historical date range: 2016-01-01 to 2017-12-31 */
|
|
HISTORICAL: {
|
|
min: '2016-01-01',
|
|
max: '2017-12-31',
|
|
},
|
|
/** Same day range: 2020-06-15 */
|
|
SAME_DAY: {
|
|
min: '2020-06-15',
|
|
max: '2020-06-15',
|
|
},
|
|
/** Start boundary: earliest date in database */
|
|
START_BOUNDARY: {
|
|
min: '1905-01-20',
|
|
max: '1905-12-31',
|
|
},
|
|
/** End boundary: latest date in database */
|
|
END_BOUNDARY: {
|
|
min: '2020-08-01',
|
|
max: '2020-09-01',
|
|
},
|
|
/** Invalid: min > max (for negative testing) */
|
|
INVALID_REVERSED: {
|
|
min: '2020-09-01',
|
|
max: '2020-01-01',
|
|
},
|
|
/** Future dates (for negative testing) */
|
|
FUTURE: {
|
|
min: '2025-01-01',
|
|
max: '2025-12-31',
|
|
},
|
|
} as const;
|