-
Notifications
You must be signed in to change notification settings - Fork 319
refactor(split): [split] refactor split theme #2194
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider the implications of using The change from
Consider the following alternatives:
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. |
||
|
||
// 测试左面板中的上下面板 | ||
const centerBtn1 = page.locator('.tiny-split-trigger-horizontal') | ||
|
@@ -32,6 +32,5 @@ test('嵌套使用', async ({ page }) => { | |
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Example: function expectRoundedEqual(actual: number, expected: number) {
expect(Math.round(actual)).toEqual(Math.round(expected));
}
// Usage
expectRoundedEqual(topMove, afterHeight);
This approach would make the tests more readable and easier to maintain, especially if you need to adjust the comparison logic in the future. |
||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider the implications of using exact equality for panel height. The change from 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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistent change in assertion, but consider variable naming. The change to use
const { height: bottomHeight } = await bottomPanel.boundingBox()
await expect(80).toEqual(Math.ceil(bottomHeight))
|
||
}) |
There was a problem hiding this comment.
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
totoEqual
withMath.ceil
might make the test more brittle and less representative of the actual component behavior. Consider the following alternatives:Retain
toBeCloseTo
with a small tolerance:If exact equality is required, add a comment explaining why:
Use a custom matcher with a small absolute tolerance:
These alternatives provide more flexibility and clarity in handling potential floating-point discrepancies.