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(button-group): add button-group e2e UI test #60

Merged
merged 1 commit into from
Sep 25, 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
97 changes: 97 additions & 0 deletions tests/button-group/xdesign.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { expect, test } from '@playwright/test'

test.describe('button-group组件xdesign规范', () => {
test('默认--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#basic-usage')
const demo = page.locator('#basic-usage .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('basic-usage.png')

// hover 时截图
const button = demo.getByRole('button', { name: 'Button2' })
await button.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('hover.png')
})

test('组件尺寸大小--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#size')
const demo = page.locator('#size .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('size.png')

// hover 时截图
const button = demo.getByRole('button', { name: 'Button2' }).first()
await button.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('size-hover.png')
})
Comment on lines +18 to +30
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 expanding size variation testing

The test case effectively captures screenshots for different button-group sizes. However, to ensure comprehensive coverage:

Consider capturing hover states for buttons in each size category. This would provide a more thorough visual regression test for all size variations. For example:

const sizes = ['small', 'medium', 'large'];
for (const size of sizes) {
  const button = demo.getByRole('button', { name: 'Button2' }).filter({ hasText: size });
  await button.hover();
  await expect(demo).toHaveScreenshot(`size-${size}-hover.png`);
}


test('禁用状态--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#disabled')
const demo = page.locator('#disabled .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('disabled.png')
})
Comment on lines +32 to +38
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance disabled state testing

The test case captures the visual appearance of disabled buttons, which is good. To improve test coverage:

Consider adding an interaction test to ensure that disabled buttons don't respond to clicks. For example:

const disabledButton = demo.getByRole('button', { name: 'Disabled', disabled: true });
await expect(disabledButton).toBeDisabled();
await disabledButton.click({ force: true });
// Add an assertion here to verify that no action was performed


test('朴素按钮--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#plain')
const demo = page.locator('#plain .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('plain.png')

// hover 时截图
const button = demo.getByRole('button', { name: 'Button2' })
await button.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('plain-hover.png')
})

test('显示更多按钮--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#show-more')
const demo = page.locator('#show-more .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('show-more.png')
})
Comment on lines +54 to +60
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Expand testing for show more button functionality

While the test captures the visual appearance of the show more button, it doesn't verify its functionality.

Consider adding an interaction test to ensure the show more button works correctly:

const showMoreButton = demo.getByRole('button', { name: 'Show More' });
await showMoreButton.click();
// Add assertions to verify that additional content is displayed
await expect(demo).toHaveScreenshot('show-more-expanded.png');


test('编辑按钮--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#show-edit')
const demo = page.locator('#show-edit .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('show-edit.png')
})
Comment on lines +62 to +68
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance edit button testing

The test case captures the visual appearance of the edit button, which is good. To improve test coverage:

  1. Add a hover state test:
const editButton = demo.getByRole('button', { name: 'Edit' });
await editButton.hover();
await expect(demo).toHaveScreenshot('show-edit-hover.png');
  1. Consider adding an interaction test to verify the edit functionality:
await editButton.click();
// Add assertions to verify that the edit mode is activated
await expect(demo).toHaveScreenshot('show-edit-active.png');


test('多行按钮组--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#button-group-multiple')
const demo = page.locator('#button-group-multiple .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('button-group-multiple.png')

// hover 时截图
const button = demo.getByRole('button', { name: 'Button02' })
await button.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('multiple-hover.png')
})

test('选块角标--UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('button-group#sup')
const demo = page.locator('#sup .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('sup.png')

// hover 时截图
const button = demo.getByRole('button', { name: '图标' }).nth(1)
await button.hover()
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('sup-hover.png')
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.