|
| 1 | +import { test, expect, type Page } from '@playwright/test' |
| 2 | +import { |
| 3 | + authStatePath, |
| 4 | + navigateTo, |
| 5 | + expandAccordion, |
| 6 | + hideWebpackOverlay, |
| 7 | + createAbstractTestPdfBuffer, |
| 8 | +} from '../helpers' |
| 9 | + |
| 10 | +// Seeded thesis in WRITING state owned by the "student" user (same thesis the |
| 11 | +// thesis file upload test uses). Uploading a thesis document triggers the |
| 12 | +// server-side abstract extraction. |
| 13 | +const THESIS_1_ID = '00000000-0000-4000-d000-000000000001' |
| 14 | +const THESIS_1_URL = `/theses/${THESIS_1_ID}` |
| 15 | + |
| 16 | +const EXTRACTED = /comprehensive evaluation of automated review systems/i |
| 17 | + |
| 18 | +async function uploadThesisPdf(page: Page) { |
| 19 | + await expandAccordion(page, 'Thesis', page.getByText('Files').first()) |
| 20 | + await expandAccordion(page, 'Files', page.getByRole('button', { name: 'Upload Thesis' })) |
| 21 | + |
| 22 | + const uploadThesisButton = page.getByRole('button', { name: 'Upload Thesis' }) |
| 23 | + await uploadThesisButton.scrollIntoViewIfNeeded() |
| 24 | + await uploadThesisButton.click() |
| 25 | + |
| 26 | + // Scope to the upload dialog by name: after upload the confirmation modal opens, so a bare |
| 27 | + // getByRole('dialog') would match two dialogs. |
| 28 | + const dialog = page.getByRole('dialog', { name: 'File Upload' }) |
| 29 | + await expect(dialog).toBeVisible({ timeout: 10_000 }) |
| 30 | + await dialog.locator('input[type="file"]').setInputFiles({ |
| 31 | + name: 'thesis-with-abstract.pdf', |
| 32 | + mimeType: 'application/pdf', |
| 33 | + buffer: createAbstractTestPdfBuffer(), |
| 34 | + }) |
| 35 | + |
| 36 | + const uploadFileButton = dialog.getByRole('button', { name: 'Upload File' }) |
| 37 | + await expect(uploadFileButton).toBeEnabled({ timeout: 10_000 }) |
| 38 | + await uploadFileButton.click() |
| 39 | + await expect(dialog).toBeHidden({ timeout: 10_000 }) |
| 40 | +} |
| 41 | + |
| 42 | +test.describe('Abstract auto-extraction - Student', () => { |
| 43 | + test.use({ storageState: authStatePath('student') }) |
| 44 | + |
| 45 | + test('auto-fills a blank abstract, then asks via a modal before replacing an existing one', async ({ |
| 46 | + page, |
| 47 | + }) => { |
| 48 | + test.setTimeout(120_000) |
| 49 | + |
| 50 | + await navigateTo(page, THESIS_1_URL) |
| 51 | + await hideWebpackOverlay(page) |
| 52 | + await expect(page.getByRole('heading', { name: /automated code review/i })).toBeVisible({ |
| 53 | + timeout: 30_000, |
| 54 | + }) |
| 55 | + |
| 56 | + // 1) The seeded abstract is blank, so a confident extraction fills it silently — no modal. |
| 57 | + // The line-end hyphenation is rejoined ("com-" + "prehensive" => "comprehensive"). |
| 58 | + await uploadThesisPdf(page) |
| 59 | + await expect(page.getByText(EXTRACTED)).toBeVisible({ timeout: 15_000 }) |
| 60 | + |
| 61 | + // 2) Replace the abstract with a manual edit; a later upload must NOT overwrite it silently. |
| 62 | + await page.getByRole('button', { name: 'Edit' }).first().click() |
| 63 | + const abstractEditor = page |
| 64 | + .locator('.mantine-InputWrapper-root', { hasText: 'Abstract' }) |
| 65 | + .locator('.ProseMirror') |
| 66 | + .first() |
| 67 | + await abstractEditor.click() |
| 68 | + await page.keyboard.press('ControlOrMeta+A') |
| 69 | + await page.keyboard.press('Backspace') |
| 70 | + await abstractEditor.pressSequentially('A manually written abstract that must not be overwritten.') |
| 71 | + await page.getByRole('button', { name: 'Save' }).click() |
| 72 | + await expect(page.getByText(/manually written abstract that must not be overwritten/i)).toBeVisible({ |
| 73 | + timeout: 10_000, |
| 74 | + }) |
| 75 | + |
| 76 | + // 3) Uploading again surfaces a confirmation modal instead of overwriting the manual abstract. |
| 77 | + await uploadThesisPdf(page) |
| 78 | + const modal = page.getByRole('dialog', { name: /use the abstract extracted/i }) |
| 79 | + await expect(modal).toBeVisible({ timeout: 15_000 }) |
| 80 | + |
| 81 | + // 4) Confirming replaces the abstract with the extracted text. |
| 82 | + await modal.getByRole('button', { name: 'Use extracted abstract' }).click() |
| 83 | + await expect(page.getByText(EXTRACTED)).toBeVisible({ timeout: 10_000 }) |
| 84 | + }) |
| 85 | +}) |
0 commit comments