Skip to content

Commit cdb3d25

Browse files
authored
feat: add playwright tests to check search bar functions (#1921)
goes through the cmd+k search shortcut and runs: 1. last seven days of emails 2. starred emails 3. with attachments run w `pnpm test:e2e:headed search-bar.spec.ts` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added Playwright end-to-end tests to verify that the search bar correctly applies and clears filters for "Last 7 Days," "Starred Emails," and "With Attachments" using the command palette. <!-- 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 to verify that search bar filters ("With Attachments", "Last 7 Days", "Starred Emails") can be applied and cleared using the command palette. The test also checks for the correct display and removal of the "Clear" button in the search bar. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 066edbc commit cdb3d25

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Search Bar Functionality', () => {
4+
test('should apply and clear multiple filters from the command palette', 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+
11+
try {
12+
const welcomeModal = page.getByText('Welcome to Zero Email!')
13+
if (await welcomeModal.isVisible({ timeout: 2000 })) {
14+
console.log('Onboarding modal detected, clicking outside to dismiss')
15+
await page.locator('body').click({ position: { x: 100, y: 100 } })
16+
await page.waitForTimeout(1500)
17+
console.log('Modal successfully dismissed')
18+
}
19+
} catch {
20+
console.log('No onboarding modal found, proceeding')
21+
}
22+
23+
await expect(page.getByText('Inbox')).toBeVisible()
24+
console.log('Confirmed we are in the inbox')
25+
26+
const filtersToTest = ["With Attachments", "Last 7 Days", "Starred Emails"]
27+
28+
for (const filterText of filtersToTest) {
29+
console.log(`Testing filter: ${filterText}`)
30+
31+
console.log(`Opening command palette with Meta+k`)
32+
await page.keyboard.press(`Meta+k`)
33+
34+
const dialogLocator = page.locator('[cmdk-dialog], [role="dialog"]')
35+
await expect(dialogLocator.first()).toBeVisible({ timeout: 5000 })
36+
console.log('Command palette dialog is visible')
37+
38+
const itemLocator = page.getByText(filterText, { exact: true })
39+
await expect(itemLocator).toBeVisible()
40+
console.log(`Found "${filterText}" item, attempting to click`)
41+
await itemLocator.click()
42+
console.log(`Successfully clicked "${filterText}"`)
43+
44+
await expect(dialogLocator.first()).not.toBeVisible({ timeout: 5000 })
45+
console.log('Command palette dialog has closed')
46+
47+
console.log('Looking for the "Clear" button in the search bar')
48+
const clearButton = page.getByRole('button', { name: 'Clear', exact: true })
49+
await expect(clearButton).toBeVisible({ timeout: 5000 })
50+
console.log('"Clear" button is visible, confirming filter is active')
51+
52+
console.log('Waiting 4 seconds for filter results to load')
53+
await page.waitForTimeout(4000)
54+
55+
await clearButton.click()
56+
console.log('Clicked the "Clear" button')
57+
58+
await expect(clearButton).not.toBeVisible({ timeout: 5000 })
59+
console.log('Filter cleared successfully')
60+
}
61+
62+
console.log(`Test completed: Successfully applied and cleared ${filtersToTest.length} filters`)
63+
})
64+
})

0 commit comments

Comments
 (0)