e13e0c9b2a
Test titles, describe blocks, comments and assertion messages are now in English, so the runner output and the code are readable without Italian. Deliberately left in Italian, because they are matched against the app or typed into it: - UI text used in locators (page headings, badges, empty states, SweetAlert messages, sidebar entries, category names) - form values filled in by the tests, so screenshots and demo videos keep showing an Italian UI with Italian data - fixture labels passed to name(), for the same reason Screenshot files are renamed to the English labels the suite now writes (desktop-registro.png -> desktop-registry.png and so on); the docs that quote test titles or screenshot names are updated to match. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
98 lines
3.8 KiB
JavaScript
98 lines
3.8 KiB
JavaScript
const { test, expect } = require('@playwright/test')
|
|
const { CALENDAR, GLOBAL_CALENDAR, createEquipment, createMaintenance, name } = require('./helpers/fixtures')
|
|
const { sql } = require('./helpers/env')
|
|
|
|
test.describe('Calendars', () => {
|
|
let equipmentId
|
|
const title = name('Manutenzione a calendario')
|
|
|
|
test.beforeAll(async ({ browser }) => {
|
|
const page = await browser.newPage()
|
|
equipmentId = await createEquipment(page, name('Macchina calendario'))
|
|
await createMaintenance(page, equipmentId, { code: 'K', title, months: 6 })
|
|
await page.close()
|
|
|
|
// a fixed due date in the future, so the event lands in a known month
|
|
sql(`UPDATE maint_maintenances SET last_done_date = '2026-09-15', next_due_date = '2026-09-15'
|
|
WHERE equipment_id = ${equipmentId}`)
|
|
})
|
|
|
|
test('the calendar draws the events and clicking one opens the equipment page', async ({ page }) => {
|
|
await page.goto(`${CALENDAR}?_=1`)
|
|
await page.locator('.fc-view-harness').waitFor()
|
|
|
|
// page through to September 2026 (the toolbar title is localised in Italian)
|
|
await page.locator('.fc-toolbar-title').waitFor()
|
|
for (let i = 0; i < 24; i++) {
|
|
const title = await page.locator('.fc-toolbar-title').textContent()
|
|
if (/settembre 2026/i.test(title)) break
|
|
await page.locator('.fc-next-button').click()
|
|
await page.waitForTimeout(120)
|
|
}
|
|
|
|
const event = page.locator('.fc-event', { hasText: name('Macchina calendario') }).first()
|
|
await expect(event).toBeVisible()
|
|
|
|
await event.click()
|
|
await page.waitForURL(/equipment\.php\?id=\d+/)
|
|
await expect(page.getByRole('heading', { name: new RegExp(name('Macchina calendario')) })).toBeVisible()
|
|
})
|
|
|
|
test('the calendar filters re-issue the request', async ({ page }) => {
|
|
await page.goto(CALENDAR)
|
|
await page.locator('.fc-view-harness').waitFor()
|
|
|
|
const [request] = await Promise.all([
|
|
page.waitForRequest((r) => r.url().includes('get_calendar_events.php') && r.url().includes('type=extraordinary')),
|
|
page.selectOption('#filterType', 'extraordinary'),
|
|
])
|
|
|
|
expect(request.url()).toContain('type=extraordinary')
|
|
})
|
|
|
|
test('the combined calendar switches layers on and off', async ({ page }) => {
|
|
const errors = []
|
|
page.on('pageerror', (e) => errors.push(e.message))
|
|
|
|
await page.goto(GLOBAL_CALENDAR)
|
|
await page.locator('.fc-view-harness').waitFor()
|
|
|
|
const toggles = page.locator('.mnt-layer-toggle')
|
|
await expect(toggles).toHaveCount(3)
|
|
await expect(page.locator('.mnt-layer-toggle.is-on')).toHaveCount(3)
|
|
|
|
// the checkbox is hidden inside the label: click the label
|
|
const maintenanceToggle = page.locator('.mnt-layer-toggle', { hasText: 'Manutenzioni' })
|
|
await maintenanceToggle.click()
|
|
await expect(maintenanceToggle).not.toHaveClass(/is-on/)
|
|
|
|
// with every layer off the calendar stays empty, and no JS error is raised
|
|
for (const layer of ['Scadenze', 'Formazione']) {
|
|
await page.locator('.mnt-layer-toggle', { hasText: layer }).click()
|
|
}
|
|
|
|
await expect(page.locator('.fc-event')).toHaveCount(0)
|
|
expect(errors).toEqual([])
|
|
})
|
|
|
|
test('every layer brings its own events', async ({ page }) => {
|
|
const countEvents = async (layers) => {
|
|
const response = await page.request.get(
|
|
`userarea/manutenzioni/ajax/get_global_calendar_events.php?start=2026-01-01&end=2027-12-31&layers=${layers}`
|
|
)
|
|
return (await response.json()).length
|
|
}
|
|
|
|
await page.goto(GLOBAL_CALENDAR)
|
|
|
|
const all = await countEvents('deadlines,trainings,maintenances')
|
|
const onlyMaintenances = await countEvents('maintenances')
|
|
const onlyDeadlines = await countEvents('deadlines')
|
|
|
|
expect(onlyMaintenances).toBeGreaterThan(0)
|
|
expect(onlyDeadlines).toBeGreaterThan(0)
|
|
expect(all).toBeGreaterThan(onlyMaintenances)
|
|
expect(all).toBeGreaterThan(onlyDeadlines)
|
|
})
|
|
})
|