caterium-app/tests/calendar-print.spec.mjs
2026-09-18 20:43:09 +03:00

66 lines
4.1 KiB
JavaScript

import {test,expect} from '@playwright/test';
import {bootCalendar,printCalendar} from './calendar-fixture.mjs';
test('phone and tablet calendar modes fit without sideways scrolling and still open orders',async({page,context})=>{
await bootCalendar(page,context,[9]);
await page.evaluate(()=>{
const now=new Date(),today=`${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,'0')}-${String(now.getDate()).padStart(2,'0')}`;
orders.forEach(o=>{o.date=today;o.event='Оченьдлинноеназваниемероприятиябезпробелов'.repeat(3);o.address='Длинныйадресдоставки'.repeat(5);o.total=123456789});
});
for(const width of [320,390,768]){
await page.setViewportSize({width,height:844});
for(const mode of ['month','week','day']){
await page.locator(`[data-cal-mode="${mode}"]`).click();
const fit=await page.locator('#calendar').evaluate(el=>{
const viewport=document.documentElement.clientWidth;
const panels=[el,...el.querySelectorAll('.cal-scroll,.cal-month,.cal-controls,.cal-metrics,.cal-agenda')];
return panels.every(p=>p.getBoundingClientRect().left>=-1&&p.getBoundingClientRect().right<=viewport+1&&p.scrollWidth<=p.clientWidth+1);
});
expect(fit,`${width}px ${mode}`).toBe(true);
if(mode==='month'){
await expect(page.locator('#calendar .cal-event:visible')).toHaveCount(9);
const timeFits=await page.locator('.cal-event-time').evaluateAll(nodes=>nodes.every(n=>n.getBoundingClientRect().right<=n.closest('button').getBoundingClientRect().right));
expect(timeFits,`${width}px times`).toBe(true);
}
}
}
await page.setViewportSize({width:390,height:844});
await page.locator('.cal-agenda-order').first().getByRole('button',{name:'Открыть'}).click();
expect(await page.evaluate(()=>draft.id)).toBe(1000);
});
test('busy calendar days show nine single-line orders and retain access to the rest',async({page,context})=>{
const dates=await bootCalendar(page,context);
const day=i=>page.locator(`.cal-day[data-date="${dates[i]}"]`);
await expect(day(0)).not.toHaveClass(/cal-day--compact/);
await expect(day(0).locator('.cal-event:visible')).toHaveCount(3);
await expect(day(1)).toHaveClass(/cal-day--compact/);
await expect(day(1).locator('.cal-event:visible')).toHaveCount(4);
await expect(day(2).locator('.cal-event:visible')).toHaveCount(9);
await expect(day(2).locator('.cal-more')).toHaveCount(0);
expect(await day(2).locator('.cal-event').evaluateAll(rows=>rows.every(row=>row.getBoundingClientRect().height<26))).toBe(true);
await expect(day(3).locator('.cal-event:visible')).toHaveCount(9);
await expect(day(3).locator('.cal-more')).toHaveText('+ ещё 2');
await day(3).locator('.cal-more').click();
await expect(page.locator('[data-cal-open-v1762]')).toHaveCount(11);
await page.locator('[data-cal-open-v1762="1310"]').click();
expect(await page.evaluate(()=>draft.id)).toBe(1310);
});
test('calendar print fits nine orders inside the day and includes overflow on a continuation sheet',async({page,context})=>{
const dates=await bootCalendar(page,context),popup=await printCalendar(page,context);
await popup.emulateMedia({media:'print'});
await expect(popup.locator(`.cal-day[data-date="${dates[2]}"] .cal-event`)).toHaveCount(9);
const fit=await popup.locator('.cal-day').evaluateAll(days=>{
return days.every(day=>{const cell=day.getBoundingClientRect();return [...day.querySelectorAll('.cal-event')].every(row=>{const box=row.getBoundingClientRect();return box.top>=cell.top&&box.bottom<=cell.bottom-1})});
});
expect(fit).toBe(true);
await expect(popup.locator('.cal-print-overflow .cal-event')).toHaveCount(2);
await expect(popup.locator('.cal-print-overflow [data-order-id="1310"]')).toBeVisible();
const ids=await popup.locator('.cal-event').evaluateAll(rows=>rows.map(r=>r.dataset.orderId));
expect(ids).toHaveLength(27);expect(new Set(ids).size).toBe(27);
expect(await popup.locator('.cal-print-overflow').evaluate(el=>getComputedStyle(el).breakBefore)).toBe('page');
expect(await popup.locator('body').innerText()).not.toContain('₽');
await popup.close();
});