import { expect, test } from "@playwright/test" import { ApiClient } from "../api-client" import { SEED } from "../seed-constants" import { SEL } from "../selectors" const apiClient = new ApiClient() test.describe("Documents Page @smoke", () => { test.beforeEach(async () => { await apiClient.login(SEED.admin.email, SEED.admin.password) await apiClient.resetDb() }) test("displays seed documents", async ({ page }) => { await page.goto("/documents") await expect(page.getByText(SEED.documents.satzung.title)).toBeVisible() await expect(page.getByText(SEED.documents.protokoll.title)).toBeVisible() await expect( page.getByText(SEED.documents.genehmigung.title) ).toBeVisible() await expect( page.getByText(SEED.documents.mietvertrag.title) ).toBeVisible() }) test("upload button opens dialog", async ({ page }) => { await page.goto("/documents") const uploadBtn = page.locator(SEL.documents.uploadButton) await expect(uploadBtn).toBeVisible() await uploadBtn.click() await expect(page.locator(SEL.documents.uploadDialog)).toBeVisible() await expect(page.locator(SEL.documents.titleInput)).toBeVisible() await expect(page.locator(SEL.documents.categorySelect)).toBeVisible() await expect(page.locator(SEL.documents.fileInput)).toBeVisible() }) test("upload form submits successfully", async ({ page }) => { // Requires backend await page.goto("/documents") await page.locator(SEL.documents.uploadButton).click() await expect(page.locator(SEL.documents.uploadDialog)).toBeVisible() await page.locator(SEL.documents.titleInput).fill("Testdokument Upload") await page.locator(SEL.documents.categorySelect).click() await page.getByRole("option", { name: /satzung/i }).click() // Upload a test file const fileInput = page.locator(SEL.documents.fileInput) await fileInput.setInputFiles({ name: "test.pdf", mimeType: "application/pdf", buffer: Buffer.from("fake pdf content"), }) const submitBtn = page.locator(SEL.documents.submitUpload) await submitBtn.click() // Verify success toast await expect(page.getByText(/erfolgreich|hochgeladen/i)).toBeVisible() }) test("download button triggers download", async ({ page }) => { await page.goto("/documents") const downloadBtn = page.locator( SEL.documents.downloadButton(SEED.documents.satzung.id) ) await expect(downloadBtn).toBeVisible() // Verify clicking download doesn't throw an error const downloadPromise = page.waitForEvent("download") await downloadBtn.click() const download = await downloadPromise expect(download.suggestedFilename()).toBeTruthy() }) test("delete button shows confirmation and removes document", async ({ page, }) => { // Requires backend await page.goto("/documents") const deleteBtn = page.locator( SEL.documents.deleteButton(SEED.documents.mietvertrag.id) ) await expect(deleteBtn).toBeVisible() await deleteBtn.click() // Confirmation dialog appears await expect(page.locator(SEL.documents.deleteConfirm)).toBeVisible() await page.locator(SEL.documents.deleteConfirm).click() // Document removed from list await expect( page.getByText(SEED.documents.mietvertrag.title) ).not.toBeVisible() }) test("category badges display correctly", async ({ page }) => { await page.goto("/documents") await expect( page.locator( SEL.documents.categoryBadge(SEED.documents.satzung.category) ) ).toBeVisible() await expect( page.locator( SEL.documents.categoryBadge(SEED.documents.protokoll.category) ) ).toBeVisible() await expect( page.locator( SEL.documents.categoryBadge(SEED.documents.genehmigung.category) ) ).toBeVisible() await expect( page.locator( SEL.documents.categoryBadge(SEED.documents.mietvertrag.category) ) ).toBeVisible() }) })