/** * E2E test: Settings export/import flow. * * Validates: * 1. Set batch_size to 10 and save * 2. Export settings (triggers download) * 3. Change batch_size to 15 and save * 4. Import the previously exported file * 5. Assert batch_size shows 10 again */ import { test, expect } from '@playwright/test'; import { loginAsUser } from '../helpers/auth'; import * as fs from 'node:fs'; import * as path from 'node:path'; test.describe('Settings export/import', () => { test('should export and re-import settings correctly', async ({ page }) => { // Step 1: Login as regular user via cookie injection await loginAsUser(page); // Step 2: Navigate to settings await page.goto('/settings', { waitUntil: 'domcontentloaded' }); // Wait for the settings page to load await expect( page.locator('h1', { hasText: 'Parametres de generation' }), ).toBeVisible({ timeout: 10_000 }); // Step 3: Set batch_size to 10 const batchSizeInput = page.locator('#batchSize'); await batchSizeInput.fill('10'); // Save await page .locator('button', { hasText: 'Enregistrer les parametres' }) .click(); // Wait for save confirmation await expect( page.getByText('Parametres enregistres avec succes'), ).toBeVisible({ timeout: 5_000 }); // Step 4: Open the Import/Export section (it's inside a
element) await page.locator('summary', { hasText: /import/i }).click(); // Click the export button and capture the download const downloadPromise = page.waitForEvent('download'); await page.locator('button', { hasText: 'Exporter' }).first().click(); const download = await downloadPromise; // Save the downloaded file to a temp location const downloadPath = path.join( '/tmp', `e2e-settings-export-${Date.now()}.json`, ); await download.saveAs(downloadPath); // Verify the downloaded file contains our batch_size const fileContent = fs.readFileSync(downloadPath, 'utf-8'); const parsed = JSON.parse(fileContent); expect(parsed.batch_size).toBe(10); // Step 5: Change batch_size to 15 and save await batchSizeInput.fill('15'); await page .locator('button', { hasText: 'Enregistrer les parametres' }) .click(); await expect( page.getByText('Parametres enregistres avec succes'), ).toBeVisible({ timeout: 5_000 }); // Verify it changed await expect(batchSizeInput).toHaveValue('15'); // Step 6: Import the previously downloaded file // The import button triggers a hidden file input. We need to set the file // on the hidden input element directly. const fileInput = page.locator('input[type="file"][accept=".json"]'); await fileInput.setInputFiles(downloadPath); // Wait for import success message await expect( page.getByText("Configuration importee avec succes"), ).toBeVisible({ timeout: 5_000 }); // Step 7: Assert the batch_size input shows 10 again await expect(batchSizeInput).toHaveValue('10'); // Clean up temp file try { fs.unlinkSync(downloadPath); } catch { // Ignore cleanup errors } }); });