bito-code-review[bot] commented on code in PR #36708:
URL: https://github.com/apache/superset/pull/36708#discussion_r2683522533


##########
superset-frontend/spec/helpers/setup.ts:
##########
@@ -38,3 +38,44 @@ jest.mock('ace-builds/src-min-noconflict/mode-handlebars', 
() => ({}));
 jest.mock('ace-builds/src-min-noconflict/mode-css', () => ({}));
 jest.mock('ace-builds/src-noconflict/theme-github', () => ({}));
 jest.mock('ace-builds/src-noconflict/theme-monokai', () => ({}));
+
+// Mock BroadcastChannel for cross-tab communication tests
+class MockBroadcastChannel {
+  name: string;
+
+  onmessage: ((event: { data: any }) => void) | null = null;
+
+  static instances: MockBroadcastChannel[] = [];
+
+  constructor(name: string) {
+    this.name = name;
+    MockBroadcastChannel.instances.push(this);
+  }
+
+  postMessage(data: any) {
+    // Simulate broadcasting to all channels with the same name
+    MockBroadcastChannel.instances.forEach(instance => {
+      if (instance.name === this.name && instance.onmessage) {
+        instance.onmessage({ data });
+      }
+    });
+  }

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Incorrect mock behavior</b></div>
   <div id="fix">
   
   The mock's postMessage sends messages to all instances including itself, but 
the real BroadcastChannel API does not deliver messages to the sender. This 
could cause incorrect test behavior, such as in useTabId where self-denial 
might occur.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
     postMessage(data: any) {
       // Simulate broadcasting to all channels with the same name
       MockBroadcastChannel.instances.forEach(instance => {
         if (instance !== this && instance.name === this.name && 
instance.onmessage) {
           instance.onmessage({ data });
         }
       });
     }
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #27a650</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to