|
@@ -59,21 +59,9 @@ function forceReactUpdate(element, value) {
|
|
|
const eventSequence = [
|
|
const eventSequence = [
|
|
|
{ type: 'focus', isFocus: true },
|
|
{ type: 'focus', isFocus: true },
|
|
|
{ type: 'focusin', isFocus: true },
|
|
{ type: 'focusin', isFocus: true },
|
|
|
- { type: 'click' },
|
|
|
|
|
{ type: 'mousedown' },
|
|
{ type: 'mousedown' },
|
|
|
{ type: 'mouseup' },
|
|
{ type: 'mouseup' },
|
|
|
- { type: 'keydown', isKey: true, key: ' ' },
|
|
|
|
|
- { type: 'keypress', isKey: true, key: ' ' },
|
|
|
|
|
- {
|
|
|
|
|
- type: 'input',
|
|
|
|
|
- isInput: true,
|
|
|
|
|
- data: String(value),
|
|
|
|
|
- inputType: 'insertText'
|
|
|
|
|
- },
|
|
|
|
|
- { type: 'keyup', isKey: true, key: ' ' },
|
|
|
|
|
- { type: 'change' },
|
|
|
|
|
- { type: 'blur', isFocus: true },
|
|
|
|
|
- { type: 'focusout', isFocus: true }
|
|
|
|
|
|
|
+
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
eventSequence.forEach((eventConfig, index) => {
|
|
eventSequence.forEach((eventConfig, index) => {
|
|
@@ -114,7 +102,6 @@ function forceReactUpdate(element, value) {
|
|
|
Object.defineProperty(event, 'target', { value: element });
|
|
Object.defineProperty(event, 'target', { value: element });
|
|
|
Object.defineProperty(event, 'currentTarget', { value: element });
|
|
Object.defineProperty(event, 'currentTarget', { value: element });
|
|
|
|
|
|
|
|
- console.log(`触发 ${eventConfig.type} 事件`);
|
|
|
|
|
element.dispatchEvent(event);
|
|
element.dispatchEvent(event);
|
|
|
}, index * 20); // 每个事件间隔20ms
|
|
}, index * 20); // 每个事件间隔20ms
|
|
|
});
|
|
});
|
|
@@ -126,20 +113,7 @@ function forceReactUpdate(element, value) {
|
|
|
}, eventSequence.length * 20 + 50);
|
|
}, eventSequence.length * 20 + 50);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 或者使用 React Test Utilities 风格
|
|
|
|
|
-function simulateReactChange(element, value) {
|
|
|
|
|
- element.value = value;
|
|
|
|
|
-
|
|
|
|
|
- // React 16+ 使用这些事件
|
|
|
|
|
- element.dispatchEvent(new Event('input', { bubbles: true }));
|
|
|
|
|
- element.dispatchEvent(new Event('change', { bubbles: true }));
|
|
|
|
|
-
|
|
|
|
|
- // 对于 React 17+
|
|
|
|
|
- element.dispatchEvent(new Event('change', {
|
|
|
|
|
- bubbles: true,
|
|
|
|
|
- composed: true
|
|
|
|
|
- }));
|
|
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
function runJob () {
|
|
function runJob () {
|
|
|
document.querySelectorAll('[aria-label="percentageInput"]').forEach(element => {
|
|
document.querySelectorAll('[aria-label="percentageInput"]').forEach(element => {
|