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: add time-line UI e2e test #47

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions tests/time-line/xdesign.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect, test } from '@playwright/test'

test.describe('tabs 组件xdesign规范', () => {
test('节点状态 --UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('time-line#status')
const demo = page.locator('#status .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('status.png')
})

test('圆点外观 --UI截图', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('time-line#shape')
const demo = page.locator('#shape .pc-demo')
await expect(demo).toBeInViewport()
await expect(demo).toHaveScreenshot('shape.png')
})
Comment on lines +12 to +18
Copy link

Choose a reason for hiding this comment

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

LGTM, but consider refactoring to reduce code duplication.

The test follows the same good practices as the previous test, and the screenshot name aligns with the test name.

However, the test code is almost identical to the previous test, with only the page URL and screenshot name being different. Consider refactoring the common logic into a helper function to reduce code duplication and make the test suite easier to maintain.

Here's a suggested refactor:

async function testUIScreenshot(page, url, selector, screenshotName) {
  page.on('pageerror', (exception) => expect(exception).toBeNull())
  await page.goto(url)
  const demo = page.locator(selector)
  await expect(demo).toBeInViewport()
  await expect(demo).toHaveScreenshot(screenshotName)
}

test.describe('tabs 组件xdesign规范', () => {
  test('节点状态 --UI截图', async ({ page }) => {
    await testUIScreenshot(page, 'time-line#status', '#status .pc-demo', 'status.png')
  })

  test('圆点外观 --UI截图', async ({ page }) => {
    await testUIScreenshot(page, 'time-line#shape', '#shape .pc-demo', 'shape.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.