Skip to content

test(site): fix icon not correct test e2e #2445

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

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/sites/demos/pc/app/action-menu/basic-usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ test('基本用法', async ({ page }) => {
// 更多按钮
await expect(moreItem).toHaveText(/更多/)
// 图标显示
await expect(moreItem.locator('svg > path').nth(0)).toHaveAttribute(
'd',
'M8 11.43c-.15 0-.31-.06-.42-.18L1.92 5.6c-.23-.23-.23-.61 0-.85s.61-.23.85 0L8 9.98l5.23-5.23a.61.61 0 0 1 .85 0c.23.23.23.61 0 .85l-5.66 5.66c-.11.11-.27.17-.42.17z'
)
await expect(moreItem.locator('.tiny-dropdown__trigger .tiny-svg')).toBeVisible()
// 分割线
await expect(actionMenu.locator('.tiny-action-menu__item-line')).toHaveCount(2)
// 图标旋转
Expand Down
3 changes: 2 additions & 1 deletion examples/sites/demos/pc/app/action-menu/card-mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ test('基本用法', async ({ page }) => {
await expect(visibleItem).toHaveCount(4)
await expect(moreItem).not.toHaveText(/更多/)
// 三点图标
await expect(moreItem.locator('circle')).toHaveCount(3)
const SvgPathReg = /^M2\.3 7\.78v.+219-1\.17Z$/
await expect(moreItem.locator('.tiny-svg path').first()).toHaveAttribute('d', SvgPathReg)
Comment on lines +15 to +16
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 making the SVG validation more resilient.

The current regex pattern with .+ is quite permissive and the hard-coded values might make the test brittle to minor UI changes. Consider focusing on essential characteristics of the SVG that indicate it's a "more" icon.

-const SvgPathReg = /^M2\.3 7\.78v.+219-1\.17Z$/
-await expect(moreItem.locator('.tiny-svg path').first()).toHaveAttribute('d', SvgPathReg)
+// Validate that the SVG represents a "more" icon by checking for essential path characteristics
+const isMoreIconPath = (path: string) => {
+  // Check if path starts with M and ends with Z (closed path)
+  return /^M.*Z$/.test(path);
+}
+const pathAttr = await moreItem.locator('.tiny-svg path').first().getAttribute('d');
+expect(isMoreIconPath(pathAttr || '')).toBeTruthy();

Committable suggestion was skipped due to low confidence.

})
2 changes: 1 addition & 1 deletion examples/sites/demos/pc/app/action-menu/icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('只显示文本', async ({ page }) => {
await page.goto('action-menu#icon')

const wrap = page.locator('#icon')
const actionMenu = wrap.locator('.tiny-action-menu').nth(2)
const actionMenu = wrap.locator('.tiny-action-menu').nth(1)
const actionMenuItem = actionMenu.locator('.tiny-action-menu__item')

await expect(actionMenuItem.nth(0).locator('.tiny-svg')).toBeHidden()
Expand Down
2 changes: 1 addition & 1 deletion examples/sites/demos/pc/app/button-group/show-more.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ test('测试更多按钮', async ({ page }) => {
// 判断图标是否正确
const moreButton = buttonGroup.getByRole('button').nth(3)
const moreButtonSvg = moreButton.locator('svg path').first()
const moreSvgPathReg = /^M292\.768 449\.694c2\.491\.515.+002-12.555-\.002z$/
const moreSvgPathReg = /^M2\.3 7\.78v.+219-1\.17Z$/
await expect(moreButtonSvg).toHaveAttribute('d', moreSvgPathReg)
})
10 changes: 2 additions & 8 deletions examples/sites/demos/pc/app/date-picker/clear.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ test('[DatePicker] 测试清除输入', async ({ page }) => {
// 默认显示清除按钮
await datePickerDefaultClearIcon.hover()
await expect(clearIcon).toBeVisible()
await expect(clearIcon.locator('path').nth(1)).toHaveAttribute(
'd',
'M4.25 3.4 8 7.15l3.75-3.75a.61.61 0 0 1 .85 0c.23.23.23.62 0 .85L8.85 8l3.75 3.75c.23.24.23.62 0 .85a.61.61 0 0 1-.85 0L8 8.85 4.25 12.6a.61.61 0 0 1-.85 0 .592.592 0 0 1 0-.85L7.15 8 3.4 4.25a.61.61 0 0 1 0-.85.61.61 0 0 1 .85 0z'
)
await expect(clearIcon.locator('path').nth(0)).toHaveAttribute('d', /^M12\.49 3\.3a.+22\.71 0Z$/)

// 隐藏清除按钮
await datePickerHideClearIcon.hover()
Expand All @@ -24,10 +21,7 @@ test('[DatePicker] 测试清除输入', async ({ page }) => {
// 自定义清除图标
await datePickerCustomClearIcon.hover()
await expect(clearIcon).toBeVisible()
await expect(clearIcon.locator('path').nth(1)).toHaveAttribute(
'd',
'M4.25 3.4 8 7.15l3.75-3.75a.61.61 0 0 1 .85 0c.23.23.23.62 0 .85L8.85 8l3.75 3.75c.23.24.23.62 0 .85a.61.61 0 0 1-.85 0L8 8.85 4.25 12.6a.61.61 0 0 1-.85 0 .592.592 0 0 1 0-.85L7.15 8 3.4 4.25a.61.61 0 0 1 0-.85.61.61 0 0 1 .85 0z'
)
await expect(clearIcon.locator('path').nth(0)).toHaveAttribute('d', /^M12\.49 3\.3a.+22\.71 0Z$/)

// 测试清除功能
await expect(datePickerCustomClearIcon).toHaveValue('2023-05-24')
Expand Down
4 changes: 0 additions & 4 deletions examples/sites/demos/pc/app/dropdown/basic-usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ test('基本用法', async ({ page }) => {

// 箭头是否存在
await expect(dropDownSvg).toBeVisible()
await expect(dropDownSvg.locator('path')).toHaveAttribute(
'd',
'M8 11.43c-.15 0-.31-.06-.42-.18L1.92 5.6c-.23-.23-.23-.61 0-.85s.61-.23.85 0L8 9.98l5.23-5.23a.61.61 0 0 1 .85 0c.23.23.23.61 0 .85l-5.66 5.66c-.11.11-.27.17-.42.17z'
)

await page.waitForTimeout(500)
await dropDown.hover()
Expand Down
Loading