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(e2e): add radio UI e2e test #37

Merged
merged 1 commit into from
Sep 20, 2024
Merged

test(e2e): add radio UI e2e test #37

merged 1 commit into from
Sep 20, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Sep 19, 2024

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 comprehensive test suite for the radio component, ensuring UI consistency across various states (default, hover, disabled, vertical layout, and size variations).
    • Implemented visual regression testing with automated screenshot captures for accurate visual representation.
  • Documentation

    • Added descriptive test cases in the documentation for better clarity on the radio component's behavior.

Copy link

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes introduce a new test suite for the radio component located in tests/radio/xdesign.spec.ts. This suite includes multiple Playwright tests that validate the UI behavior of the radio component across various states such as default, disabled, and size variations. Each test captures screenshots to ensure visual consistency and accuracy of the component's appearance.

Changes

File Change Summary
tests/radio/xdesign.spec.ts Added a test suite with five tests: default state, radio group, disabled state, vertical layout, and size variations, each capturing UI screenshots.

Possibly related PRs

  • test(tag): add tag e2e UI snapshot #28: The tag component tests include a similar structure of UI tests using Playwright, validating visual output and capturing screenshots, which aligns with the approach taken in the main PR for the radio component.
  • test(alert): add alert e2e ui snapshot #31: The alert component tests also utilize Playwright for UI testing and involve capturing screenshots for various states, similar to the visual regression testing framework established in the main PR for the radio component.

Suggested labels

e2e

Suggested reviewers

  • shenjunjian
  • gimmyhehe

Poem

In the garden where radios bloom,
Tests now dance, dispelling gloom.
Screenshots captured, states in view,
A hop of joy for all that's new!
With every click, the UI shines,
A playful test, where code aligns! 🐇✨


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 generate interesting stats about this repository and render them as a table.
    -- @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 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: 1

Outside diff range and nitpick comments (1)
tests/radio/xdesign.spec.ts (1)

12-12: Use more resilient selectors instead of hard-coded text

Using hard-coded text strings like '选项二', '公交', and '地铁' in your locators can make tests fragile if the text changes or if localization is implemented. Consider using data attributes or roles to make your selectors more robust.

For example, assign data attributes to your elements in the application code:

<label data-test-id="option-two">选项二</label>

Then, update your test selectors:

-await page.getByRole('radio', { name: '选项二' }).hover()
+await page.locator('[data-test-id="option-two"]').hover()

Also applies to: 25-25, 29-29

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eff32a3 and 6cf50db.

Files ignored due to path filters (8)
  • tests/radio/xdesign.spec.ts-snapshots/basic-usage-chromium-win32.png is excluded by !**/*.png
  • tests/radio/xdesign.spec.ts-snapshots/checked-hover-chromium-win32.png is excluded by !**/*.png
  • tests/radio/xdesign.spec.ts-snapshots/disabled-chromium-win32.png is excluded by !**/*.png
  • tests/radio/xdesign.spec.ts-snapshots/group-hover-chromium-win32.png is excluded by !**/*.png
  • tests/radio/xdesign.spec.ts-snapshots/hover-chromium-win32.png is excluded by !**/*.png
  • tests/radio/xdesign.spec.ts-snapshots/radio-group-chromium-win32.png is excluded by !**/*.png
  • tests/radio/xdesign.spec.ts-snapshots/size-chromium-win32.png is excluded by !**/*.png
  • tests/radio/xdesign.spec.ts-snapshots/vertical-chromium-win32.png is excluded by !**/*.png
Files selected for processing (1)
  • tests/radio/xdesign.spec.ts (1 hunks)
Additional comments not posted (1)
tests/radio/xdesign.spec.ts (1)

6-6: Verify that page.goto navigations work with relative URLs

The page.goto method uses relative URLs like 'radio#basic-usage'. Ensure that your Playwright configuration includes a baseURL so that these relative navigations resolve correctly. Otherwise, the tests might fail to load the intended pages.

Run the following script to check if a baseURL is set in your Playwright configuration:

Also applies to: 19-19, 36-36, 44-44, 52-52

Verification successful

To gather more information about how the baseURL is defined and used in the Playwright configuration, let's run another script to view more context:


Relative URL navigation with page.goto is correctly configured

The Playwright configuration file (playwright.config.ts) properly sets up the baseURL for relative URL navigation. The baseURL is defined as ${origin}/tiny-vue/zh-CN/smb-theme/components/, where origin is set to 'http://localhost:3101'. This configuration ensures that relative URLs like 'radio#basic-usage' used in page.goto() will resolve correctly.

Key points:

  • The baseURL is correctly defined and exported in the configuration.
  • It points to a local development server, which is appropriate for testing.
  • The configuration is set up for a Vue.js application, likely using a custom testing framework.

No changes are required for the page.goto calls with relative URLs in your tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that 'baseURL' is set in Playwright configuration.

# Test: Search for 'baseURL' in Playwright config files.
# Expect: 'baseURL' to be defined in the configuration.

fd -e ts -e js -e mjs --max-depth 2 'playwright.config' --exec grep -E 'baseURL.*='

Length of output: 148


Script:

#!/bin/bash
# Description: View context around 'baseURL' definition in Playwright config

# Find the Playwright config file
config_file=$(fd -e ts -e js -e mjs --max-depth 2 'playwright.config' | head -n 1)

# If config file is found, show context around baseURL
if [ -n "$config_file" ]; then
  echo "Contents of $config_file:"
  echo "------------------------"
  cat "$config_file"
else
  echo "Playwright config file not found."
fi

Length of output: 1012


test.describe('radio组件xdesign规范', () => {
test('默认--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
Copy link

Choose a reason for hiding this comment

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

Refactor to use a beforeEach hook for setting up the page error handler

Currently, each test sets up the same page error handler individually. To reduce code duplication and improve maintainability, consider moving this event listener into a beforeEach hook.

Apply this diff to refactor the code:

+test.beforeEach(async ({ page }) => {
+  page.on('pageerror', (exception) => expect(exception).toBeNull())
+})

-  test('默认--UI截图', async ({ page }) => {
-    page.on('pageerror', (exception) => expect(exception).toBeNull())
   // ... rest of the test

-  test('单选框组--UI截图', async ({ page }) => {
-    page.on('pageerror', (exception) => expect(exception).toBeNull())
   // ... rest of the test

-  test('禁用--UI截图', async ({ page }) => {
-    page.on('pageerror', (exception) => expect(exception).toBeNull())
   // ... rest of the test

-  test('垂直布局--UI截图', async ({ page }) => {
-    page.on('pageerror', (exception) => expect(exception).toBeNull())
   // ... rest of the test

-  test('尺寸--UI截图', async ({ page }) => {
-    page.on('pageerror', (exception) => expect(exception).toBeNull())
   // ... rest of the test

Also applies to: 18-18, 35-35, 43-43, 51-51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e playwright
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant