From 066edbc77b5f4e3b70489f3eea5d41b65abb554b Mon Sep 17 00:00:00 2001 From: amrit Date: Thu, 7 Aug 2025 09:32:07 +0530 Subject: [PATCH] feat: add playwright tests to check for zero summary of past emails in sidebar (#1920) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # READ CAREFULLY THEN REMOVE Remove bullet points that are not relevant. PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI. - Pull requests that do not follow these guidelines will be closed without review or comment. - If you use AI to write your PR description your pr will be close without review or comment. - If you are unsure about anything, feel free to ask for clarification. ## Description Please provide a clear description of your changes. --- ## Type of Change Please delete options that are not relevant. - [ ] 🐛 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (non-breaking change which adds functionality) - [ ] 💥 Breaking change (fix or feature with breaking changes) - [ ] 📝 Documentation update - [ ] 🎨 UI/UX improvement - [ ] 🔒 Security enhancement - [ ] ⚡ Performance improvement ## Areas Affected Please check all that apply: - [ ] Email Integration (Gmail, IMAP, etc.) - [ ] User Interface/Experience - [ ] Authentication/Authorization - [ ] Data Storage/Management - [ ] API Endpoints - [ ] Documentation - [ ] Testing Infrastructure - [ ] Development Workflow - [ ] Deployment/Infrastructure ## Testing Done Describe the tests you've done: - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [ ] Manual testing performed - [ ] Cross-browser testing (if UI changes) - [ ] Mobile responsiveness verified (if UI changes) ## Security Considerations For changes involving data or authentication: - [ ] No sensitive data is exposed - [ ] Authentication checks are in place - [ ] Input validation is implemented - [ ] Rate limiting is considered (if applicable) ## Checklist - [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document - [ ] My code follows the project's style guidelines - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in complex areas - [ ] I have updated the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix/feature works - [ ] All tests pass locally - [ ] Any dependent changes are merged and published ## Additional Notes Add any other context about the pull request here. ## Screenshots/Recordings Add screenshots or recordings here if applicable. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._ --- ## Summary by cubic Added Playwright end-to-end tests to verify that the sidebar correctly summarizes the past five emails. - **Testing** - Checks that the AI chat sidebar opens and displays a summary when prompted. - Confirms the summary is visible and contains content. ## Summary by CodeRabbit * **New Features** * Added an end-to-end test to verify that the AI chat can summarize recent emails and display the result in the inbox sidebar. * **Style** * Added a data attribute to each AI chat message for improved message role identification. --- packages/testing/e2e/ai-summary.spec.ts | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 packages/testing/e2e/ai-summary.spec.ts diff --git a/packages/testing/e2e/ai-summary.spec.ts b/packages/testing/e2e/ai-summary.spec.ts new file mode 100644 index 000000000..52e5ba242 --- /dev/null +++ b/packages/testing/e2e/ai-summary.spec.ts @@ -0,0 +1,55 @@ +import { test, expect } from '@playwright/test'; + +const email = process.env.EMAIL; + +if (!email) { + throw new Error('EMAIL environment variable must be set.'); +} + +test.describe('AI Chat Email Summarization', () => { + test('should summarize emails and display the result', async ({ page }) => { + await page.goto('/mail/inbox'); + await page.waitForLoadState('domcontentloaded'); + console.log('Successfully accessed mail inbox'); + + await page.waitForTimeout(2000); + try { + const welcomeModal = page.getByText('Welcome to Zero Email!'); + if (await welcomeModal.isVisible({ timeout: 2000 })) { + console.log('Onboarding modal detected, dismissing...'); + await page.locator('body').click({ position: { x: 100, y: 100 } }); + await page.waitForTimeout(1500); + console.log('Modal successfully dismissed'); + } + } catch { + console.log('No onboarding modal found, proceeding...'); + } + + await expect(page.getByText('Inbox')).toBeVisible(); + console.log('Mail inbox is now visible'); + + console.log('Opening AI chat sidebar with keyboard shortcut...'); + await page.keyboard.press('Meta+0'); + await expect(page.locator('form#ai-chat-form')).toBeVisible({ timeout: 10000 }); + console.log('AI chat sidebar opened successfully'); + + const chatInput = page.locator('form#ai-chat-form [contenteditable="true"]').first(); + await chatInput.click(); + await chatInput.fill('Please summarise the past five emails'); + await page.keyboard.press('Enter'); + console.log('Sent summarization query by pressing Enter'); + + console.log('Waiting for AI response...'); + + const assistantMessage = page.locator('[data-message-role="assistant"]').last(); + await expect(assistantMessage).toBeVisible({ timeout: 15000 }); + + const responseText = await assistantMessage.textContent(); + + console.log('AI Response Text:', responseText); + expect(responseText).toBeTruthy(); + expect(responseText!.length).toBeGreaterThan(15); + + console.log('Test completed: AI summarization successful!'); + }); +}); \ No newline at end of file