Files
madbase/control-plane-ui/node_modules/@testing-library/user-event/dist/cjs/document/prepareDocument.js
Vlad Durnea cffdf8af86
Some checks failed
CI/CD Pipeline / unit-tests (push) Failing after 1m16s
CI/CD Pipeline / integration-tests (push) Failing after 2m32s
CI/CD Pipeline / lint (push) Successful in 5m22s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped
wip:milestone 0 fixes
2026-03-15 12:35:42 +02:00

59 lines
1.7 KiB
JavaScript

'use strict';
var dispatchEvent = require('../event/dispatchEvent.js');
var isElementType = require('../utils/misc/isElementType.js');
require('../utils/dataTransfer/Clipboard.js');
var UI = require('./UI.js');
require('@testing-library/dom');
var interceptor = require('./interceptor.js');
const isPrepared = Symbol('Node prepared with document state workarounds');
function prepareDocument(document) {
if (document[isPrepared]) {
return;
}
document.addEventListener('focus', (e)=>{
const el = e.target;
prepareElement(el);
}, {
capture: true,
passive: true
});
// Our test environment defaults to `document.body` as `activeElement`.
// In other environments this might be `null` when preparing.
// istanbul ignore else
if (document.activeElement) {
prepareElement(document.activeElement);
}
document.addEventListener('blur', (e)=>{
const el = e.target;
const initialValue = UI.getInitialValue(el);
if (initialValue !== undefined) {
if (el.value !== initialValue) {
dispatchEvent.dispatchDOMEvent(el, 'change');
}
UI.clearInitialValue(el);
}
}, {
capture: true,
passive: true
});
document[isPrepared] = isPrepared;
}
function prepareElement(el) {
if (el[isPrepared]) {
return;
}
if (isElementType.isElementType(el, [
'input',
'textarea'
])) {
interceptor.prepareValueInterceptor(el);
interceptor.prepareSelectionInterceptor(el);
interceptor.prepareRangeTextInterceptor(el);
}
el[isPrepared] = isPrepared;
}
exports.prepareDocument = prepareDocument;