|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('Mail actions: favorite, read, unread', () => { |
| 4 | + test('should allow marking an email as favorite, read, and unread', async ({ page }) => { |
| 5 | + await page.goto('/mail/inbox'); |
| 6 | + await page.waitForLoadState('domcontentloaded'); |
| 7 | + console.log('Successfully accessed mail inbox'); |
| 8 | + |
| 9 | + await page.waitForTimeout(2000); |
| 10 | + try { |
| 11 | + const welcomeModal = page.getByText('Welcome to Zero Email!'); |
| 12 | + if (await welcomeModal.isVisible({ timeout: 2000 })) { |
| 13 | + console.log('Onboarding modal detected, clicking outside to dismiss...'); |
| 14 | + await page.locator('body').click({ position: { x: 100, y: 100 } }); |
| 15 | + await page.waitForTimeout(1500); |
| 16 | + console.log('Modal successfully dismissed'); |
| 17 | + } |
| 18 | + } catch { |
| 19 | + console.log('No onboarding modal found, proceeding...'); |
| 20 | + } |
| 21 | + |
| 22 | + await expect(page.getByText('Inbox')).toBeVisible(); |
| 23 | + console.log('Mail inbox is now visible'); |
| 24 | + |
| 25 | + const firstEmail = page.locator('[data-thread-id]').first(); |
| 26 | + await expect(firstEmail).toBeVisible(); |
| 27 | + console.log('Found first email'); |
| 28 | + |
| 29 | + await firstEmail.click({ button: 'right' }); |
| 30 | + await page.waitForTimeout(500); |
| 31 | + |
| 32 | + const markAsReadButton = page.getByText('Mark as read'); |
| 33 | + const isInitiallyUnread = await markAsReadButton.isVisible(); |
| 34 | + |
| 35 | + if (isInitiallyUnread) { |
| 36 | + console.log('Email is unread. Marking as read...'); |
| 37 | + await markAsReadButton.click(); |
| 38 | + console.log('Marked email as read.'); |
| 39 | + } else { |
| 40 | + console.log('Email is read. Marking as unread...'); |
| 41 | + const markAsUnreadButton = page.getByText('Mark as unread'); |
| 42 | + await expect(markAsUnreadButton).toBeVisible(); |
| 43 | + await markAsUnreadButton.click(); |
| 44 | + console.log('Marked email as unread.'); |
| 45 | + } |
| 46 | + await page.waitForTimeout(1000); |
| 47 | + |
| 48 | + console.log('Right-clicking on email to favorite...'); |
| 49 | + await firstEmail.click({ button: 'right' }); |
| 50 | + await page.waitForTimeout(500); |
| 51 | + await page.getByText('Favorite').click(); |
| 52 | + console.log('Clicked "Favorite"'); |
| 53 | + await page.waitForTimeout(1000); |
| 54 | + |
| 55 | + console.log('Right-clicking on email to toggle read state again...'); |
| 56 | + await firstEmail.click({ button: 'right' }); |
| 57 | + await page.waitForTimeout(500); |
| 58 | + |
| 59 | + if (isInitiallyUnread) { |
| 60 | + const markAsUnreadButton = page.getByText('Mark as unread'); |
| 61 | + await expect(markAsUnreadButton).toBeVisible(); |
| 62 | + await markAsUnreadButton.click(); |
| 63 | + console.log('Marked email as unread.'); |
| 64 | + } else { |
| 65 | + const markAsReadButtonAgain = page.getByText('Mark as read'); |
| 66 | + await expect(markAsReadButtonAgain).toBeVisible(); |
| 67 | + await markAsReadButtonAgain.click(); |
| 68 | + console.log('Marked email as read.'); |
| 69 | + } |
| 70 | + |
| 71 | + await page.waitForTimeout(1000); |
| 72 | + |
| 73 | + console.log('Entire email actions flow completed successfully!'); |
| 74 | + }); |
| 75 | +}); |
0 commit comments