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

refactor(split): [split] refactor split theme #2194

Merged
merged 1 commit into from
Sep 27, 2024
Merged

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Sep 26, 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

    • Updated the styling of the split component, enhancing responsiveness and visual consistency through CSS variables.
    • Introduced refined hover states for trigger elements.
  • Bug Fixes

    • Adjusted assertions in test cases for improved precision in UI component dimension comparisons.
  • Documentation

    • Clarified changes in CSS variable definitions to reflect a new design system for the split panel component.

Copy link

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes primarily involve the removal of border styles from various CSS classes across multiple Vue component files. This alteration affects the visual styling of components, specifically those using the .split-v-model and .demo-split classes, by eliminating previously defined borders. Additionally, modifications were made to test files to change assertion methods from toBeCloseTo to toEqual, adjusting the precision of comparisons in tests.

Changes

File(s) Change Summary
examples/sites/demos/pc/app/split/*.vue Removed border: 1px solid #d9d9d9; from .split-v-model and .demo-split classes in various files, altering their visual styling.
examples/sites/demos/pc/app/split/*.spec.ts Updated assertions from toBeCloseTo to toEqual with Math.ceil() for stricter comparison in test cases.
packages/theme/src/split/index.less Replaced .component-css-vars-split() with .inject-Split-vars(), updated styles and dimensions using CSS variables.
packages/theme/src/split/vars.less Removed .component-css-vars-split() and introduced .inject-Split-vars() with new CSS variable definitions.

Possibly related PRs

Suggested labels

refactoring

Poem

🐇 In a meadow bright and fair,
Borders gone, no more to wear.
Components dance with styles anew,
A cleaner look, a fresher view.
Tests now precise, no room for doubt,
Hooray for changes, let’s hop about! 🐇


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 refactoring Refactoring (重构) label Sep 26, 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: 6

🧹 Outside diff range and nitpick comments (5)
packages/theme/src/split/vars.less (1)

14-23: Consider translating comments to English for better international collaboration.

The overall consistency and naming conventions are excellent. The use of the --tv-Split- prefix and descriptive variable names enhances readability and maintainability.

However, the comments are currently in Chinese. For better international collaboration, consider translating these comments to English.

Here's a suggested translation for the comments:

// Panel border color
--tv-Split-wrapper-border-color: var(--tv-color-border);
// Panel split line trigger icon line color
--tv-Split-trigger-icon-line-color: var(--tv-color-icon);
// Panel split line trigger icon line hover color
--tv-Split-trigger-icon-line-color-hover: var(--tv-color-icon-hover);
// Panel border radius size
--tv-Split-wrapper-radius-size: var(--tv-border-radius-lg);
// Simple mode split line hover background color
--tv-Split-trigger-line-bg-hover: var(--tv-color-border-active-control);
examples/sites/demos/pc/app/split/split-threshold.spec.ts (1)

Line range hint 1-24: Consider adding more comprehensive test cases.

While the changes to the assertions make the tests more precise, they might also make them more brittle. Additionally, the current test doesn't fully verify the threshold behavior of the split panel.

Consider adding the following test cases:

  1. Test that the panel doesn't resize below the minimum threshold.
  2. Test that the panel doesn't resize above the maximum threshold.
  3. Test the behavior when trying to resize exactly at the threshold limits.

For example:

// Test minimum threshold
await triggerBtn.hover()
await page.mouse.down()
await page.mouse.move(x, y + 1000) // Move way past the threshold
await page.mouse.up()
const { height: minHeight } = await topPanel.boundingBox()
await expect(minHeight).toBeGreaterThanOrEqual(50) // Assuming 50 is the min threshold

// Similar tests for maximum threshold and at-threshold behavior

These additional tests will ensure that the split functionality works correctly within its defined limits.

examples/sites/demos/pc/app/split/nested-use.spec.ts (1)

Line range hint 1-36: Summary of changes and alignment with PR objectives

The changes in this file consistently modify the assertion logic for component dimensions after user interactions. While these changes align with the general goal of refactoring mentioned in the PR objectives, there are a few points to consider:

  1. The modifications potentially make the tests more strict, which could catch previously undetected issues but might also introduce false positives.
  2. The refactoring approach could be further improved to enhance maintainability and flexibility of the tests.

To better align with the refactoring objectives:

  1. Consider implementing a more generalized solution for these assertions, as suggested in the previous comments.
  2. Ensure that these changes are consistent across all relevant test files in the project.
  3. Update the documentation to reflect any new patterns or helpers introduced during this refactoring.
  4. If these changes are part of a larger refactoring effort for the split theme, consider providing more context in the PR description about the specific goals and scope of the refactoring.

These steps will help ensure that the refactoring not only improves the current file but also contributes to the overall maintainability and consistency of the project's test suite.

packages/theme/src/split/index.less (2)

30-30: Translate comment to English

The comment is currently in Chinese:

// split嵌套使用内部不需要圆角和边框

For better understanding among the team and consistency, please translate the comment to English.


76-76: Specify transitioned properties for better performance

Using transition: all 0.1s; affects all properties, which can lead to unintended animations and performance issues. It's better to specify only the properties that need to be transitioned.

Apply this diff to specify the properties:

-transition: all 0.1s;
+transition: transform 0.1s;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ca051e7 and f507d38.

📒 Files selected for processing (41)
  • examples/sites/demos/pc/app/split/basic-usage-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/basic-usage.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/split/basic-usage.vue (0 hunks)
  • examples/sites/demos/pc/app/split/collapsible-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/collapsible.vue (0 hunks)
  • examples/sites/demos/pc/app/split/disabled-drag-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/disabled-drag.vue (0 hunks)
  • examples/sites/demos/pc/app/split/event-click-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/event-click.vue (0 hunks)
  • examples/sites/demos/pc/app/split/horizontal-collapse-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/horizontal-collapse-left-top-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/horizontal-collapse-left-top.vue (0 hunks)
  • examples/sites/demos/pc/app/split/horizontal-collapse.vue (0 hunks)
  • examples/sites/demos/pc/app/split/left-right-slot-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/left-right-slot.vue (0 hunks)
  • examples/sites/demos/pc/app/split/moveend-event-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/moveend-event.vue (0 hunks)
  • examples/sites/demos/pc/app/split/movestart-event-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/movestart-event.vue (0 hunks)
  • examples/sites/demos/pc/app/split/moving-event-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/moving-event.vue (0 hunks)
  • examples/sites/demos/pc/app/split/nested-use-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/nested-use.spec.ts (2 hunks)
  • examples/sites/demos/pc/app/split/nested-use.vue (0 hunks)
  • examples/sites/demos/pc/app/split/split-mode-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/split-mode.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/split/split-mode.vue (0 hunks)
  • examples/sites/demos/pc/app/split/split-threshold-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/split-threshold.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/split/split-threshold.vue (0 hunks)
  • examples/sites/demos/pc/app/split/three-areas-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/three-areas.vue (0 hunks)
  • examples/sites/demos/pc/app/split/top-bottom-slot-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/top-bottom-slot.vue (0 hunks)
  • examples/sites/demos/pc/app/split/trigger-simple-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/trigger-simple.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/split/trigger-simple.vue (0 hunks)
  • examples/sites/demos/pc/app/split/trigger-slot-composition-api.vue (0 hunks)
  • examples/sites/demos/pc/app/split/trigger-slot.vue (0 hunks)
  • packages/theme/src/split/index.less (7 hunks)
  • packages/theme/src/split/vars.less (1 hunks)
💤 Files not reviewed due to no reviewable changes (34)
  • examples/sites/demos/pc/app/split/basic-usage-composition-api.vue
  • examples/sites/demos/pc/app/split/basic-usage.vue
  • examples/sites/demos/pc/app/split/collapsible-composition-api.vue
  • examples/sites/demos/pc/app/split/collapsible.vue
  • examples/sites/demos/pc/app/split/disabled-drag-composition-api.vue
  • examples/sites/demos/pc/app/split/disabled-drag.vue
  • examples/sites/demos/pc/app/split/event-click-composition-api.vue
  • examples/sites/demos/pc/app/split/event-click.vue
  • examples/sites/demos/pc/app/split/horizontal-collapse-composition-api.vue
  • examples/sites/demos/pc/app/split/horizontal-collapse-left-top-composition-api.vue
  • examples/sites/demos/pc/app/split/horizontal-collapse-left-top.vue
  • examples/sites/demos/pc/app/split/horizontal-collapse.vue
  • examples/sites/demos/pc/app/split/left-right-slot-composition-api.vue
  • examples/sites/demos/pc/app/split/left-right-slot.vue
  • examples/sites/demos/pc/app/split/moveend-event-composition-api.vue
  • examples/sites/demos/pc/app/split/moveend-event.vue
  • examples/sites/demos/pc/app/split/movestart-event-composition-api.vue
  • examples/sites/demos/pc/app/split/movestart-event.vue
  • examples/sites/demos/pc/app/split/moving-event-composition-api.vue
  • examples/sites/demos/pc/app/split/moving-event.vue
  • examples/sites/demos/pc/app/split/nested-use-composition-api.vue
  • examples/sites/demos/pc/app/split/nested-use.vue
  • examples/sites/demos/pc/app/split/split-mode-composition-api.vue
  • examples/sites/demos/pc/app/split/split-mode.vue
  • examples/sites/demos/pc/app/split/split-threshold-composition-api.vue
  • examples/sites/demos/pc/app/split/split-threshold.vue
  • examples/sites/demos/pc/app/split/three-areas-composition-api.vue
  • examples/sites/demos/pc/app/split/three-areas.vue
  • examples/sites/demos/pc/app/split/top-bottom-slot-composition-api.vue
  • examples/sites/demos/pc/app/split/top-bottom-slot.vue
  • examples/sites/demos/pc/app/split/trigger-simple-composition-api.vue
  • examples/sites/demos/pc/app/split/trigger-simple.vue
  • examples/sites/demos/pc/app/split/trigger-slot-composition-api.vue
  • examples/sites/demos/pc/app/split/trigger-slot.vue
🔇 Additional comments (18)
examples/sites/demos/pc/app/split/split-mode.spec.ts (1)

11-11: Clarification needed: Width comparison adjustment

The assertion for comparing the split element's width with the center button's width has been modified. Previously, it expected the widths to be approximately equal, but now it expects the split element to be 2 units wider than the center button.

Could you please clarify the reason for this adjustment? It's important to verify if this change is intentional and aligns with the component's design specifications.

To ensure this change doesn't introduce unexpected visual regressions, please consider the following:

  1. Review the component's design specifications to confirm if this 2-unit difference is expected.
  2. Visually inspect the rendered component to ensure it appears as intended.
  3. If possible, add a comment explaining the reason for this 2-unit difference to improve code maintainability.
examples/sites/demos/pc/app/split/trigger-simple.spec.ts (1)

19-19: 🛠️ Refactor suggestion

Consider the implications of using exact equality with ceiling values.

The change from toBeCloseTo to toEqual with Math.ceil() makes the assertion more strict. While this might increase accuracy by ensuring exact pixel values, it could potentially make the test more brittle.

Consider the following points:

  1. The new assertion doesn't allow for small floating-point discrepancies, which might occur due to sub-pixel calculations during the drag operation.
  2. Different browsers or systems might have slight variations in rendering, which this strict equality doesn't account for.

To balance accuracy and test stability, consider using toBeCloseTo with a smaller epsilon value:

await expect(afterMove).toBeCloseTo(afterWidth, 0); // Allows for a difference of less than 1

This approach would still catch significant discrepancies while allowing for minor, inconsequential differences.

To ensure this change doesn't introduce flakiness, run the following script to check for any existing uses of toBeCloseTo in similar contexts:

If other split-related tests use toBeCloseTo, it might be worth maintaining consistency across these tests.

packages/theme/src/split/vars.less (3)

13-13: LGTM: Function name and structure are appropriate.

The function name .inject-Split-vars() clearly indicates its purpose, and the use of a Less mixin is a good practice for defining reusable sets of CSS variables.


15-23: LGTM: CSS variable definitions are well-structured and meaningful.

The five CSS variables are appropriately named and assigned values:

  1. --tv-Split-wrapper-border-color
  2. --tv-Split-trigger-icon-line-color
  3. --tv-Split-trigger-icon-line-color-hover
  4. --tv-Split-wrapper-radius-size
  5. --tv-Split-trigger-line-bg-hover

Each variable uses the --tv-Split- prefix for consistency and is assigned a value using another CSS variable, which is a good practice for maintaining a flexible theming system.


13-23: Verify the impact of these changes on the rest of the codebase.

The introduction of .inject-Split-vars() and its new set of variables represents a significant change in the theming approach for the split panel component. While the new variables provide a more focused and potentially more flexible way to style the component, it's important to ensure that these changes don't negatively impact other parts of the codebase.

Please run the following script to check for any potential issues:

This script will help identify:

  1. Any remaining usage of the old split variables
  2. Places where the new .inject-Split-vars() function is being used
  3. Files related to the split component that might need updating

Please review the results and update any affected files accordingly.

✅ Verification successful

Old Split Variables are No Longer in Use

The verification confirms that there is no usage of old split variables in the codebase, and the new .inject-Split-vars() function is properly implemented in the relevant files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of old split variables and the new inject function

# Test 1: Check for usage of old split variables
echo "Checking for usage of old split variables:"
rg --type less '\-\-tv-(split-font-size|split-bg-color|split-line-bg-color|split-btn-wrapper-width|split-btn-wrapper-height)'

# Test 2: Check for usage of the new inject function
echo "Checking for usage of the new inject function:"
rg --type less '\.inject-Split-vars\(\)'

# Test 3: Check for files that might need updating
echo "Files that might need updating:"
rg --type less 'split'

Length of output: 9209

packages/theme/src/split/index.less (13)

21-21: Update mixin to .inject-Split-vars()

Replacing .component-css-vars-split() with .inject-Split-vars() ensures that the Split component uses the latest theming variables, enhancing maintainability and consistency across the theme.


27-28: Utilize CSS variables for wrapper styling

Applying CSS variables for border-radius and border properties (--tv-Split-wrapper-radius-size and --tv-Split-wrapper-border-color) promotes consistency and allows for easier theming.


85-86: Adjust trigger bar dimensions and positioning

Updating the width to 16px and adjusting the transform improves the alignment and click area of the vertical trigger bar.


90-90: Use CSS variable for icon fill color

Replacing hardcoded fill color with var(--tv-Split-trigger-icon-line-color) enhances theming flexibility and consistency.


100-101: Adjust SVG transform and use theme variable for fill

Modifying the SVG transform and utilizing var(--tv-Split-trigger-icon-line-color) for the fill color in the horizontal trigger ensures consistency with the vertical trigger styling.


107-109: Define vertical trigger dimensions and background using variables

Setting width, height, and background with CSS variables ensures the vertical trigger styling is consistent and themeable.


115-115: Use theme variable for trigger bar background

Applying var(--tv-Split-wrapper-border-color) for the trigger bar background maintains consistent theming.


122-122: Set dimensions for horizontal trigger

Defining height and width for the horizontal trigger ensures it aligns with the design specifications.


130-130: Apply theme variable to horizontal trigger bar background

Using var(--tv-Split-wrapper-border-color) for the background improves consistency and theming.


175-175: Update cursor style to not-allowed for disabled triggers

Changing the cursor to not-allowed on disabled trigger controls enhances user experience by clearly indicating non-interactive elements.

Also applies to: 243-243


278-278: Set SVG fill color using theme variable

Using var(--tv-Split-trigger-icon-line-color) for the SVG fill color ensures consistency across themes.


285-285: Set SVG fill color on hover using theme variable

Applying var(--tv-Split-trigger-icon-line-color-hover) for the hover state fill color provides visual feedback consistent with the theme.


319-319: Set trigger line background on hover using theme variable

Using var(--tv-Split-trigger-line-bg-hover) for the background on hover enhances theming and user interaction feedback.

@@ -17,5 +17,5 @@ test('基本用法', async ({ page }) => {
const afterMove = leftPanelWidth + 100 - triggerBtnWidth / 2
const { width: afterWidth } = await leftPanel.boundingBox()
// 小数点后一位相同即可
await expect(afterMove).toBeCloseTo(afterWidth, 1)
await expect(Math.ceil(afterMove)).toEqual(Math.ceil(afterWidth))
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reconsider the assertion change for width comparison

The change from toBeCloseTo to toEqual with Math.ceil might make the test more brittle and less representative of the actual component behavior. Consider the following alternatives:

  1. Retain toBeCloseTo with a small tolerance:

    await expect(afterMove).toBeCloseTo(afterWidth, 1);
  2. If exact equality is required, add a comment explaining why:

    // Exact pixel equality is required for this component
    await expect(Math.round(afterMove)).toEqual(Math.round(afterWidth));
  3. Use a custom matcher with a small absolute tolerance:

    await expect(Math.abs(afterMove - afterWidth)).toBeLessThan(0.5);

These alternatives provide more flexibility and clarity in handling potential floating-point discrepancies.

@@ -13,13 +13,13 @@ test('面板阈值', async ({ page }) => {
await page.mouse.move(x, y - 100)
await page.mouse.up()
const { height: afterHeight } = await topPanel.boundingBox()
await expect(50).toBeCloseTo(afterHeight, 1)
await expect(50).toEqual(Math.ceil(afterHeight))
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider the implications of using exact equality for panel height.

The change from toBeCloseTo to toEqual with Math.ceil makes the test more strict. While this ensures precise behavior, it might lead to brittle tests if there are small variations in panel sizes due to browser rendering differences.

Consider using a small tolerance or range check instead. For example:

const expectedHeight = 50;
await expect(afterHeight).toBeGreaterThanOrEqual(expectedHeight - 1);
await expect(afterHeight).toBeLessThanOrEqual(expectedHeight + 1);

This approach maintains strictness while allowing for minor rendering variations.

await page.waitForTimeout(300)
// 向下滑动时判断下面面板高度是否为80
await triggerBtn.hover()
await page.mouse.down()
await page.mouse.move(x, y + 200)
const { height: bottomMove } = await bottomPanel.boundingBox()
await page.mouse.up()
await expect(80).toBeCloseTo(bottomMove, 1)
await expect(80).toEqual(Math.ceil(bottomMove))
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consistent change in assertion, but consider variable naming.

The change to use toEqual with Math.ceil is consistent with the previous assertion. However, there's a naming issue to address.

  1. The variable bottomMove suggests movement, but it's storing the height. Consider renaming it to bottomHeight for clarity:
const { height: bottomHeight } = await bottomPanel.boundingBox()
await expect(80).toEqual(Math.ceil(bottomHeight))
  1. As mentioned in the previous comment, consider using a tolerance range instead of exact equality to make the test more robust against minor rendering variations.

@@ -18,7 +18,7 @@ test('嵌套使用', async ({ page }) => {
// 移动之后的宽度为:移动之前的宽度+50-分割线宽度的一半
const afterMove = leftWidth + 50 - centerWidth / 2
const { width: afterWidth } = await leftDiv.boundingBox()
await expect(afterMove).toBeCloseTo(afterWidth, 1)
await expect(Math.ceil(afterMove)).toEqual(Math.ceil(afterWidth))
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 the implications of using Math.ceil and toEqual.

The change from toBeCloseTo to Math.ceil and toEqual alters the assertion's behavior:

  1. It makes the test more strict by requiring exact equality after rounding up.
  2. It might catch issues previously masked by floating-point imprecisions.
  3. However, it could make the test more brittle if small variations are expected and acceptable.

Consider the following alternatives:

  1. Use Math.round instead of Math.ceil to handle cases where the value is closer to the lower integer.
  2. Implement a custom matcher that allows for a small tolerance while still using integer comparisons.

Example of a custom matcher:

expect(Math.round(afterMove)).toEqual(expect.closeTo(Math.round(afterWidth), 1));

This approach would maintain integer comparisons while allowing for a small tolerance.

@@ -32,6 +32,5 @@
await page.mouse.up()
const { height: afterHeight } = await topDiv.boundingBox()
const topMove = topHeight - 30 - verticalHeight / 2
await expect(topMove).toBeCloseTo(afterHeight, 1)
await page.waitForTimeout(300)
await expect(Math.ceil(topMove)).toEqual(Math.ceil(afterHeight))
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consistent change, consider generalizing the approach.

The change here is consistent with the previous modification, which is good for maintaining uniformity in the test assertions.

To improve maintainability and reduce duplication, consider:

  1. Creating a custom matcher or helper function for these comparisons. This would centralize the logic and make it easier to adjust in the future.

Example:

function expectRoundedEqual(actual: number, expected: number) {
  expect(Math.round(actual)).toEqual(Math.round(expected));
}

// Usage
expectRoundedEqual(topMove, afterHeight);
  1. If this pattern is used across multiple test files, consider adding it to a shared test utilities file.

This approach would make the tests more readable and easier to maintain, especially if you need to adjust the comparison logic in the future.

Comment on lines +31 to +34
& & {
border-radius: 0;
border: none;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Review nested selector & & for specificity

Using the nested selector & & may increase CSS specificity, which can make overriding styles more difficult. Consider whether this level of specificity is necessary or if there's an alternative approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring (重构)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant