Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix e2e test #244

Merged
merged 1 commit into from
Mar 3, 2025
Merged

test: fix e2e test #244

merged 1 commit into from
Mar 3, 2025

Conversation

zzxming
Copy link
Member

@zzxming zzxming commented Mar 3, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced a fallback for version information, ensuring consistent display even when version data is missing.
  • Tests

    • Updated demo page routes and refined element selections for toolbar and image functionalities to improve reliability in user interactions.
  • Chores

    • Enhanced testing configuration with revised local server settings and extended timeouts for smoother test execution.

Copy link

coderabbitai bot commented Mar 3, 2025

Walkthrough

This pull request implements changes across documentation and test files. The version insertion function now assigns a default value of 'dev' if a version variable is unset. In the Playwright tests, element selection is updated from using await page.$ to page.locator, and URLs are adjusted from /docs/ to /docs/demo/ paths. Additionally, the Playwright configuration is modified with a new timeout setting and an updated web server command.

Changes

File(s) Summary
packages/.../fluent-editor/.vitepress/theme/insert-deps-version.ts Modified the insertDepsVersion function to use fallback values ('dev') for version attributes when variables are falsy.
packages/.../fluent-editor/demos/add-toolbar-item.spec.ts, packages/.../fluent-editor/demos/basic-usage.spec.ts, packages/.../fluent-editor/demos/image-upload.spec.ts Updated test URLs to /docs/demo/... and replaced deprecated await page.$ with page.locator, including refined selectors for editor, toolbar, and image elements.
packages/.../playwright.config.ts Added a timeout setting of 120 seconds and updated the web server configuration to execute pnpm dev on port 5173 with reuse of the existing server based on the CI flag.

Sequence Diagram(s)

sequenceDiagram
    participant F as insertDepsVersion
    participant D as Document Body
    F->>F: Retrieve version variables (Vite, VitePress, Vue, Quill)
    alt Version exists
        F->>D: Set corresponding data attribute with version value
    else
        F->>D: Set corresponding data attribute to 'dev'
    end
Loading

Suggested labels

bug

Suggested reviewers

  • kagol

Poem

I'm a rabbit coder, hopping with delight,
Setting fallbacks as I code through the night.
Tests now click and scroll with precision so keen,
Configs and docs polished, smooth and clean.
With a spring in my step and a carrot so bright,
I celebrate these changes under the moonlight!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (3)
packages/docs/fluent-editor/demos/add-toolbar-item.spec.ts (3)

43-43: Consider translating the Chinese comment to English for consistency.

The comment "添加更多测试用例" (which translates to "Add more test cases") could be translated to English to maintain consistency throughout the codebase.

- // 添加更多测试用例
+ // Add more test cases

13-20: Add a test to verify toolbar buttons' visual appearance.

Since you're testing custom toolbar items, consider adding a test to verify they have the correct visual properties (icons, tooltips, etc.) to ensure a complete test coverage.

test('should display toolbar buttons with correct visual properties', async ({ page }) => {
  const goodButton = page.locator('.ql-good')
  const badButton = page.locator('.ql-bad')
  
  // Check if buttons have the expected appearance
  await expect(goodButton).toBeVisible()
  await expect(badButton).toBeVisible()
  
  // Verify tooltips or other visual attributes if applicable
  // Example: await expect(goodButton).toHaveAttribute('title', 'Good Format')
})

22-41: Enhance test reliability by awaiting content changes.

The test could be more reliable by explicitly waiting for content changes after applying formats, rather than relying on immediate state changes.

test('should apply custom formats when toolbar buttons are clicked', async ({ page }) => {
  const editor = page.locator('#editor-add-toolbar-item .ql-editor')
  expect(editor).not.toBeNull()
  await editor.click()
  await page.keyboard.type('Test text')

  const goodButton = page.locator('.ql-good')
  expect(goodButton).not.toBeNull()
  await goodButton.click()
  await page.keyboard.type(' Good')

  const badButton = page.locator('.ql-bad')
  expect(badButton).not.toBeNull()
  await badButton.click()
  await page.keyboard.type(' Bad')

+ // Wait for editor content to stabilize after formatting
+ await page.waitForTimeout(100)

  const editorHtml = await editor.innerHTML()
  expect(editorHtml).toContain('<span style="color: rgb(92, 179, 0);"> Good</span>')
  expect(editorHtml).toContain('<span style="color: rgb(242, 48, 48);"> Bad</span>')
})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3e7ee3 and dc7a7c8.

