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(time-select;drop-times): add e2e UI test #63

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

Youyou-smiles
Copy link
Contributor

@Youyou-smiles Youyou-smiles commented Sep 25, 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 new test suite for the drop-times component to validate UI behavior through various user interactions.
    • Added a comprehensive testing suite for the time-select component, ensuring visual accuracy during user interactions.
  • Tests

    • Implemented multiple screenshot captures to verify the visual state of both components under different scenarios.

Copy link

coderabbitai bot commented Sep 25, 2024

Walkthrough

This pull request introduces new test suites for the drop-times and time-select components, implemented in Playwright. Each suite contains tests that validate the UI behavior through various user interactions, capturing screenshots to verify visual states. The tests ensure that elements are in the viewport during interactions, focusing on the components' responsiveness and visual integrity.

Changes

File Path Change Summary
tests/drop-times/xdesign.spec.ts Introduced a test suite for the drop-times component, covering UI interactions and screenshot captures.
tests/time-select/xdesign.spec.ts Added a test suite for the time-select component, focusing on user interactions and visual state verification through screenshots.

Possibly related PRs

  • test(notify): add notify UI e2e test #30: The tests/notify/xdesign.spec.ts PR introduces a test suite for the notify component, which includes interactions and visual validations similar to the interactions covered in the drop-times component tests.
  • test: add search UI e2e test #39: The tests/search/xdesign.spec.ts PR includes tests for the search component that also focus on user interactions and visual states, paralleling the interaction-based testing approach of the drop-times component.
  • test: add tabs UI e2e test #46: The tests/tabs/xdesign.spec.ts PR features tests for the tabs component, which similarly emphasizes UI interactions and visual validations, akin to the testing strategy employed in the drop-times component.
  • test: add time-line UI e2e test #47: The tests/time-line/xdesign.spec.ts PR introduces tests for the timeline component, which also involves capturing screenshots based on user interactions, aligning with the approach taken in the drop-times component tests.

Suggested labels

e2e

Suggested reviewers

  • zzcr

Poem

🐇 In the land of code where bunnies play,
New tests hop in to brighten the day.
Screenshots captured, UI in sight,
Ensuring the components work just right!
With every click, a joyful cheer,
For the drop-times and time-select are here! 🎉


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 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.

@github-actions github-actions bot added the e2e playwright label Sep 25, 2024
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

Outside diff range and nitpick comments (8)
tests/drop-times/xdesign.spec.ts (5)

1-3: Consider translating the test suite description to English.

The test suite description is currently in Chinese. For consistency and to improve readability for non-Chinese speaking developers, consider translating it to English.

Suggested translation:

test.describe('drop-times component xdesign specification', () => {

4-10: Approve test setup and suggest translating the test title to English.

The test setup, including error handling, navigation, and initial screenshot capture, looks good. However, for consistency, consider translating the test title to English.

Suggested translation:

test('Default--UI screenshot', async ({ page }) => {

12-21: Approve hover and focus interactions and suggest translating comments to English.

The hover and focus interactions, along with their respective screenshot captures, are well implemented. However, for consistency and improved readability, consider translating the Chinese comments to English.

Suggested translations:

// Screenshot on hover
// ...
// Screenshot on focus

23-32: Approve time selection interaction, correct comment, and suggest translation to English.

The time selection interaction and screenshot captures are well implemented. However, there are a few improvements to be made:

  1. The comment on line 23 is incorrect and duplicated from the previous section. It should describe the time selection action instead of focusing.
  2. For consistency and improved readability, translate the comments to English.

Suggested changes:

// Screenshot on time option hover
const select = page.getByText('00:30')
await select.hover()
await expect(bigPic).toBeInViewport()
await expect(bigPic).toHaveScreenshot('time-option-hover.png')  

// Screenshot after time selection
await select.click()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('time-selected.png')  

1-34: Approve overall test structure and coverage, suggest additional test cases.

The test provides excellent coverage of the drop-times component's UI behavior, capturing screenshots at various interaction stages. The structure is clear and follows a logical flow of user interactions.

To further enhance the test suite, consider adding the following test cases:

  1. Test with different time selections to ensure consistent behavior.
  2. Verify the behavior when an invalid time is entered manually.
  3. Test the component's responsiveness by changing the viewport size.
  4. Verify keyboard navigation and accessibility features.
tests/time-select/xdesign.spec.ts (3)

1-3: Consider using English for test descriptions.

The test suite description is currently in Chinese. For better maintainability and consistency, especially in international teams, consider using English for all test descriptions.

-test.describe('time-select组件xdesign规范', () => {
+test.describe('time-select component xdesign specification', () => {

12-21: Consider using more specific screenshot names.

The current screenshot names ('hover.png', 'focus.png') are descriptive but could be more specific to the time-select component. This would help differentiate these screenshots from similar interactions in other components.

Consider renaming the screenshots to be more specific:

-    await expect(demo).toHaveScreenshot('hover.png')
+    await expect(demo).toHaveScreenshot('time-select-hover.png')

-    await expect(bigPic).toHaveScreenshot('focus.png')  
+    await expect(bigPic).toHaveScreenshot('time-select-focus.png')  

23-32: Use more specific screenshot names for time selection interactions.

Similar to the previous suggestion, the screenshot names for time selection interactions could be more specific to the time-select component and the action being performed.

Consider renaming the screenshots:

-    await expect(bigPic).toHaveScreenshot('focus-hover.png')  
+    await expect(bigPic).toHaveScreenshot('time-select-option-hover.png')  

-    await expect(demo).toHaveScreenshot('select.png')  
+    await expect(demo).toHaveScreenshot('time-select-option-selected.png')  
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8c9ee66 and 7d370e1.

Files ignored due to path filters (12)
  • tests/drop-times/xdesign.spec.ts-snapshots/basic-usage-chromium-win32.png is excluded by !**/*.png
  • tests/drop-times/xdesign.spec.ts-snapshots/click-chromium-win32.png is excluded by !**/*.png
  • tests/drop-times/xdesign.spec.ts-snapshots/focus-hover-chromium-win32.png is excluded by !**/*.png
  • tests/drop-times/xdesign.spec.ts-snapshots/hover-chromium-win32.png is excluded by !**/*.png
  • tests/drop-times/xdesign.spec.ts-snapshots/select-chromium-win32.png is excluded by !**/*.png
  • tests/time-select/xdesign.spec.ts-snapshots/basic-usage-chromium-win32.png is excluded by !**/*.png
  • tests/time-select/xdesign.spec.ts-snapshots/focus-chromium-win32.png is excluded by !**/*.png
  • tests/time-select/xdesign.spec.ts-snapshots/focus-hover-chromium-win32.png is excluded by !**/*.png
  • tests/time-select/xdesign.spec.ts-snapshots/hover-chromium-win32.png is excluded by !**/*.png
  • tests/time-select/xdesign.spec.ts-snapshots/icon-hover-chromium-win32.png is excluded by !**/*.png
  • tests/time-select/xdesign.spec.ts-snapshots/select-chromium-win32.png is excluded by !**/*.png
  • tests/time-select/xdesign.spec.ts-snapshots/select-hover-chromium-win32.png is excluded by !**/*.png
Files selected for processing (2)
  • tests/drop-times/xdesign.spec.ts (1 hunks)
  • tests/time-select/xdesign.spec.ts (1 hunks)

Comment on lines +4 to +10
test('默认--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('time-select#basic-usage')
const demo = page.locator('#basic-usage .pc-demo')
const bigPic = page.locator('#doc-layout div').filter({ hasText: '示例API基本用法详细用法参考如下示例。time-' }).nth(2)
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('basic-usage.png')
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use English for test titles and consider more robust navigation.

  1. The test title is in Chinese. For consistency and better maintainability, consider using English for all test titles.

  2. The navigation to the specific component demo uses a fragment identifier, which might be brittle if the page structure changes. Consider using a more robust method to navigate to the specific demo, such as environment variables or configuration files for URLs.

-  test('默认--UI截图', async ({ page }) => {
+  test('Default - UI screenshot', async ({ page }) => {

Consider refactoring the navigation to use a more robust method:

const BASE_URL = process.env.TEST_BASE_URL || 'http://your-default-url.com';
// ...
await page.goto(`${BASE_URL}/time-select#basic-usage`);

Comment on lines +34 to +44
// 选中后清除图标截图
const selectInput = demo.getByRole('textbox', { name: ':00' })
await selectInput.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('select-hover.png')

// 清除图标hover时截图
const icon = page.getByLabel('示例', { exact: true }).locator('path').nth(1)
await icon.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('icon-hover.png')
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve screenshot names and icon selection method.

  1. The screenshot names could be more specific to the time-select component and the action being performed.

  2. The method of selecting the clear icon using getByLabel and nth might be brittle if the page structure changes. Consider using a more robust selector method.

Rename the screenshots for clarity:

-    await expect(demo).toHaveScreenshot('select-hover.png')
+    await expect(demo).toHaveScreenshot('time-select-selected-hover.png')

-    await expect(demo).toHaveScreenshot('icon-hover.png')
+    await expect(demo).toHaveScreenshot('time-select-clear-icon-hover.png')

Consider using a more robust selector for the clear icon:

const clearIcon = demo.locator('.clear-icon-class');
// or
const clearIcon = demo.getByRole('button', { name: 'Clear' });

Replace the existing icon selection with the more robust method:

-    const icon = page.getByLabel('示例', { exact: true }).locator('path').nth(1)
-    await icon.hover()
+    const clearIcon = demo.locator('.clear-icon-class');
+    await clearIcon.hover()

Comment on lines +1 to +46
import { expect, test } from '@playwright/test'

test.describe('time-select组件xdesign规范', () => {
test('默认--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('time-select#basic-usage')
const demo = page.locator('#basic-usage .pc-demo')
const bigPic = page.locator('#doc-layout div').filter({ hasText: '示例API基本用法详细用法参考如下示例。time-' }).nth(2)
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('basic-usage.png')

// hover时截图
const input = demo.getByRole('textbox', { name: '选择时间' })
await input.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('hover.png')

// 聚焦时截图
await input.focus()
await expect(bigPic).toBeInViewport()
await expect(bigPic).toHaveScreenshot('focus.png')

// 聚焦时截图
const select = page.getByText('10:00')
await select.hover()
await expect(bigPic).toBeInViewport()
await expect(bigPic).toHaveScreenshot('focus-hover.png')

// 选中时截图
await select.click()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('select.png')

// 选中后清除图标截图
const selectInput = demo.getByRole('textbox', { name: ':00' })
await selectInput.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('select-hover.png')

// 清除图标hover时截图
const icon = page.getByLabel('示例', { exact: true }).locator('path').nth(1)
await icon.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('icon-hover.png')
})
})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding more test cases for improved coverage.

While the current test provides good coverage of basic user interactions, consider adding the following test cases to improve overall coverage:

  1. Verify the selected time value is correctly displayed in the input field.
  2. Test error states (e.g., selecting an invalid time).
  3. Test edge cases (e.g., selecting the first and last available times).
  4. Test keyboard navigation and accessibility features.

Here's an example of how you might add a test to verify the selected time value:

test('Verify selected time value', async ({ page }) => {
  // ... (setup code) ...
  
  const timeOption = page.getByText('10:00');
  await timeOption.click();
  
  const input = demo.getByRole('textbox', { name: '选择时间' });
  await expect(input).toHaveValue('10:00');
});

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.

2 participants