Skip to content

Commit fcfafbc

Browse files
committed
chore: Revert unrelated formatting to keep PR diff minimal
1 parent d17b333 commit fcfafbc

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

js/__tests__/search_widget_fix.test.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,8 @@ describe("Search Widget Listener Fix", () => {
136136
activity.turtleBlocksScale = 1;
137137

138138
// Fresh mocks for each instance
139-
activity.addEventListener = jest.fn(function (target, type, listener) {
140-
if (target && target.addEventListener) {
141-
target.addEventListener(type, listener);
142-
}
143-
if (!this._listeners) this._listeners = [];
144-
this._listeners.push({ target, type, listener });
145-
});
146-
activity.removeEventListener = jest.fn(function (target, type, listener) {
147-
if (target && target.removeEventListener) {
148-
target.removeEventListener(type, listener);
149-
}
150-
});
139+
activity = new Activity();
140+
activity.turtleBlocksScale = 1;
151141

152142
// Re-inject mocks that might be overwritten or needed
153143
activity.searchWidget = sandbox.document.getElementById("search");
@@ -167,35 +157,35 @@ describe("Search Widget Listener Fix", () => {
167157
throw e;
168158
}
169159

170-
const addCalls = activity.addEventListener.mock.calls.filter(c => c[1] === "mousedown");
160+
const addCalls = sandbox.document.addEventListener.mock.calls.filter(c => c[0] === "mousedown");
171161
expect(addCalls.length).toBe(1);
172162
});
173163

174164
test("showSearchWidget should NOT accumulate listeners when toggled", () => {
175165
activity.showSearchWidget(); // Toggles ON
176-
expect(activity.addEventListener.mock.calls.filter(c => c[1] === "mousedown").length).toBe(1);
166+
expect(sandbox.document.addEventListener.mock.calls.filter(c => c[0] === "mousedown").length).toBe(1);
177167

178168
activity.showSearchWidget(); // Toggles OFF
179169

180-
expect(activity.removeEventListener.mock.calls.filter(c => c[1] === "mousedown").length).toBe(1);
170+
expect(sandbox.document.removeEventListener.mock.calls.filter(c => c[0] === "mousedown").length).toBe(1);
181171
// addEventListener should NOT have been called again during toggle OFF
182-
expect(activity.addEventListener.mock.calls.filter(c => c[1] === "mousedown").length).toBe(1);
172+
expect(sandbox.document.addEventListener.mock.calls.filter(c => c[0] === "mousedown").length).toBe(1);
183173
});
184174

185-
test("hideSearchWidget should remove the listener via wrapper", () => {
175+
test("hideSearchWidget should remove the listener", () => {
186176
activity.showSearchWidget();
187177

188178
// Capture the listener added
189-
const listener = activity.addEventListener.mock.calls.find(c => c[1] === "mousedown")[2];
179+
const listener = sandbox.document.addEventListener.mock.calls.find(c => c[0] === "mousedown")[1];
190180

191181
activity.hideSearchWidget();
192182

193-
expect(activity.removeEventListener).toHaveBeenCalledWith(sandbox.document, "mousedown", listener);
183+
expect(sandbox.document.removeEventListener).toHaveBeenCalledWith("mousedown", listener);
194184
});
195185

196186
test("clicking inside search should NOT remove listener", () => {
197187
activity.showSearchWidget();
198-
const listener = activity.addEventListener.mock.calls.find(c => c[1] === "mousedown")[2];
188+
const listener = sandbox.document.addEventListener.mock.calls.find(c => c[0] === "mousedown")[1];
199189

200190
const searchElem = activity.searchWidget;
201191
searchElem.style.visibility = "visible";
@@ -207,20 +197,20 @@ describe("Search Widget Listener Fix", () => {
207197
searchElem.contains.mockImplementation(target => target === searchElem);
208198

209199
// Verify removeEventListener was NOT called for this listener
210-
const removeCalls = activity.removeEventListener.mock.calls.filter(c => c[2] === listener);
200+
const removeCalls = sandbox.document.removeEventListener.mock.calls.filter(c => c[1] === listener);
211201
expect(removeCalls.length).toBe(0);
212202
});
213203

214204
test("clicking outside search SHOULD remove listener and hide widget", () => {
215205
activity.showSearchWidget();
216-
const listener = activity.addEventListener.mock.calls.find(c => c[1] === "mousedown")[2];
206+
const listener = sandbox.document.addEventListener.mock.calls.find(c => c[0] === "mousedown")[1];
217207
const hideSpy = jest.spyOn(activity, "hideSearchWidget");
218208

219209
// Clicked outside
220210
listener({ target: {} });
221211

222212
expect(hideSpy).toHaveBeenCalled();
223-
expect(activity.removeEventListener).toHaveBeenCalledWith(sandbox.document, "mousedown", listener);
213+
expect(sandbox.document.removeEventListener).toHaveBeenCalledWith("mousedown", listener);
224214
hideSpy.mockRestore();
225215
});
226216
});

js/activity.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ class Activity {
581581
if (this.helpfulSearchDiv && this.helpfulSearchDiv.parentNode) {
582582
this.helpfulSearchDiv.parentNode.removeChild(this.helpfulSearchDiv);
583583
}
584-
this.__tick();
584+
that.__tick();
585585
};
586586

587587
/*
@@ -3164,9 +3164,8 @@ class Activity {
31643164
this.searchWidget.style.visibility = "hidden";
31653165
this.searchWidget.idInput_custom = "";
31663166

3167-
// clean up listener
31683167
if (this._searchCloseListener) {
3169-
this.removeEventListener(document, "mousedown", this._searchCloseListener);
3168+
document.removeEventListener("mousedown", this._searchCloseListener);
31703169
this._searchCloseListener = null;
31713170
}
31723171
};
@@ -3199,40 +3198,40 @@ class Activity {
31993198
this.searchBlockPosition = [100, 100];
32003199
this.prepSearchWidget();
32013200

3201+
const that = this;
32023202
const closeListener = e => {
32033203
if (
32043204
document.getElementById("search").style.visibility === "visible" &&
32053205
(e.target === document.getElementById("search") ||
32063206
document.getElementById("search").contains(e.target))
32073207
) {
3208-
// do nothing in input field
3208+
//do nothing when clicked in the input field
32093209
} else if (
32103210
document.getElementById("ui-id-1") &&
32113211
document.getElementById("ui-id-1").style.display === "block" &&
32123212
(e.target === document.getElementById("ui-id-1") ||
32133213
document.getElementById("ui-id-1").contains(e.target))
32143214
) {
3215-
// do nothing on menu
3215+
//do nothing when clicked on the menu
32163216
} else if (document.getElementsByTagName("tr")[2].contains(e.target)) {
3217-
// do nothing on search row
3217+
//do nothing when clicked on the search row
32183218
} else {
3219-
// hide search bar if someone clicks on menu items
3220-
this.hideSearchWidget();
3219+
// this will hide the search bar if someone clicks on menu items
3220+
that.hideSearchWidget();
32213221
}
32223222
};
32233223

3224-
// remove previous listener
32253224
if (this._searchCloseListener) {
3226-
this.removeEventListener(document, "mousedown", this._searchCloseListener);
3225+
document.removeEventListener("mousedown", this._searchCloseListener);
32273226
}
32283227
this._searchCloseListener = closeListener;
3229-
this.addEventListener(document, "mousedown", closeListener);
3228+
document.addEventListener("mousedown", closeListener);
32303229

32313230
// Give the browser time to update before selecting
32323231
// focus.
32333232
setTimeout(() => {
3234-
this.searchWidget.focus();
3235-
this.doSearch();
3233+
that.searchWidget.focus();
3234+
that.doSearch();
32363235
}, 500);
32373236
}
32383237
};

0 commit comments

Comments
 (0)