/** * E2E test: Admin providers management. * * Validates that an admin user can: * 1. Navigate to /admin/providers * 2. See the Gemini provider card * 3. Toggle enable if needed * 4. Save changes * 5. Verify the provider appears in the settings dropdown */ import { test, expect } from '@playwright/test'; import { loginAsAdmin } from '../helpers/auth'; test.describe('Admin providers', () => { test('should see Gemini provider and verify it appears in settings', async ({ page, }) => { // Step 1: Login as admin via cookie injection await loginAsAdmin(page); // Step 2: Navigate to admin providers page await page.goto('/admin/providers', { waitUntil: 'domcontentloaded' }); // Step 3: Wait for the page to load and verify the Gemini provider card is visible await expect( page.locator('h2', { hasText: 'Google Gemini' }), ).toBeVisible({ timeout: 10_000 }); // Step 4: Find the Gemini card. Check if the enable toggle shows "Active" const geminiCard = page .locator('.bg-white.shadow-sm.border') .filter({ hasText: 'Google Gemini' }); await expect(geminiCard).toBeVisible(); // Check the toggle state. If it shows "Desactive", click it to enable. const statusText = geminiCard.locator('span', { hasText: /Active|Desactive/ }); const currentStatus = await statusText.textContent(); if (currentStatus?.trim() === 'Desactive') { // Click the toggle switch (role="switch") within the Gemini card await geminiCard.locator('button[role="switch"]').click(); // Verify it now shows "Active" await expect( geminiCard.locator('span', { hasText: 'Active' }), ).toBeVisible(); } // Step 5: Click save on the Gemini card const saveButton = geminiCard.locator('button', { hasText: 'Enregistrer', }); await saveButton.click(); // Wait for save confirmation (toast or page update) // The save triggers a toast; just wait briefly for the API call await page.waitForTimeout(1000); // Step 6: Navigate to settings to verify the provider appears in dropdown await page.goto('/settings', { waitUntil: 'domcontentloaded' }); // Wait for settings page to load await expect( page.locator('h1', { hasText: 'Parametres de generation' }), ).toBeVisible({ timeout: 10_000 }); // When multiple providers are enabled the provider dropdown is visible. // Select Google Gemini, then verify the model dropdown populates. const providerDropdown = page.locator('#aiProvider'); const modelDropdown = page.locator('#aiModel'); // If only one provider is enabled, the provider dropdown is hidden and // the model dropdown is pre-populated. Handle both cases. const hasProviderDropdown = await providerDropdown.isVisible().catch(() => false); if (hasProviderDropdown) { await providerDropdown.selectOption('gemini'); // Wait for the model dropdown to update after provider selection await expect(modelDropdown).toBeEnabled({ timeout: 5_000 }); } await expect(modelDropdown).toBeVisible({ timeout: 5_000 }); // Verify Gemini models are available in the dropdown const options = modelDropdown.locator('option'); const optionCount = await options.count(); expect(optionCount).toBeGreaterThan(0); // Check that at least one option mentions a Gemini model const allText = await modelDropdown.textContent(); expect(allText).toContain('Gemini'); }); });