📒 Files selected for processing (5)
  • packages/docs/fluent-editor/.vitepress/theme/insert-deps-version.ts (1 hunks)
  • packages/docs/fluent-editor/demos/add-toolbar-item.spec.ts (1 hunks)
  • packages/docs/fluent-editor/demos/basic-usage.spec.ts (1 hunks)
  • packages/docs/fluent-editor/demos/image-upload.spec.ts (2 hunks)
  • packages/docs/playwright.config.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Playwright Tests
packages/docs/fluent-editor/demos/basic-usage.spec.ts

[error] 5-5: Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:5173/tiny-editor/docs/demo/basic-usage

packages/docs/fluent-editor/demos/image-upload.spec.ts

[error] 10-10: Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:5173/tiny-editor/docs/demo/image-upload

packages/docs/fluent-editor/demos/add-toolbar-item.spec.ts

[error] 5-5: Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:5173/tiny-editor/docs/demo/add-toolbar-item


[error] 5-5: Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:5173/tiny-editor/docs/demo/add-toolbar-item


[error] 5-5: Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:5173/tiny-editor/docs/demo/add-toolbar-item

🔇 Additional comments (5)
packages/docs/fluent-editor/demos/basic-usage.spec.ts (1)

5-5:

❓ Verification inconclusive

URL path has been updated to match new demo structure

The URL has been changed to include /demo/ in the path, which aligns with the new demo path structure used across test files. This is a good consistency improvement.

However, there is a pipeline failure showing that this URL is resulting in a connection refused error. This needs to be verified.


🏁 Script executed:

#!/bin/bash
# Check if the server is configured correctly for the new URL path structure
# First, find the server config in the project
rg -A 3 "tiny-editor/docs/demo" --type ts

# Then, check if there are any vite.config or similar files that define routes
fd -e ts "config" --exec grep -l "routes\|path" {}

Length of output: 1443


Attention: Verify Demo Server Connectivity on Updated URL Structure

  • The new URL path (e.g., http://localhost:5173/tiny-editor/docs/demo/basic-usage) is consistently applied across all demo test files.
  • Our code search confirms that files like basic-usage.spec.ts, add-toolbar-item.spec.ts, and image-upload.spec.ts have been updated accordingly.
  • However, the pipeline failure indicating a “connection refused” error suggests that the demo server may not be starting/updating its routes as expected in the test environment.
  • Please manually verify that the demo server is correctly configured, is running on port 5173, and that any route definitions in configuration files (e.g., in packages/docs/playwright.config.ts, packages/fluent-editor/vite.config.ts, etc.) accommodate the /demo/ path. In addition, ensure that any changes in the server startup configuration are reflected in the CI/pipeline environment.
🧰 Tools
🪛 GitHub Actions: Playwright Tests

[error] 5-5: Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:5173/tiny-editor/docs/demo/basic-usage

packages/docs/fluent-editor/.vitepress/theme/insert-deps-version.ts (1)

14-17: Improved robustness with fallback version values

Adding fallback values for the version attributes is a good defensive programming practice. This ensures that the document attributes will always have a value even if the environment variables are undefined, which prevents potential DOM-related issues.

packages/docs/fluent-editor/demos/image-upload.spec.ts (1)

23-23: Improved selector specificity for image element

The selector for the image element has been refined to be more specific by targeting an image within #editor .ql-editor rather than just within #editor. This makes the test more robust against potential DOM structure changes and provides more reliable element targeting.

packages/docs/playwright.config.ts (1)

73-73: Increased test timeout for better stability

Adding a global timeout of 120 seconds (120,000 milliseconds) is a good practice for end-to-end tests, especially when working with complex UI components like rich text editors. This helps prevent tests from failing due to timing issues in slower environments.

packages/docs/fluent-editor/demos/add-toolbar-item.spec.ts (1)

9-9: Good migration from deprecated page.$ to recommended page.locator API.

The updates from await page.$ to page.locator align with Playwright's best practices for element selection. This approach provides better chainability and improved selector capabilities.

Note that page.locator() returns a Locator object immediately (without waiting), so removing the await is correct. Actions performed on these locators (like click()) will still need to be awaited.

Also applies to: 14-17, 23-24, 28-29, 33-34

@zzxming
Copy link
Member Author

zzxming commented Mar 3, 2025

由于 vite 服务启动失败,需要 #243 合并后 test 应该可以通过

@kagol kagol merged commit f510486 into opentiny:main Mar 3, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants