Adds a 'Cron' schedule type option to the scheduled task editor, allowing users to create and edit cron-based schedules through the UI. - Add cron expression input with inline validation (cron-parser) - Show next 4 upcoming run times as a preview - Provide clickable example chips (every 5min, hourly, Monday 9am, etc.) - Preserve cron expressions when editing existing cron tasks - Add cron.ts utility module for validation and next-run computation - Add i18n keys across all 8 locale files Closes #1586 Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
|
|
import { getNextRuns, isValidCronExpression } from './cron';
|
|
|
|
describe('cron helpers', () => {
|
|
test('accepts valid cron expressions', () => {
|
|
expect(isValidCronExpression('*/5 * * * *').valid).toBe(true);
|
|
expect(isValidCronExpression('0 9 * * 1').valid).toBe(true);
|
|
expect(isValidCronExpression('0 0 9 * * 1').valid).toBe(true);
|
|
});
|
|
|
|
test('rejects empty and invalid cron expressions', () => {
|
|
expect(isValidCronExpression('').valid).toBe(false);
|
|
expect(isValidCronExpression(' ').valid).toBe(false);
|
|
expect(isValidCronExpression('abc').valid).toBe(false);
|
|
expect(isValidCronExpression('61 * * * *').valid).toBe(false);
|
|
});
|
|
|
|
test('returns the requested number of next runs', () => {
|
|
const runs = getNextRuns('*/5 * * * *', 'UTC', 3);
|
|
|
|
expect(runs).toHaveLength(3);
|
|
expect(runs.every((run) => run instanceof Date && Number.isFinite(run.getTime()))).toBe(true);
|
|
});
|
|
|
|
test('returns an empty list for invalid expressions', () => {
|
|
expect(getNextRuns('not cron', 'UTC')).toEqual([]);
|
|
});
|
|
});
|