|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { setLocale, stubSupabaseSession } from './helpers/auth'; |
| 3 | + |
| 4 | +const locales = ['en', 'es', 'hu'] as const; |
| 5 | +const titledRoutes = ['generate', 'attack', 'brainstorm', 'factoids', 'ask'] as const; |
| 6 | + |
| 7 | +test('Sources does not show the stale consultation date', async ({ page }) => { |
| 8 | + await page.goto('/expocit/sources'); |
| 9 | + |
| 10 | + await expect(page.getByRole('heading', { name: 'Sources' })).toBeVisible(); |
| 11 | + await expect(page.getByText(/Consulta: 8 de marzo de 2026/i)).toHaveCount(0); |
| 12 | +}); |
| 13 | + |
| 14 | +for (const locale of locales) { |
| 15 | + test(`navigation and page titles agree in ${locale}`, async ({ page }, testInfo) => { |
| 16 | + await setLocale(page, locale); |
| 17 | + await stubSupabaseSession(page); |
| 18 | + await page.addInitScript(() => { |
| 19 | + window.localStorage.setItem('debate-trainer-onboarding', JSON.stringify({ |
| 20 | + state: { hasCompletedOnboarding: true, isTourRunning: false }, |
| 21 | + version: 0, |
| 22 | + })); |
| 23 | + }); |
| 24 | + await page.goto('/app'); |
| 25 | + |
| 26 | + for (const route of titledRoutes) { |
| 27 | + const desktopLink = page.locator(`[data-tour="nav-${route}"]`).first(); |
| 28 | + const label = await desktopLink.getAttribute('aria-label'); |
| 29 | + expect(label).toBeTruthy(); |
| 30 | + if (testInfo.project.name === 'mobile-chromium') { |
| 31 | + await page.locator('header button.lg\\:hidden[aria-expanded]').click(); |
| 32 | + await page.getByRole('navigation', { name: 'Mobile navigation' }) |
| 33 | + .getByRole('link') |
| 34 | + .filter({ hasText: label! }) |
| 35 | + .first() |
| 36 | + .click(); |
| 37 | + } else { |
| 38 | + await desktopLink.click(); |
| 39 | + } |
| 40 | + await expect(page).toHaveURL(new RegExp(`/app/${route}$`)); |
| 41 | + await expect(page.getByRole('heading', { level: 1, name: label!, exact: true }).last()).toBeVisible(); |
| 42 | + } |
| 43 | + }); |
| 44 | +} |
| 45 | + |
| 46 | +test('Factoids names the save action with its claim', async ({ page }) => { |
| 47 | + await setLocale(page, 'en'); |
| 48 | + await stubSupabaseSession(page); |
| 49 | + await page.route('**/functions/v1/ai', async (route) => { |
| 50 | + await route.fulfill({ |
| 51 | + status: 200, |
| 52 | + contentType: 'application/json', |
| 53 | + body: JSON.stringify({ |
| 54 | + output: { |
| 55 | + factoids: [{ |
| 56 | + id: 'fact-1', |
| 57 | + shortClaim: 'Solar costs fell by 42 percent', |
| 58 | + keyFigure: '42%', |
| 59 | + context: 'The official report compares the relevant period.', |
| 60 | + limitations: 'The result depends on the measured market segment.', |
| 61 | + citation: { |
| 62 | + title: 'Official energy statistics', |
| 63 | + publisher: 'Department of Energy', |
| 64 | + date: '2024', |
| 65 | + url: 'https://energy.gov/reports/solar-costs-2024', |
| 66 | + verified: 'verified', |
| 67 | + }, |
| 68 | + howToUse: 'Use this as a bounded cost trend.', |
| 69 | + relevanceScore: 92, |
| 70 | + }], |
| 71 | + searchSuggestions: [], |
| 72 | + warnings: [], |
| 73 | + verificationStatus: 'complete', |
| 74 | + }, |
| 75 | + }), |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + await page.goto('/app/factoids'); |
| 80 | + await page.getByRole('textbox', { name: /statement/i }).fill('Solar energy costs are falling'); |
| 81 | + await page.getByRole('button', { name: /find factoids/i }).click(); |
| 82 | + |
| 83 | + await expect(page.getByRole('button', { |
| 84 | + name: 'Save Solar costs fell by 42 percent to library', |
| 85 | + })).toBeVisible(); |
| 86 | +}); |
| 87 | + |
| 88 | +test('Flowchart confirms selected-node deletion and reports success', async ({ page }, testInfo) => { |
| 89 | + await setLocale(page, 'en'); |
| 90 | + await stubSupabaseSession(page); |
| 91 | + await page.goto('/app/flowchart'); |
| 92 | + |
| 93 | + await page.getByText('Argument 1', { exact: true }).click(); |
| 94 | + await page.getByRole('button', { name: 'Delete' }).last().click(); |
| 95 | + await expect(page.getByRole('alertdialog', { name: 'Delete node?' })).toBeVisible(); |
| 96 | + const confirm = page.getByRole('button', { name: 'Delete node' }); |
| 97 | + if (testInfo.project.name === 'mobile-chromium') { |
| 98 | + const box = await confirm.boundingBox(); |
| 99 | + expect(box).not.toBeNull(); |
| 100 | + await page.touchscreen.tap(box!.x + box!.width / 2, box!.y + box!.height / 2); |
| 101 | + } else { |
| 102 | + await confirm.click(); |
| 103 | + } |
| 104 | + |
| 105 | + await expect(page.getByText('Node deleted', { exact: true })).toBeVisible(); |
| 106 | + await expect(page.getByText('Argument 1', { exact: true })).toHaveCount(0); |
| 107 | +}); |
0 commit comments