Files
zibo-dashboard/tests/e2e/forms.spec.js
T
RMubarakzyanov e13e0c9b2a Translate the Playwright e2e suite to English
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>
2026-08-10 21:11:59 +03:00

134 lines
6.3 KiB
JavaScript

const { test, expect } = require('@playwright/test')
const {
createEquipment, createMaintenance, submitAndReload, waitForModal, name, listItem
} = require('./helpers/fixtures')
const { scalar } = require('./helpers/env')
/**
* Modal validation and reload of the values: the fields must come back exactly
* as they were saved, and incomplete data must not get through.
*/
test.describe('Modals: validation and reload of the values', () => {
let equipmentId
test.beforeAll(async ({ browser }) => {
const page = await browser.newPage()
equipmentId = await createEquipment(page, name('Macchina moduli'))
await page.close()
})
test.beforeEach(async ({ page }) => {
await page.goto(`userarea/manutenzioni/equipment.php?id=${equipmentId}`)
})
// Title and date carry the required attribute: the browser validation stops
// the submit, so the modal stays open and no request is fired.
test('maintenance without a title: the form blocks and nothing is saved', async ({ page }) => {
const before = scalar(`SELECT COUNT(*) FROM maint_maintenances WHERE equipment_id = ${equipmentId}`)
await page.click('#btnAddMaintenance')
await waitForModal(page, '#maintenanceModal')
await page.click('#maintenanceForm button[type="submit"]')
await expect(page.locator('#maintenanceModal')).toBeVisible()
expect(await page.locator('#mtTitle').evaluate((el) => el.checkValidity())).toBe(false)
expect(scalar(`SELECT COUNT(*) FROM maint_maintenances WHERE equipment_id = ${equipmentId}`)).toBe(before)
})
test('intervention without a date: the form blocks and nothing is saved', async ({ page }) => {
const title = name('Lavoro per validazione')
await createMaintenance(page, equipmentId, { code: 'V', title })
await page.locator(`.mnt-item-card:has-text("${title}") .btn-register`).first().click()
await waitForModal(page, '#interventionModal')
await page.fill('#ivDate', '')
await page.click('#interventionForm button[type="submit"]')
await expect(page.locator('#interventionModal')).toBeVisible()
expect(await page.locator('#ivDate').evaluate((el) => el.checkValidity())).toBe(false)
expect(scalar(`SELECT COUNT(*) FROM maint_interventions
WHERE maintenance_id = (SELECT id FROM maint_maintenances
WHERE equipment_id = ${equipmentId} AND title = '${title}')`)).toBe('0')
})
test('reopening a maintenance task shows the saved values', async ({ page }) => {
const title = name('Manutenzione completa')
await page.click('#btnAddMaintenance')
await waitForModal(page, '#maintenanceModal')
await page.fill('#mtCode', 'Q')
await page.fill('#mtTitle', title)
await page.fill('#mtDescription', 'Descrizione dettagliata del controllo.')
await page.selectOption('#mtType', 'extraordinary')
await page.selectOption('#mtFrequencyUnit', 'week')
await page.fill('#mtFrequencyValue', '6')
await page.fill('#mtFrequencyNote', 'solo durante il periodo estivo')
await page.fill('#mtAlertDays', '21')
await page.check('#mtCritical')
await submitAndReload(page, '#maintenanceForm button[type="submit"]')
await page.locator(`.mnt-item-card:has-text("${title}") .btn-edit-maintenance`).first().click()
await waitForModal(page, '#maintenanceModal')
await expect(page.locator('#mtCode')).toHaveValue('Q')
await expect(page.locator('#mtTitle')).toHaveValue(title)
await expect(page.locator('#mtDescription')).toHaveValue('Descrizione dettagliata del controllo.')
await expect(page.locator('#mtType')).toHaveValue('extraordinary')
await expect(page.locator('#mtFrequencyUnit')).toHaveValue('week')
await expect(page.locator('#mtFrequencyValue')).toHaveValue('6')
await expect(page.locator('#mtFrequencyNote')).toHaveValue('solo durante il periodo estivo')
await expect(page.locator('#mtAlertDays')).toHaveValue('21')
await expect(page.locator('#mtCritical')).toBeChecked()
await expect(page.locator('#mtActive')).toBeChecked()
})
test('reopening an intervention shows the saved values', async ({ page }) => {
const title = name('Lavoro con storico')
await createMaintenance(page, equipmentId, { code: 'W', title })
await page.locator(`.mnt-item-card:has-text("${title}") .btn-register`).first().click()
await waitForModal(page, '#interventionModal')
await page.fill('#ivDate', '2026-03-12')
await page.selectOption('#ivResult', 'compliant')
await page.fill('#ivNotes', 'Sostituita guarnizione')
await page.fill('#ivMaterials', 'Guarnizione 40x60')
await page.fill('#ivOperatorName', 'Tecnico esterno Rossi')
await submitAndReload(page, '#interventionForm button[type="submit"]')
const card = page.locator(`.mnt-item-card:has-text("${title}")`).first()
await card.locator('.btn-toggle-history').click()
await card.locator('.mnt-timeline-item').first().locator('.btn-edit-intervention').click()
await waitForModal(page, '#interventionModal')
await expect(page.locator('#ivDate')).toHaveValue('2026-03-12')
await expect(page.locator('#ivResult')).toHaveValue('compliant')
await expect(page.locator('#ivNotes')).toHaveValue('Sostituita guarnizione')
await expect(page.locator('#ivMaterials')).toHaveValue('Guarnizione 40x60')
await expect(page.locator('#ivOperatorName')).toHaveValue('Tecnico esterno Rossi')
await expect(page.locator('#interventionModalTitle')).toHaveText('Modifica intervento')
})
test('equipment used in production cannot be deleted', async ({ page }) => {
// the imported Taglierina is linked to real production records
const usedId = scalar('SELECT tool_id FROM productiondata_tools LIMIT 1')
test.skip(!usedId, 'no equipment linked to production in this database')
const usedName = scalar(`SELECT name FROM inv_equipment WHERE id = ${usedId}`)
await page.goto(`userarea/manutenzioni/index.php?q=${encodeURIComponent(usedName)}&status=all`)
await listItem(page, `${usedName}`).locator('.btn-delete').first().click()
await expect(page.locator('.swal2-popup')).toBeVisible()
await page.click('.swal2-confirm')
await expect(page.locator('.swal2-title')).toContainText('Errore')
await expect(page.locator('.swal2-html-container')).toContainText('registrazioni di produzione')
expect(scalar(`SELECT COUNT(*) FROM inv_equipment WHERE id = ${usedId}`)).toBe('1')
})
})