codeant-ai-for-open-source[bot] commented on code in PR #40525:
URL: https://github.com/apache/superset/pull/40525#discussion_r3325193003
##########
superset-frontend/src/features/alerts/AlertReportModal.test.tsx:
##########
@@ -678,6 +678,56 @@ test('removes ignore cache checkbox when chart is
selected', async () => {
).not.toBeInTheDocument();
});
+test('open chart button opens explore with slice_id', async () => {
+ // Render with an existing alert that has a chart selected
+ render(<AlertReportModal {...generateMockedProps(false, true, false)} />, {
+ useRedux: true,
+ });
+ userEvent.click(screen.getByTestId('contents-panel'));
+
+ // Ensure chart is present
+ await screen.findByText(/test chart/i);
+
+ const openChartButton = screen.getByRole('button', {
+ name: /open chart in new tab/i,
+ });
+ expect(openChartButton).toBeInTheDocument();
+
+ const origOpen = window.open;
+ // @ts-ignore
+ window.open = jest.fn();
+ await userEvent.click(openChartButton);
+ expect(window.open).toHaveBeenCalledWith('/explore/?slice_id=1', '_blank',
'noopener');
+ // restore
+ // @ts-ignore
+ window.open = origOpen;
Review Comment:
**Suggestion:** The test overrides `window.open` directly and restores it
only at the end of the happy path; if any assertion throws before the restore
line, the global stays mocked and can break unrelated tests. Use a spy with
automatic restoration (or `try/finally`) so cleanup always runs. [missing
cleanup]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ AlertReportModal tests share polluted global window.open mock.
- ⚠️ Subsequent tests may fail with misleading window.open behavior.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Run the frontend Jest test suite so that
`superset-frontend/src/features/alerts/AlertReportModal.test.tsx` is
executed, focusing on
`test('open chart button opens explore with slice_id', async () => ...)` at
lines 22–45
from the Read output.
2. In this test, note that at lines 37–44 it executes `const origOpen =
window.open;
window.open = jest.fn(); ... // restore ... window.open = origOpen;` without
any
`try/finally` or `afterEach` guard.
3. Force this test to fail after `window.open` is reassigned but before the
restore, for
example by modifying or breaking the expectation at line 41
(`expect(window.open).toHaveBeenCalledWith(...)`), causing Jest to throw and
skip the
restore block.
4. Observe that the next test in the same file, `test('open dashboard button
opens
dashboard url', async () => ...)` at lines 47–70, now starts with `const
origOpen =
window.open;` capturing the leftover mock instead of the jsdom
implementation, so even
after its own "restore" `window.open` remains a Jest mock for the rest of
the suite,
demonstrating cross-test global-state contamination due to missing
guaranteed cleanup.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=94a4c480fa1b4eb1b5491ffebbb5f0cc&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=94a4c480fa1b4eb1b5491ffebbb5f0cc&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/features/alerts/AlertReportModal.test.tsx
**Line:** 696:703
**Comment:**
*Missing Cleanup: The test overrides `window.open` directly and
restores it only at the end of the happy path; if any assertion throws before
the restore line, the global stays mocked and can break unrelated tests. Use a
spy with automatic restoration (or `try/finally`) so cleanup always runs.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40525&comment_hash=cee3f1efe4758e46d19c1c2a09afaad32c7fa9266feb832455f254cff6d7a003&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40525&comment_hash=cee3f1efe4758e46d19c1c2a09afaad32c7fa9266feb832455f254cff6d7a003&reaction=dislike'>👎</a>
##########
superset-frontend/src/features/alerts/AlertReportModal.test.tsx:
##########
@@ -678,6 +678,56 @@ test('removes ignore cache checkbox when chart is
selected', async () => {
).not.toBeInTheDocument();
});
+test('open chart button opens explore with slice_id', async () => {
+ // Render with an existing alert that has a chart selected
+ render(<AlertReportModal {...generateMockedProps(false, true, false)} />, {
+ useRedux: true,
+ });
+ userEvent.click(screen.getByTestId('contents-panel'));
+
+ // Ensure chart is present
+ await screen.findByText(/test chart/i);
+
+ const openChartButton = screen.getByRole('button', {
+ name: /open chart in new tab/i,
+ });
+ expect(openChartButton).toBeInTheDocument();
+
+ const origOpen = window.open;
+ // @ts-ignore
+ window.open = jest.fn();
+ await userEvent.click(openChartButton);
+ expect(window.open).toHaveBeenCalledWith('/explore/?slice_id=1', '_blank',
'noopener');
+ // restore
+ // @ts-ignore
+ window.open = origOpen;
+});
+
+test('open dashboard button opens dashboard url', async () => {
+ // Render with an existing alert that has a dashboard selected
+ render(<AlertReportModal {...generateMockedProps(false, true, true)} />, {
+ useRedux: true,
+ });
+ userEvent.click(screen.getByTestId('contents-panel'));
+
+ // Ensure dashboard is present
+ await screen.findByText(/test dashboard/i);
+
+ const openDashButton = screen.getByRole('button', {
+ name: /open dashboard in new tab/i,
+ });
+ expect(openDashButton).toBeInTheDocument();
+
+ const origOpen = window.open;
+ // @ts-ignore
+ window.open = jest.fn();
+ await userEvent.click(openDashButton);
+ expect(window.open).toHaveBeenCalledWith('/superset/dashboard/1', '_blank',
'noopener');
+ // restore
+ // @ts-ignore
+ window.open = origOpen;
Review Comment:
**Suggestion:** This test has the same global-mock lifecycle issue:
`window.open` is reassigned and only restored after assertions, so an
intermediate failure leaves polluted global state for later tests. Wrap the
mock in guaranteed cleanup (`try/finally` or `jest.spyOn(...).mockRestore()`).
[missing cleanup]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Dashboard open test can leave global window.open mocked.
- ⚠️ Later tests may behave incorrectly under polluted globals.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Run the frontend Jest tests so that
`superset-frontend/src/features/alerts/AlertReportModal.test.tsx` executes
`test('open
dashboard button opens dashboard url', async () => ...)` at lines 47–70 from
the Read
output.
2. In this test, observe that at lines 62–69 it assigns `const origOpen =
window.open;
window.open = jest.fn(); ... expect(window.open)...; // restore ...
window.open =
origOpen;`, directly mutating the global `window.open` without `try/finally`
or
framework-level cleanup.
3. Induce a failure in this test after `window.open` is mocked but before
the restore, for
example by changing the expected URL in the assertion at line 66 so the
`expect(window.open).toHaveBeenCalledWith('/superset/dashboard/1', ...)`
fails and aborts
the test mid-way.
4. Because no `afterEach` hook in `AlertReportModal.test.tsx` resets
`window.open`,
subsequent tests in the same environment (e.g. `test('does not show
screenshot width when
csv is selected', async () => ...)` at lines 72–93) will run with
`window.open` still set
to the Jest mock instead of jsdom's implementation, making the suite
sensitive to this
test's failures and causing flaky or misleading results until the process is
restarted.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=302d6daaf8bb4c3eb746ea07fdd91b09&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=302d6daaf8bb4c3eb746ea07fdd91b09&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/features/alerts/AlertReportModal.test.tsx
**Line:** 721:728
**Comment:**
*Missing Cleanup: This test has the same global-mock lifecycle issue:
`window.open` is reassigned and only restored after assertions, so an
intermediate failure leaves polluted global state for later tests. Wrap the
mock in guaranteed cleanup (`try/finally` or `jest.spyOn(...).mockRestore()`).
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40525&comment_hash=fc5e271cae20557fa3e011a91526df83808836593567f5d2bd0165cdfc0ee288&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40525&comment_hash=fc5e271cae20557fa3e011a91526df83808836593567f5d2bd0165cdfc0ee288&reaction=dislike'>👎</a>
--
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]