super-productivity/e2e/commands/addTaskWithReminder.ts
Johannes Millan a8e3c46d3d test: fix e2e
2024-09-18 15:11:13 +02:00

65 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { AddTaskWithReminderParams, NBrowser } from '../n-browser-interface';
const TASK = 'task';
const SCHEDULE_TASK_ITEM = 'task-detail-item:nth-child(2)';
const DIALOG = 'mat-dialog-container';
const DIALOG_SUBMIT = `${DIALOG} mat-dialog-actions button:last-of-type`;
const TIME_INP = 'input[type="time"]';
const M = 60 * 1000;
// being slightly longer than a minute prevents the edge case
// of the wrong minute if the rest before takes to long
const DEFAULT_DELTA = 1.2 * M;
// NOTE: needs to
// be executed from work view
module.exports = {
async command(
this: NBrowser,
{
title,
taskSel = TASK,
scheduleTime = Date.now() + DEFAULT_DELTA,
}: AddTaskWithReminderParams,
) {
const d = new Date(scheduleTime);
return this.addTask(title)
.openPanelForTask(taskSel)
.waitForElementVisible(SCHEDULE_TASK_ITEM)
.click(SCHEDULE_TASK_ITEM)
.waitForElementVisible(DIALOG)
.pause(30)
.waitForElementVisible(TIME_INP)
.pause(50)
.setValue(TIME_INP, getTimeVal(d))
.pause(50)
.waitForElementVisible(DIALOG_SUBMIT)
.click(DIALOG_SUBMIT)
.waitForElementNotPresent(DIALOG);
},
};
const getTimeVal = (d: Date): string => {
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
const v = new Date(d).toLocaleTimeString('en-GB', {
hour: '2-digit',
minute: '2-digit',
hour12: isBrowserLocaleClockType12h(),
timeZone: tz,
});
console.log(
`Enter time input value ${v} ${tz}; 12h: ${isBrowserLocaleClockType12h()}`,
);
return v;
};
const isBrowserLocaleClockType12h = (): boolean => {
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
const parts = new Intl.DateTimeFormat(locale, { hour: 'numeric' }).formatToParts(
new Date(),
);
return parts.some((part) => part.type === 'dayPeriod');
};