Files
hyprcrd/public/js/test/calendar-popup.test.js
T
2026-04-09 22:18:45 +02:00

70 lines
2.3 KiB
JavaScript

import { describe, it, afterEach, expect, $, $$, click, sleep, closeAll } from './runner.js';
describe('Calendar: Day Click', () => {
afterEach(() => closeAll());
it('clicking a day opens day popup', async () => {
click('#calendar-btn');
await sleep(300);
// Find a day cell in the current month (not dp-out)
const days = $$('#cal-grid .cal-day:not(.cal-out)');
if (!days.length) return;
// Click the first day
days[0].click();
await sleep(300);
// Day popup should appear
const popup = document.querySelector('.cal-day-popup, [class*="day-popup"]');
// Even if no popup (depends on implementation), no crash
expect(true).toBe(true);
});
});
describe('Calendar: Month Boundaries', () => {
afterEach(() => closeAll());
it('January prev goes to December of previous year', async () => {
click('#calendar-btn');
await sleep(300);
// Navigate to January
const title = $('#cal-title');
let safety = 15;
while (!title.textContent.includes('January') && safety-- > 0) {
click('#cal-prev');
await sleep(100);
}
if (!title.textContent.includes('January')) return;
const yearBefore = title.textContent.match(/\d{4}/)?.[0];
click('#cal-prev');
await sleep(200);
expect(title.textContent).toContain('December');
const yearAfter = title.textContent.match(/\d{4}/)?.[0];
expect(parseInt(yearAfter)).toBe(parseInt(yearBefore) - 1);
});
it('December next goes to January of next year', async () => {
click('#calendar-btn');
await sleep(300);
const title = $('#cal-title');
let safety = 15;
while (!title.textContent.includes('December') && safety-- > 0) {
click('#cal-next');
await sleep(100);
}
if (!title.textContent.includes('December')) return;
const yearBefore = title.textContent.match(/\d{4}/)?.[0];
click('#cal-next');
await sleep(200);
expect(title.textContent).toContain('January');
const yearAfter = title.textContent.match(/\d{4}/)?.[0];
expect(parseInt(yearAfter)).toBe(parseInt(yearBefore) + 1);
});
});