From e4e91c9c9ebb6763a74346d4a853885a486d38e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A4=A9=E4=BD=91?= <66231260+You-Hw-Y@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:28:38 +0800 Subject: [PATCH] fix(test): [date-picker] update e2e test (#1453) * fix(test): [date-picker] update e2e test * fix(test): [date-picker] update e2e test * fix(test): [user-link] update e2e test --- .../demos/pc/app/date-picker/align.spec.ts | 31 ++++++++++--------- .../demos/pc/app/date-picker/clear.spec.ts | 2 +- .../pc/app/hrapprover/custom-service.spec.ts | 7 +++-- .../demos/pc/app/hrapprover/disabled.spec.ts | 2 +- .../pc/app/user-link/custom-service.spec.ts | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/sites/demos/pc/app/date-picker/align.spec.ts b/examples/sites/demos/pc/app/date-picker/align.spec.ts index acad35712..d949f7716 100644 --- a/examples/sites/demos/pc/app/date-picker/align.spec.ts +++ b/examples/sites/demos/pc/app/date-picker/align.spec.ts @@ -6,28 +6,31 @@ test('[DatePicker] 测试对齐方式', async ({ page }) => { // 左对齐 const leftDateInputDom = page.getByRole('textbox').nth(1) - const leftDatePanelDom = page.locator('body > div:nth-child(8)') + const leftDatePanelDom = page.locator('.tiny-picker-panel').nth(2) + const leftClosePanel = page.getByText('左对齐:') - const { x: leftDateInputX } = await leftDateInputDom.boundingBox() await leftDateInputDom.click() - const { x: leftDatePanelX } = await leftDatePanelDom.boundingBox() - expect(leftDateInputX - leftDatePanelX).toBeCloseTo(0) + await page.waitForTimeout(200) + await expect(leftDatePanelDom).toHaveAttribute('x-placement', /bottom-start|top-start/) + await leftClosePanel.click() // 居中对齐 const centerDateInputDom = page.getByRole('textbox').nth(2) - const centerDatePanelDom = page.locator('body > div:nth-child(9)') - const { x: centerDateInputX, width: centerDateInputWidth } = await centerDateInputDom.boundingBox() + const centerDatePanelDom = page.locator('.tiny-picker-panel').nth(2) + const centerClosePanel = page.getByText('居中对齐:') + await centerDateInputDom.click() - const { x: centerDatePanelX, width: centerDatePanelWidth } = await centerDatePanelDom.boundingBox() - expect( - centerDateInputX + Math.round(centerDateInputWidth / 2) - centerDatePanelX - Math.round(centerDatePanelWidth / 2) - ).toBeCloseTo(0) + await page.waitForTimeout(200) + await expect(centerDatePanelDom).toHaveAttribute('x-placement', /bottom|top/) + await centerClosePanel.click() // 右对齐 const rightDateInputDom = page.getByRole('textbox').nth(3) - const rightDatePanelDom = page.locator('body > div:nth-child(10)') - const { x: rightDateInputX, width: rightDateInputWidth } = await rightDateInputDom.boundingBox() + const rightDatePanelDom = page.locator('.tiny-picker-panel').nth(2) + const rightClosePanel = page.getByText('右对齐:') + await rightDateInputDom.click() - const { x: rightDatePanelX, width: rightDatePanelWidth } = await rightDatePanelDom.boundingBox() - expect(rightDateInputX + rightDateInputWidth - rightDatePanelX - rightDatePanelWidth).toBeCloseTo(0) + await page.waitForTimeout(200) + await expect(rightDatePanelDom).toHaveAttribute('x-placement', /bottom-end|top-end/) + await rightClosePanel.click() }) diff --git a/examples/sites/demos/pc/app/date-picker/clear.spec.ts b/examples/sites/demos/pc/app/date-picker/clear.spec.ts index 297dacfb5..5ecca1085 100644 --- a/examples/sites/demos/pc/app/date-picker/clear.spec.ts +++ b/examples/sites/demos/pc/app/date-picker/clear.spec.ts @@ -31,6 +31,6 @@ test('[DatePicker] 测试清除输入', async ({ page }) => { // 测试清除功能 await expect(datePickerCustomClearIcon).toHaveValue('2023-05-24') - await page.locator('.tiny-input__icon-container > svg > .st0').click() + await page.locator('#clear').getByRole('img').nth(2).click() await expect(datePickerCustomClearIcon).toHaveValue('') }) diff --git a/examples/sites/demos/pc/app/hrapprover/custom-service.spec.ts b/examples/sites/demos/pc/app/hrapprover/custom-service.spec.ts index 06fa27e6f..e8fe15ff9 100644 --- a/examples/sites/demos/pc/app/hrapprover/custom-service.spec.ts +++ b/examples/sites/demos/pc/app/hrapprover/custom-service.spec.ts @@ -2,6 +2,9 @@ import { test, expect } from '@playwright/test' test('自定义服务', async ({ page }) => { await page.goto('hrapprover#custom-service') - await page.locator('#preview').getByRole('img').nth(1).click() - await expect(page.getByText('已选权签人备注 test1 test2权限申请 test3资产申请')).toBeVisible() + await page.locator('#custom-service').getByRole('img').click() + await page.waitForTimeout(200) + await expect(page.getByRole('cell', { name: 'test1' })).toBeVisible() + await expect(page.getByRole('cell', { name: 'test2' })).toBeVisible() + await expect(page.getByRole('cell', { name: 'test3' })).toBeVisible() }) diff --git a/examples/sites/demos/pc/app/hrapprover/disabled.spec.ts b/examples/sites/demos/pc/app/hrapprover/disabled.spec.ts index 40001b750..5e1992c9d 100644 --- a/examples/sites/demos/pc/app/hrapprover/disabled.spec.ts +++ b/examples/sites/demos/pc/app/hrapprover/disabled.spec.ts @@ -4,5 +4,5 @@ test('禁用', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('hrapprover#disabled') await page.getByRole('button', { name: '启用/禁用' }).click() - await expect(page.locator('.tiny-hrapprover > .is-disabled > input')).toHaveAttribute('disabled', '') + await expect(page.locator('#disabled').getByRole('textbox')).toHaveAttribute('disabled', '') }) diff --git a/examples/sites/demos/pc/app/user-link/custom-service.spec.ts b/examples/sites/demos/pc/app/user-link/custom-service.spec.ts index 64dc87e04..b16e8228f 100644 --- a/examples/sites/demos/pc/app/user-link/custom-service.spec.ts +++ b/examples/sites/demos/pc/app/user-link/custom-service.spec.ts @@ -3,7 +3,7 @@ import { test, expect } from '@playwright/test' test('user-link-custom-service', async ({ page }) => { await page.goto('user-link#custom-service') const card = page.locator('.tiny-popper.tiny-user-card') - const reference = page.locator('#preview .tiny-userlink .tiny-popover__reference') + const reference = page.locator('.reference-wrapper') const img = card.locator('.card-top-img img') await expect(reference).toHaveText('test3')