MCPcopy Create free account
hub / github.com/GCWing/BitFun / installReactTrackedInput

Function installReactTrackedInput

tests/e2e/specs/l0-webdriver-protocol.spec.ts:38–81  ·  view source on GitHub ↗
(id: string, initialValue: string)

Source from the content-addressed store, hash-verified

36}
37
38async function installReactTrackedInput(id: string, initialValue: string): Promise<void> {
39 await browser.execute(({ inputId, value }) => {
40 let input = document.getElementById(inputId) as HTMLInputElement | null;
41 if (!input) {
42 input = document.createElement('input');
43 input.id = inputId;
44 input.style.position = 'fixed';
45 input.style.left = '24px';
46 input.style.top = '196px';
47 document.body.appendChild(input);
48 }
49
50 const proto = Object.getPrototypeOf(input) as HTMLInputElement;
51 const descriptor = Object.getOwnPropertyDescriptor(proto, 'value');
52 if (!descriptor?.get || !descriptor?.set) {
53 throw new Error('Missing native value descriptor');
54 }
55
56 const tracker = { currentValue: value, syntheticChanges: 0 };
57 Object.defineProperty(input, 'value', {
58 configurable: true,
59 get() {
60 return descriptor.get!.call(this);
61 },
62 set(next: string) {
63 tracker.currentValue = String(next);
64 descriptor.set!.call(this, next);
65 },
66 });
67
68 descriptor.set.call(input, value);
69 input.focus();
70 input.setSelectionRange(value.length, value.length);
71 (window as typeof window & { __wdReactTracker?: typeof tracker }).__wdReactTracker = tracker;
72
73 input.oninput = () => {
74 const liveValue = descriptor.get!.call(input!);
75 if (liveValue !== tracker.currentValue) {
76 tracker.syntheticChanges += 1;
77 tracker.currentValue = liveValue;
78 }
79 };
80 }, { inputId: id, value: initialValue });
81}
82
83describe('L0 Embedded WebDriver Protocol', () => {
84 it('supports alert lifecycle endpoints', async () => {

Callers 1

Calls 3

executeMethod · 0.65
focusMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected