Skip to content

Commit 96e086c

Browse files
authored
docs(cn): update api/browser/interactivity.md (#1035)
1 parent 72de71d commit 96e086c

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

‎api/advanced/artifacts.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
outline: deep
33
title: Test Artifacts
44
---
5-
5+
<!-- TODO: translation -->
66
# Test Artifacts <Advanced /> <Version type="experimental">4.0.11</Version> <Experimental />
77

88
::: warning

‎api/advanced/vitest.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Vitest API
77

88
## mode <Deprecated /> {#mode}
99

10-
Since Vitest 5, this property is always `'test'`.
10+
自 Vitest 5 起,该属性始终为 `'test'`。
1111

1212
## config
1313

‎api/browser/interactivity.md‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ await originalUserEvent.keyboard('{/Shift}') // 没有放开 shift 键,因为
4141
:::
4242

4343
::: warning
44-
With `playwright` and `webdriverio` providers, interactions are performed by the underlying browser driver. That means some interaction state, like pressed keys or pointer position and the resulting hover state, can persist between tests in the same file.
44+
使用 `playwright` 和 `webdriverio` provider 时,交互由底层浏览器 provider 执行。这意味着同一文件中的测试之间可能会保留某些交互状态,例如按下的按键、指针位置以及由此产生的悬停状态。
4545

46-
Vitest resets unreleased keyboard state automatically before starting each test case, but pointer position and the resulting hover state are not reset automatically since resetting pointer position can be expensive.
46+
Vitest 会在每个测试用例开始前自动重置尚未释放的键盘状态,但不会自动重置指针位置及由此产生的悬停状态,这是因为重置指针位置的开销可能很大。
4747

48-
This applies both to `userEvent.*` calls and locator shortcuts like `locator.click()` or `locator.hover()`, because they use the same underlying interaction state.
48+
这一点既适用于 `userEvent.*` 调用,也适用于 `locator.click()` 或 `locator.hover()` 等定位器方法,因为它们使用相同的底层交互状态。
4949

50-
If your tests depend on a neutral hover state, reset it explicitly, for example in `beforeEach`:
50+
如果测试依赖于无元素被悬停的状态,请显式重置该状态,例如在 `beforeEach` 中进行重置:
5151

5252
```ts
5353
import { beforeEach } from 'vitest'
@@ -57,6 +57,7 @@ beforeEach(async () => {
5757
await userEvent.unhover(document.body)
5858
})
5959
```
60+
6061
:::
6162

6263
## userEvent.click
@@ -106,7 +107,7 @@ await userEvent.keyboard('{/Shift}')
106107
await userEvent.click(element, { modifiers: ['Shift'] })
107108
```
108109

109-
References:
110+
相关链接:
110111

111112
- [Playwright `locator.click` API](https://playwright.dev/docs/api/class-locator#locator-click)
112113
- [WebdriverIO `element.click` API](https://webdriver.io/docs/api/element/click/)
@@ -191,38 +192,38 @@ function wheel(
191192
): Promise<void>
192193
```
193194

194-
Triggers a [`wheel` event](https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event) on an element.
195+
在元素上触发 [`wheel` 事件](https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event)。
195196

196-
You can specify the scroll amount using either `delta` for precise pixel-based control, or `direction` for simpler directional scrolling (`up`, `down`, `left`, `right`). When you need to trigger multiple wheel events, use the `times` option rather than calling the method multiple times for better performance.
197+
你可以使用 `delta` 指定滚动量,以像素为单位进行精确控制;也可以使用 `direction` 进行更简单的定向滚动(`up`、`down`、`left`、`right`)。需要触发多次滚轮事件时,请使用 `times` 选项获得更好的性能,而不是多次调用此方法。
197198

198199
```ts
199200
import { page, userEvent } from 'vitest/browser'
200201
201202
test('scroll using delta values', async () => {
202203
const tablist = page.getByRole('tablist')
203204
204-
// Scroll right by 100 pixels
205+
// 向右滚动 100 像素
205206
await userEvent.wheel(tablist, { delta: { x: 100 } })
206207
207-
// Scroll down by 50 pixels
208+
// 向下滚动 50 像素
208209
await userEvent.wheel(tablist, { delta: { y: 50 } })
209210
210-
// Scroll diagonally 2 times
211+
// 沿对角线滚动 2 次
211212
await userEvent.wheel(tablist, { delta: { x: 50, y: 100 }, times: 2 })
212213
})
213214
214215
test('scroll using direction', async () => {
215216
const tablist = page.getByRole('tablist')
216217
217-
// Scroll right 5 times
218+
// 向右滚动 5 次
218219
await userEvent.wheel(tablist, { direction: 'right', times: 5 })
219220
220-
// Scroll left once
221+
// 向左滚动 1 次
221222
await userEvent.wheel(tablist, { direction: 'left' })
222223
})
223224
```
224225

225-
Wheel events can also be triggered directly from [locators](/api/browser/locators#wheel):
226+
也可以直接通过 [定位器](/api/browser/locators#wheel) 触发滚轮事件:
226227

227228
```ts
228229
import { page } from 'vitest/browser'
@@ -231,7 +232,7 @@ await page.getByRole('tablist').wheel({ direction: 'right' })
231232
```
232233

233234
::: warning
234-
This method is intended for testing UI that explicitly listens to `wheel` events (e.g., custom zoom controls, horizontal tab scrolling, canvas interactions). If you need to scroll the page to bring an element into view, rely on the built-in automatic scrolling functionality provided by other `userEvent` methods or [locator actions](/api/browser/locators#methods) instead.
235+
此方法用于测试显式监听 `wheel` 事件的 UI(例如自定义缩放控制、水平滚动标签页或 canvas 交互)。如果需要滚动页面以使元素进入视口,请改用其他 `userEvent` 方法或 [定位器操作](/api/browser/locators#methods) 提供的内置自动滚动功能。
235236
:::
236237

237238
## userEvent.fill

0 commit comments

Comments
 (0)