MCPcopy Create free account
hub / github.com/testing-library/user-event / pointerAction

Function pointerAction

src/pointer/index.ts:67–111  ·  view source on GitHub ↗
(instance: Instance, action: PointerAction)

Source from the content-addressed store, hash-verified

65}
66
67async function pointerAction(instance: Instance, action: PointerAction) {
68 const pointerName =
69 'pointerName' in action && action.pointerName
70 ? action.pointerName
71 : 'keyDef' in action
72 ? instance.system.pointer.getPointerName(action.keyDef)
73 : 'mouse'
74
75 const previousPosition =
76 instance.system.pointer.getPreviousPosition(pointerName)
77 const position: PointerPosition = {
78 target: action.target ?? getPrevTarget(instance, previousPosition),
79 coords: action.coords ?? previousPosition?.coords,
80 caret: {
81 node:
82 action.node ??
83 (hasCaretPosition(action) ? undefined : previousPosition?.caret?.node),
84 offset:
85 action.offset ??
86 (hasCaretPosition(action)
87 ? undefined
88 : previousPosition?.caret?.offset),
89 },
90 }
91
92 if ('keyDef' in action) {
93 if (instance.system.pointer.isKeyPressed(action.keyDef)) {
94 setLevelRef(instance, ApiLevel.Trigger)
95 await instance.system.pointer.release(instance, action.keyDef, position)
96 }
97
98 if (!action.releasePrevious) {
99 setLevelRef(instance, ApiLevel.Trigger)
100 await instance.system.pointer.press(instance, action.keyDef, position)
101
102 if (action.releaseSelf) {
103 setLevelRef(instance, ApiLevel.Trigger)
104 await instance.system.pointer.release(instance, action.keyDef, position)
105 }
106 }
107 } else {
108 setLevelRef(instance, ApiLevel.Trigger)
109 await instance.system.pointer.move(instance, pointerName, position)
110 }
111}
112
113function hasCaretPosition(action: PointerAction) {
114 return !!(action.target ?? action.node ?? action.offset !== undefined)

Callers 1

pointerFunction · 0.85

Calls 9

setLevelRefFunction · 0.90
getPrevTargetFunction · 0.85
hasCaretPositionFunction · 0.85
getPointerNameMethod · 0.80
getPreviousPositionMethod · 0.80
pressMethod · 0.80
isKeyPressedMethod · 0.45
releaseMethod · 0.45
moveMethod · 0.45

Tested by

no test coverage detected