Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test(e2e): [input,link,popeditor] fix input、link、popeditor error e2e test #2586

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
Dec 2, 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
18 changes: 10 additions & 8 deletions examples/sites/demos/pc/app/input/resize-composition-api.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
<tiny-input type="textarea" v-model="input" resize="both" placeholder="resize = both"></tiny-input>
<tiny-input type="textarea" v-model="input" resize="horizontal" placeholder="resize = horizontal"></tiny-input>
<tiny-input type="textarea" v-model="input" resize="vertical" placeholder="resize = vertical"></tiny-input>
<p>autosize</p>
<tiny-input
type="textarea"
v-model="textarea"
placeholder="autosize = { minRows: 2, maxRows: 3 }"
:autosize="{ minRows: 2, maxRows: 3 }"
></tiny-input>
<tiny-input type="textarea" v-model="textarea" placeholder="autosize" autosize></tiny-input>
<div class="auto-size">
<p>autosize</p>
<tiny-input
type="textarea"
v-model="textarea"
placeholder="autosize = { minRows: 2, maxRows: 3 }"
:autosize="{ minRows: 2, maxRows: 3 }"
></tiny-input>
<tiny-input type="textarea" v-model="textarea" placeholder="autosize" autosize></tiny-input>
</div>
<p>hover-expand</p>
<tiny-input
class="expand"
Expand Down
6 changes: 4 additions & 2 deletions examples/sites/demos/pc/app/input/resize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { test, expect } from '@playwright/test'
test('可缩放文本域', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('input#resize')
const textarea = await page.locator('.demo-input .tiny-textarea > .tiny-textarea-display-only > textarea')

const demo = page.locator('#resize')
const textarea = await demo.locator('.tiny-textarea > .tiny-textarea-display-only > textarea')
await expect(textarea.nth(0)).toHaveCSS('resize', 'vertical')
await expect(textarea.nth(1)).toHaveCSS('resize', 'none')
await expect(textarea.nth(2)).toHaveCSS('resize', 'both')
Expand All @@ -12,7 +14,7 @@ test('可缩放文本域', async ({ page }) => {

const fillText =
'test1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'
const textarea2 = page.locator('.demo-input .tiny-textarea .tiny-textarea-autosize-display-only > textarea')
const textarea2 = demo.locator('.auto-size .tiny-textarea textarea')

// autosize = { minRows: 2, maxRows: 3 } 检查高度
let defaultHeight = await textarea2
Expand Down
18 changes: 10 additions & 8 deletions examples/sites/demos/pc/app/input/resize.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
<tiny-input type="textarea" v-model="input" resize="both" placeholder="resize = both"></tiny-input>
<tiny-input type="textarea" v-model="input" resize="horizontal" placeholder="resize = horizontal"></tiny-input>
<tiny-input type="textarea" v-model="input" resize="vertical" placeholder="resize = vertical"></tiny-input>
<p>autosize</p>
<tiny-input
type="textarea"
v-model="textarea"
placeholder="autosize = { minRows: 2, maxRows: 3 }"
:autosize="{ minRows: 2, maxRows: 3 }"
></tiny-input>
<tiny-input type="textarea" v-model="textarea" placeholder="autosize" autosize></tiny-input>
<div class="auto-size">
<p>autosize</p>
<tiny-input
type="textarea"
v-model="textarea"
placeholder="autosize = { minRows: 2, maxRows: 3 }"
:autosize="{ minRows: 2, maxRows: 3 }"
></tiny-input>
<tiny-input type="textarea" v-model="textarea" placeholder="autosize" autosize></tiny-input>
</div>
<p>hover-expand</p>
<tiny-input
class="expand"
Expand Down
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/app/link/basic-usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ test('基础用法', async ({ page }) => {
const preview = page.locator('#basic-usage')
const link = preview.locator('a')

await expect(link.first()).toHaveText('默认链接')
await expect(link.nth(1)).toHaveText('默认链接2')
await link.first().hover()
await expect(link.first()).toHaveCSS('color', 'rgb(20, 118, 255)')

Expand All @@ -20,5 +18,7 @@ test('基础用法', async ({ page }) => {
})
await link.first().click()

await page.waitForTimeout(100)

Comment on lines +21 to +22
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 using a more robust wait strategy.

Instead of using a fixed timeout, consider waiting for the console event directly. This would make the test more reliable and faster in most cases.

Here's a suggested implementation:

- await page.waitForTimeout(100)
+ // Wait for the console event with a reasonable timeout
+ await expect.poll(() => values[0], {
+   timeout: 2000,
+ }).toBe('clicked')
- expect(values[0]).toBe('clicked')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await page.waitForTimeout(100)
// Wait for the console event with a reasonable timeout
await expect.poll(() => values[0], {
timeout: 2000,
}).toBe('clicked')

expect(values[0]).toBe('clicked')
})
27 changes: 9 additions & 18 deletions examples/sites/demos/pc/app/popeditor/condition-form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,18 @@ test('PopEditor 表单中使用并开启表单校验', async ({ page }) => {
await page.goto('popeditor#condition-form')

const preview = page.locator('#condition-form')
const textBox = preview.getByRole('textbox').nth(2)
const textBoxInput1 = page.getByText('15').nth(1)
const textBoxInput2 = page.getByText('18').nth(1)
const dialogBox = page.locator('div').getByRole('textbox').nth(5)
const del = page
await preview
.locator('div')
.filter({ hasText: /^文本选择确 认取 消$/ })
.getByRole('textbox')
.click()
Comment on lines +8 to +12
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify and make the locator more maintainable.

The current locator chain with text filter is fragile and hard to maintain. Consider using data-testid attributes for more reliable element selection.

Example implementation:

- await preview
-   .locator('div')
-   .filter({ hasText: /^文本选择确 认取 消$/ })
-   .getByRole('textbox')
-   .click()
+ // Add data-testid to the component
+ await preview.getByTestId('text-selector-input').click()

Committable suggestion skipped: line range outside the PR's diff.

await page.getByRole('row', { name: 'GFD科技YX公司 福建 福州' }).locator('path').nth(1).click()
await page.getByRole('button', { name: '确 认' }).click()
await preview
.locator('div')
.filter({ hasText: /^文本$/ })
.getByRole('img')
const confirmBtn = page.getByRole('button', { name: '确 认' })
const dataItem = page.getByRole('row', { name: 'GFD科技YX公司 福建 福州' }).locator('.tiny-grid-radio.size__mini')
.click()
const tooltip = page.getByRole('tooltip', { name: '必填' })

await textBox.click()
await textBoxInput1.click()
await textBoxInput2.click()
await dialogBox.click()
await dataItem.click()
await confirmBtn.click()
await expect(dialogBox).toHaveValue('GFD科技YX公司')

await del.click()
await expect(dialogBox).toHaveValue('')
await expect(tooltip).toBeVisible()
})
Loading