codeant-ai-for-open-source[bot] commented on code in PR #40929:
URL: https://github.com/apache/superset/pull/40929#discussion_r3399413507
##########
superset-frontend/src/dashboard/containers/DashboardPage.test.tsx:
##########
@@ -443,6 +446,115 @@ test('passes null theme when Redux dashboardInfo.theme is
explicitly null (theme
);
});
+test('copies currentState to filterState for legacy native_filters URL
params', async () => {
+ // Pre-2021 URLs encode filter selections under `currentState`. The dataMask
+ // reducer uses `filterState`, so without normalization the filter panel
shows
+ // no active selections even though extraFormData still filters chart
queries.
+ mockGetUrlParam.mockImplementation((param: { name: string }) => {
+ if (param.name === 'native_filters') {
+ return {
+ 'NATIVE_FILTER-OvPTDNKc9': {
+ extraFormData: {
+ filters: [{ col: 'team_name', op: 'IN', val: ['MarginEdge'] }],
+ },
+ currentState: { value: ['MarginEdge'] },
+ },
+ };
+ }
+ return null;
+ });
Review Comment:
**Suggestion:** This test mutates the shared `getUrlParam` mock with
`mockImplementation`, but the suite only calls `jest.clearAllMocks()` in
`beforeEach`, which does not reset mock implementations. The custom
implementation can leak into later tests and make them order-dependent/flaky.
Reset `mockGetUrlParam` (e.g., `mockReset` + default return value) in
`beforeEach`/`afterEach` so each test starts from the same URL-param behavior.
[possible bug]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ DashboardPage tests behave differently when run in isolation.
- ⚠️ Undo-history test runs with unexpected native_filters data.
- ⚠️ Future tests may silently rely on wrong URL defaults.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Note that `DashboardPage` reads URL parameters with `getUrlParam` in
`superset-frontend/src/dashboard/containers/DashboardPage.tsx:204-207` (for
`permalinkKey`, `nativeFiltersKey`, and `nativeFilters`), and that the tests
mock this
function in
`superset-frontend/src/dashboard/containers/DashboardPage.test.tsx:136-140`
via `jest.mock('src/utils/urlUtils', () => ({ getUrlParam:
jest.fn().mockReturnValue(null)
}))`, so the default behavior is to return `null` for all params.
2. Observe the Jest lifecycle hooks in
`superset-frontend/src/dashboard/containers/DashboardPage.test.tsx:158-180`:
`afterEach`
calls `jest.restoreAllMocks()` and `beforeEach` calls
`jest.clearAllMocks()`, but there is
no `jest.resetAllMocks()` nor any explicit reset of `mockGetUrlParam`;
`jest.restoreAllMocks()` does not restore plain `jest.fn()` mocks created in
the module
factory, so mock implementations persist across tests.
3. In the legacy URL test at
`superset-frontend/src/dashboard/containers/DashboardPage.test.tsx:449-465`,
`mockGetUrlParam.mockImplementation((param: { name: string }) => { ... })`
is used to
return a non-null object whenever `param.name === 'native_filters'`. In the
modern URL
test at `502-516`, `mockGetUrlParam.mockImplementation` is called again with
a different
implementation. Neither test calls `mockReset`/`mockRestore` on
`mockGetUrlParam`, so
after these tests run, the last implementation (the modern URL version)
remains active for
subsequent tests.
4. The final test, `test('clears undo history after hydrating the
dashboard', ...)` at
`superset-frontend/src/dashboard/containers/DashboardPage.test.tsx:558-585`,
renders
`<DashboardPage />` without overriding `mockGetUrlParam`. When the full file
test suite is
run, `beforeEach` only clears mock call history and `afterEach` does not
restore
`getUrlParam`'s implementation, so this test executes with the leaked
`mockGetUrlParam`
implementation from the previous test (returning a non-null object for
`URL_PARAMS.nativeFilters`). If you instead focus this last test in
isolation (e.g. using
`it.only`), it runs with the default `jest.fn().mockReturnValue(null)`
implementation, so
`getUrlParam(URL_PARAMS.nativeFilters)` is `null`. This difference in
behavior based
solely on test ordering demonstrates that the shared `mockGetUrlParam`
implementation is
leaking across tests, making the tests order-dependent and potentially
flaky. Resetting
`mockGetUrlParam`'s implementation in `beforeEach` (e.g.
`mockGetUrlParam.mockReset();
mockGetUrlParam.mockReturnValue(null);`) would remove this order dependence.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=97d5d48c1f544bdaad40a64b1447b721&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=97d5d48c1f544bdaad40a64b1447b721&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/dashboard/containers/DashboardPage.test.tsx
**Line:** 453:465
**Comment:**
*Possible Bug: This test mutates the shared `getUrlParam` mock with
`mockImplementation`, but the suite only calls `jest.clearAllMocks()` in
`beforeEach`, which does not reset mock implementations. The custom
implementation can leak into later tests and make them order-dependent/flaky.
Reset `mockGetUrlParam` (e.g., `mockReset` + default return value) in
`beforeEach`/`afterEach` so each test starts from the same URL-param behavior.
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%2F40929&comment_hash=0e0cf11ed89d0e298314baade768498032cf5589ab9910e2b80aecef7d38aee3&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40929&comment_hash=0e0cf11ed89d0e298314baade768498032cf5589ab9910e2b80aecef7d38aee3&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]