cherry-studio/tests/e2e/specs/navigation.spec.ts
fullex d0bd10190d
feat(test): e2e framework (#11494)
* feat(test): e2e framework

Add Playwright-based e2e testing framework for Electron app with:
- Custom fixtures for electronApp and mainWindow
- Page Object Model (POM) pattern implementation
- 15 example test cases covering app launch, navigation, settings, and chat
- Comprehensive README for humans and AI assistants

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(tests): update imports and improve code readability

- Changed imports from 'import { Page, Locator }' to 'import type { Locator, Page }' for better type clarity across multiple page files.
- Reformatted waitFor calls in ChatPage and HomePage for improved readability.
- Updated index.ts to correct the export order of ChatPage and SidebarPage.
- Minor adjustments in electron.fixture.ts and electron-app.ts for consistency in import statements.

These changes enhance the maintainability and clarity of the test codebase.

* chore: update linting configuration to include tests directory

- Added 'tests/**' to the ignore patterns in .oxlintrc.json and eslint.config.mjs to ensure test files are not linted.
- Minor adjustment in electron.fixture.ts to improve the fixture definition.

These changes streamline the linting process and enhance code organization.

* fix(test): select main window by title to fix flaky e2e tests on Mac

On Mac, the app may create miniWindow for QuickAssistant alongside mainWindow.
Using firstWindow() could randomly select the wrong window, causing test failures.
Now we wait for the window with title "Cherry Studio" to ensure we get the main window.

Also removed unused electron-app.ts utility file.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-27 19:52:31 +08:00

47 lines
1.3 KiB
TypeScript

import { expect, test } from '../fixtures/electron.fixture'
import { SidebarPage } from '../pages/sidebar.page'
import { waitForAppReady } from '../utils/wait-helpers'
test.describe('Navigation', () => {
let sidebarPage: SidebarPage
test.beforeEach(async ({ mainWindow }) => {
await waitForAppReady(mainWindow)
sidebarPage = new SidebarPage(mainWindow)
})
test('should navigate to Settings page', async ({ mainWindow }) => {
await sidebarPage.goToSettings()
// Wait a bit for navigation to complete
await mainWindow.waitForTimeout(1000)
const currentUrl = mainWindow.url()
expect(currentUrl).toContain('/settings')
})
test('should navigate to Files page', async ({ mainWindow }) => {
await sidebarPage.goToFiles()
await mainWindow.waitForTimeout(1000)
const currentUrl = mainWindow.url()
expect(currentUrl).toContain('/files')
})
test('should navigate back to Home', async ({ mainWindow }) => {
// First go to settings
await sidebarPage.goToSettings()
await mainWindow.waitForTimeout(1000)
// Then go back to home
await sidebarPage.goToHome()
await mainWindow.waitForTimeout(1000)
// Verify we're on home page
const currentUrl = mainWindow.url()
// Home page URL should be either / or empty hash
expect(currentUrl).toMatch(/#\/?$|#$/)
})
})