|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { seedEmail, cleanupPrefix, BUCKET } from "./helpers"; |
| 3 | + |
| 4 | +test.describe("Email", () => { |
| 5 | + test.beforeAll(async ({ request }) => { |
| 6 | + await seedEmail(request, "1000000000000-e2e-email-1", { |
| 7 | + subject: "Welcome to E2E Testing", |
| 8 | + fromName: "Alice Sender", |
| 9 | + fromAddress: "alice@example.com", |
| 10 | + body: "This is the first test email body.", |
| 11 | + read: false, |
| 12 | + hasAttachments: false, |
| 13 | + }); |
| 14 | + await seedEmail(request, "1000000000001-e2e-email-2", { |
| 15 | + subject: "Second Test Email", |
| 16 | + fromName: "Bob Tester", |
| 17 | + fromAddress: "bob@example.com", |
| 18 | + body: "This is the second test email.", |
| 19 | + read: true, |
| 20 | + hasAttachments: false, |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + test.afterAll(async ({ request }) => { |
| 25 | + await cleanupPrefix(request, ".r2-explorer/emails/"); |
| 26 | + }); |
| 27 | + |
| 28 | + test("shows email list with sender and subject", async ({ page }) => { |
| 29 | + await page.goto(`/${BUCKET}/email`); |
| 30 | + |
| 31 | + // Wait for emails to load — use td.email-subject (visible desktop cell) |
| 32 | + await expect( |
| 33 | + page.locator("td.email-subject", { hasText: "Welcome to E2E Testing" }), |
| 34 | + ).toBeVisible({ timeout: 15_000 }); |
| 35 | + |
| 36 | + await expect( |
| 37 | + page.locator("td.email-sender", { hasText: "Alice Sender" }), |
| 38 | + ).toBeVisible(); |
| 39 | + |
| 40 | + // Second email should also be visible |
| 41 | + await expect( |
| 42 | + page.locator("td.email-subject", { hasText: "Second Test Email" }), |
| 43 | + ).toBeVisible(); |
| 44 | + await expect( |
| 45 | + page.locator("td.email-sender", { hasText: "Bob Tester" }), |
| 46 | + ).toBeVisible(); |
| 47 | + }); |
| 48 | + |
| 49 | + test("opens email detail view when clicking an email", async ({ page }) => { |
| 50 | + await page.goto(`/${BUCKET}/email`); |
| 51 | + await expect( |
| 52 | + page.locator("td.email-subject", { hasText: "Welcome to E2E Testing" }), |
| 53 | + ).toBeVisible({ timeout: 15_000 }); |
| 54 | + |
| 55 | + await page |
| 56 | + .locator("td.email-subject", { hasText: "Welcome to E2E Testing" }) |
| 57 | + .click(); |
| 58 | + |
| 59 | + // Should navigate to email detail view showing sender info |
| 60 | + await expect(page.locator("text=alice@example.com")).toBeVisible({ |
| 61 | + timeout: 10_000, |
| 62 | + }); |
| 63 | + // Should show the subject |
| 64 | + await expect(page.locator("text=Welcome to E2E Testing")).toBeVisible(); |
| 65 | + // Should show the recipient |
| 66 | + await expect(page.locator("text=test@example.com")).toBeVisible(); |
| 67 | + }); |
| 68 | + |
| 69 | + test("shows email body content in detail view", async ({ page }) => { |
| 70 | + await page.goto(`/${BUCKET}/email`); |
| 71 | + await expect( |
| 72 | + page.locator("td.email-subject", { hasText: "Welcome to E2E Testing" }), |
| 73 | + ).toBeVisible({ timeout: 15_000 }); |
| 74 | + |
| 75 | + await page |
| 76 | + .locator("td.email-subject", { hasText: "Welcome to E2E Testing" }) |
| 77 | + .click(); |
| 78 | + |
| 79 | + // Wait for detail to load |
| 80 | + await expect(page.locator("text=alice@example.com")).toBeVisible({ |
| 81 | + timeout: 10_000, |
| 82 | + }); |
| 83 | + |
| 84 | + // Email body should be displayed (HTML renders in iframe, text as div) |
| 85 | + // Our seeded email has HTML: <p>This is the first test email body.</p> |
| 86 | + // Check the iframe or text fallback contains the body |
| 87 | + await expect(page.locator("iframe, div").first()).toBeVisible({ |
| 88 | + timeout: 10_000, |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + test("marks email as unread from detail view", async ({ page }) => { |
| 93 | + await page.goto(`/${BUCKET}/email`); |
| 94 | + await expect( |
| 95 | + page.locator("td.email-subject", { hasText: "Welcome to E2E Testing" }), |
| 96 | + ).toBeVisible({ timeout: 15_000 }); |
| 97 | + |
| 98 | + // Open the email (this auto-marks as read) |
| 99 | + await page |
| 100 | + .locator("td.email-subject", { hasText: "Welcome to E2E Testing" }) |
| 101 | + .click(); |
| 102 | + |
| 103 | + await expect(page.locator("text=alice@example.com")).toBeVisible({ |
| 104 | + timeout: 10_000, |
| 105 | + }); |
| 106 | + |
| 107 | + // After opening, the "mark as unread" button should appear |
| 108 | + // (because the email was auto-marked as read) |
| 109 | + const unreadBtn = page.locator( |
| 110 | + 'button:has(.q-icon:text-is("mark_email_unread"))', |
| 111 | + ); |
| 112 | + await expect(unreadBtn).toBeVisible({ timeout: 10_000 }); |
| 113 | + |
| 114 | + // Click "mark as unread" |
| 115 | + await unreadBtn.click(); |
| 116 | + |
| 117 | + // After marking as unread, the "mark as read" button should appear |
| 118 | + await expect( |
| 119 | + page.locator('button:has(.q-icon:text-is("mark_email_read"))'), |
| 120 | + ).toBeVisible({ timeout: 5_000 }); |
| 121 | + }); |
| 122 | + |
| 123 | + test("navigates between email list and Files", async ({ page }) => { |
| 124 | + await page.goto(`/${BUCKET}/email`); |
| 125 | + await expect( |
| 126 | + page.locator("td.email-subject", { hasText: "Welcome to E2E Testing" }), |
| 127 | + ).toBeVisible({ timeout: 15_000 }); |
| 128 | + |
| 129 | + // Click Files button in sidebar |
| 130 | + await page.getByRole("button", { name: "Files" }).click(); |
| 131 | + |
| 132 | + // Should be on the files page |
| 133 | + await expect(page.locator(".q-table")).toBeVisible({ timeout: 10_000 }); |
| 134 | + |
| 135 | + // Click Email button to go back |
| 136 | + await page.getByRole("button", { name: "Email" }).click(); |
| 137 | + |
| 138 | + // Should be back on email page |
| 139 | + await expect( |
| 140 | + page.locator("td.email-subject", { hasText: "Welcome to E2E Testing" }), |
| 141 | + ).toBeVisible({ timeout: 15_000 }); |
| 142 | + }); |
| 143 | +}); |
0 commit comments