Skip to content

Commit 68a1714

Browse files
authored
feat: add tests for optimistic actions (#1922)
added playwright tests for marking an email as read, unread and starring it upon right clicking <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added Playwright tests to cover marking an email as read, unread, and favoriting it using right-click actions in the inbox. <!-- End of auto-generated description by cubic. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added a new end-to-end test verifying that users can mark emails as favorite, read, and unread in the inbox. The test ensures proper UI interactions and state changes for these mail actions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 17bdc34 commit 68a1714

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)